fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ksynch.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/cmn_err.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/kmem.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/conf.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/errno.h>
5c5f137104b2d56181283389fa902220f2023809Richard Lowe#include <sys/sysmacros.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef _SunOS_5_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_5_6 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ddi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsc_thread.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/nsctl/nsctl.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/sdt.h> /* dtrace is S10 or later */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "rdc_io.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "rdc_bitmap.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "rdc_update.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "rdc_ioctl.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "rdcsrv.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "rdc_diskq.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 Fortevolatile int net_exit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_size_t MAX_RDC_FBAS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint RDC_MAX_SYNC_THREADS = 8;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_maxthreads_last = 8;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortekmutex_t rdc_ping_lock; /* Ping lock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic kmutex_t net_blk_lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_conf_lock is used as a global device configuration lock.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * It is also used by enable/resume and disable/suspend code to ensure that
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the transition of an rdc set between configured and unconfigured is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * atomic.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * krdc->group->lock is used to protect state changes of a configured rdc
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * set (e.g. changes to urdc->flags), such as enabled to disabled and vice
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * versa.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_many_lock is also used to protect changes in group membership. A group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * linked list cannot change while this lock is held. The many list and the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * multi-hop list are both protected by rdc_many_lock.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortekmutex_t rdc_conf_lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortekmutex_t rdc_many_lock; /* Many/multi-list lock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic kmutex_t rdc_net_hnd_id_lock; /* Network handle id lock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_debug = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_debug_sleep = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int rdc_net_hnd_id = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern kmutex_t rdc_clnt_lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void rdc_ditemsfree(rdc_net_dataset_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid rdc_clnt_destroy(void);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_k_info_t *rdc_k_info;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_u_info_t *rdc_u_info;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteunsigned long rdc_async_timeout;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_size_t rdc_maxthres_queue = RDC_MAXTHRES_QUEUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_max_qitems = RDC_MAX_QITEMS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_asyncthr = RDC_ASYNCTHR;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic nsc_svc_t *rdc_volume_update;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int rdc_prealloc_handle = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int _rdc_rsrv_diskq(rdc_group_t *group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void _rdc_rlse_diskq(rdc_group_t *group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Forward declare all statics that are used before defined
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to enforce parameter checking
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Some (if not all) of these could be removed if the code were reordered
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void rdc_volume_update_svc(intptr_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void halt_sync(rdc_k_info_t *krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid rdc_kstat_create(int index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid rdc_kstat_delete(int index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int rdc_checkforbitmap(int, nsc_off_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int rdc_installbitmap(int, void *, int, nsc_off_t, int, int *, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic rdc_group_t *rdc_newgroup();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_enable_diskq(rdc_k_info_t *krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid rdc_close_diskq(rdc_group_t *group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_suspend_diskq(rdc_k_info_t *krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_resume_diskq(rdc_k_info_t *krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid rdc_init_diskq_header(rdc_group_t *grp, dqheader *header);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid rdc_fail_diskq(rdc_k_info_t *krdc, int wait, int dolog);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid rdc_unfail_diskq(rdc_k_info_t *krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid rdc_unintercept_diskq(rdc_group_t *grp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_stamp_diskq(rdc_k_info_t *krdc, int rsrvd, int flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid rdc_qfiller_thr(rdc_k_info_t *krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortenstset_t *_rdc_ioset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortenstset_t *_rdc_flset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * RDC threadset tunables
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_threads = 64; /* default number of threads */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint rdc_threads_inc = 8; /* increment for changing the size of the set */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Private threadset manipulation variables
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int rdc_threads_hysteresis = 2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* hysteresis for threadset resizing */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int rdc_sets_active; /* number of sets currently enabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortekmutex_t rdc_cntlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_thread_deconfigure - rdc is being deconfigured, stop any
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * thread activity.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Inherently single-threaded by the Solaris module unloading code.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_thread_deconfigure(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nst_destroy(_rdc_ioset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_ioset = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nst_destroy(_rdc_flset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_flset = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nst_destroy(sync_info.rdc_syncset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sync_info.rdc_syncset = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_thread_configure - rdc is being configured, initialize the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * threads we need for flushing aync volumes.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Must be called with rdc_conf_lock held.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_thread_configure(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_conf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((_rdc_ioset = nst_init("rdc_thr", rdc_threads)) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((_rdc_flset = nst_init("rdc_flushthr", 2)) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((sync_info.rdc_syncset =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nst_init("rdc_syncthr", RDC_MAX_SYNC_THREADS)) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_thread_tune - called to tune the size of the rdc threadset.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Called from the config code when an rdc_set has been enabled or disabled.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 'sets' is the increment to the number of active rdc_sets.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Must be called with rdc_conf_lock held.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_thread_tune(int sets)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int incr = (sets > 0) ? 1 : -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int change = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int nthreads;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_conf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sets < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sets = -sets;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (sets--) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nthreads = nst_nthread(_rdc_ioset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_sets_active += incr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_sets_active >= nthreads)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte change += nst_add_thread(_rdc_ioset, rdc_threads_inc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if ((rdc_sets_active <
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (nthreads - (rdc_threads_inc + rdc_threads_hysteresis))) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((nthreads - rdc_threads_inc) >= rdc_threads))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte change -= nst_del_thread(_rdc_ioset, rdc_threads_inc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (change) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_thread_tune: "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "nsets %d, nthreads %d, nthreads change %d",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana rdc_sets_active, nst_nthread(_rdc_ioset), change);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _rdc_unload() - cache is being unloaded,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * deallocate any dual copy structures allocated during cache
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * loading.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_unload(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_volume_update) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_unregister_svc(rdc_volume_update);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_volume_update = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_thread_deconfigure();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_k_info != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < rdc_max_sets; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&krdc->dc_sleep);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&krdc->bmapmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&krdc->kstat_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&krdc->bmp_kstat_mutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&krdc->syncbitmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_destroy(&krdc->busycv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_destroy(&krdc->closingcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_destroy(&krdc->haltcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_destroy(&krdc->synccv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&sync_info.lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&rdc_ping_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&net_blk_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&rdc_many_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&rdc_net_hnd_id_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&rdc_clnt_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&rdc_cntlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_exit = ATM_EXIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_k_info != NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(rdc_k_info, sizeof (*rdc_k_info) * rdc_max_sets);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_u_info != NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(rdc_u_info, sizeof (*rdc_u_info) * rdc_max_sets);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_max_sets = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _rdc_load() - rdc is being loaded, Allocate anything
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * that will be needed while the cache is loaded but doesn't really
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * depend on configuration parameters.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_load(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&rdc_ping_lock, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&net_blk_lock, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&rdc_conf_lock, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&rdc_many_lock, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&rdc_net_hnd_id_lock, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&rdc_clnt_lock, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&sync_info.lock, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&rdc_cntlock, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((i = nsc_max_devices()) < rdc_max_sets)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_max_sets = i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* following case for partial installs that may fail */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!rdc_max_sets)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_max_sets = 1024;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info = kmem_zalloc(sizeof (*rdc_k_info) * rdc_max_sets, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!rdc_k_info)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENOMEM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info = kmem_zalloc(sizeof (*rdc_u_info) * rdc_max_sets, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!rdc_u_info) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(rdc_k_info, sizeof (*rdc_k_info) * rdc_max_sets);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENOMEM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_exit = ATM_NONE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < rdc_max_sets; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[i];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(krdc, sizeof (*krdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->index = i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&krdc->dc_sleep, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&krdc->bmapmutex, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&krdc->kstat_mutex, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&krdc->bmp_kstat_mutex, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&krdc->syncbitmutex, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_init(&krdc->busycv, NULL, CV_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_init(&krdc->closingcv, NULL, CV_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_init(&krdc->haltcv, NULL, CV_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_init(&krdc->synccv, NULL, CV_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_volume_update = nsc_register_svc("RDCVolumeUpdated",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana rdc_volume_update_svc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_u_init(rdc_u_info_t *urdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte const int index = (int)(urdc - &rdc_u_info[0]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (urdc->secondary.addr.maxlen)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_rdc_netbuf(&urdc->secondary.addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (urdc->primary.addr.maxlen)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_rdc_netbuf(&urdc->primary.addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(urdc, sizeof (rdc_u_info_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->index = index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->maxqfbas = rdc_maxthres_queue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->maxqitems = rdc_max_qitems;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->asyncthr = rdc_asyncthr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _rdc_configure() - cache is being configured.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Initialize dual copy structures
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_configure(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 0; index < rdc_max_sets; index++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->remote_index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->dcio_bitmap = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->bitmap_ref = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->bitmap_size = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->bitmap_write = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->disk_status = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->many_next = krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_init(&rdc_u_info[index]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_async_timeout = 120 * HZ; /* Seconds * HZ */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MAX_RDC_FBAS = FBA_LEN(RDC_MAXDATA);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (net_exit != ATM_INIT) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_exit = ATM_INIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _rdc_deconfigure - rdc is being deconfigured, shut down any
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * dual copy operations and return to an unconfigured state.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_deconfigure(void)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 0; index < rdc_max_sets; index++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->remote_index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->dcio_bitmap = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->bitmap_ref = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->bitmap_size = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->bitmap_write = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->disk_status = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->many_next = krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (urdc->primary.addr.maxlen)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_rdc_netbuf(&(urdc->primary.addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (urdc->secondary.addr.maxlen)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_rdc_netbuf(&(urdc->secondary.addr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(urdc, sizeof (rdc_u_info_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->index = index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_exit = ATM_EXIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clnt_destroy();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Lock primitives, containing checks that lock ordering isn't broken
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*ARGSUSED*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_many_enter(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(!MUTEX_HELD(&krdc->bmapmutex));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_many_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_many_exit(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_many_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_group_enter(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(!MUTEX_HELD(&rdc_many_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(!MUTEX_HELD(&rdc_conf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(!MUTEX_HELD(&krdc->bmapmutex));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&krdc->group->lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_group_exit(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&krdc->group->lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Suspend and disable operations use this function to wait until it is safe
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to do continue, without trashing data structures used by other ioctls.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortewait_busy(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_conf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (krdc->busy_count > 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_wait(&krdc->busycv, &rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Other ioctls use this function to hold off disable and suspend.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteset_busy(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_conf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wait_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->busy_count++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Other ioctls use this function to allow disable and suspend to continue.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortewakeup_busy(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_conf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->busy_count <= 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->busy_count--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&krdc->busycv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Remove the rdc set from its group, and destroy the group if no longer in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * use.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteremove_from_group(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_conf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->count--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lock queue while looking at thrnum
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((group->rdc_thrnum == 0) && (group->count == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Assure the we've stopped and the flusher thread has not
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fallen back to sleep
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->group->ra_queue.qfill_sleeping != RDC_QFILL_DEAD) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->ra_queue.qfflags |= RDC_QFILLSTOP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (krdc->group->ra_queue.qfflags & RDC_QFILLSTOP) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->group->ra_queue.qfill_sleeping ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_QFILL_ASLEEP)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&group->ra_queue.qfcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&group->diskqmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_close_diskq(group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&group->diskqmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_delgroup(group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Always clear the group field.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * no, you need it set in rdc_flush_memq().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to call rdc_group_log()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * krdc->group = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Take this rdc structure off the group list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (p = krdc->group_next; p->group_next != krdc; p = p->group_next)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p->group_next = krdc->group_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Add the rdc set to its group, setting up a new group if it's the first one.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteadd_to_group(rdc_k_info_t *krdc, int options, int cmd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *utmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *ktmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsthread_t *trc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_conf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Look for matching group name, primary host name and secondary
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * host name.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 0; index < rdc_max_sets; index++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte utmp = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ktmp = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (urdc->group_name[0] == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_CONFIGURED(ktmp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(utmp->group_name, urdc->group_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(utmp->primary.intf, urdc->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MAX_RDC_HOST_SIZE) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Same group name, different primary interface */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(utmp->secondary.intf, urdc->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MAX_RDC_HOST_SIZE) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Same group name, different secondary interface */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Group already exists, so add this set to the group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((options & RDC_OPT_ASYNC) == 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((ktmp->type_flag & RDC_ASYNCMODE) != 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Must be same mode as existing group members */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((options & RDC_OPT_ASYNC) != 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((ktmp->type_flag & RDC_ASYNCMODE) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Must be same mode as existing group members */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* cannont reconfigure existing group into new queue this way */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((cmd != RDC_CMD_RESUME) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !RDC_IS_DISKQ(ktmp->group) && urdc->disk_queue[0] != '\0') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EQNOADD);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ktmp->group->count++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group = ktmp->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group_next = ktmp->group_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ktmp->group_next = krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->autosync = utmp->autosync; /* Same as rest */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->disk_queue, utmp->disk_queue, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* This must be a new group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group = rdc_newgroup();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group = group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group_next = krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->autosync = -1; /* Unknown */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Tune the thread set by one for each thread created
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_thread_tune(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte trc = nst_create(_rdc_ioset, rdc_qfiller_thr, (void *)krdc, NST_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (trc == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = -1;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!unable to create queue filler daemon");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (urdc->disk_queue[0] == '\0') {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group->flags |= RDC_MEMQUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group->flags |= RDC_DISKQUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* XXX check here for resume or enable and act accordingly */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cmd == RDC_CMD_RESUME) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_resume_diskq(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (cmd == RDC_CMD_ENABLE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_enable_diskq(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc == RDC_EQNOADD) && (cmd != RDC_CMD_ENABLE)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!disk queue %s enable failed,"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte " enabling memory queue",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group->flags &= ~RDC_DISKQUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group->flags |= RDC_MEMQUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(urdc->disk_queue, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefail:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Move the set to a new group if possible
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortechange_group(rdc_k_info_t *krdc, int options)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *utmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *ktmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char tmpq[NSC_MAXPATH];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group, *old_group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsthread_t *trc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_conf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Look for matching group name, primary host name and secondary
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * host name.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&tmpq, sizeof (tmpq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old_group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte next = krdc->group_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(old_group)) { /* can't keep your own queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(tmpq, urdc->disk_queue, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(urdc->disk_queue, sizeof (urdc->disk_queue));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 0; index < rdc_max_sets; index++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte utmp = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ktmp = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ktmp == krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (urdc->group_name[0] == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_CONFIGURED(ktmp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(utmp->group_name, urdc->group_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(utmp->primary.intf, urdc->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MAX_RDC_HOST_SIZE) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto bad;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(utmp->secondary.intf, urdc->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MAX_RDC_HOST_SIZE) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto bad;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Group already exists, so add this set to the group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((options & RDC_OPT_ASYNC) == 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((ktmp->type_flag & RDC_ASYNCMODE) != 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Must be same mode as existing group members */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto bad;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((options & RDC_OPT_ASYNC) != 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((ktmp->type_flag & RDC_ASYNCMODE) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Must be same mode as existing group members */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto bad;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ktmp->group->count++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group = ktmp->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group_next = ktmp->group_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ktmp->group_next = krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(urdc->disk_queue, sizeof (urdc->disk_queue));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->disk_queue, utmp->disk_queue, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto good;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* This must be a new group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group = rdc_newgroup();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group = group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group_next = krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte trc = nst_create(_rdc_ioset, rdc_qfiller_thr, (void *)krdc, NST_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (trc == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = -1;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!unable to create queue filler daemon");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto bad;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (urdc->disk_queue[0] == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group->flags |= RDC_MEMQUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group->flags |= RDC_DISKQUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc = rdc_enable_diskq(krdc)) < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto bad;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortegood:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_ASYNC) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->type_flag |= RDC_ASYNCMODE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_ASYNC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->type_flag &= ~RDC_ASYNCMODE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_ASYNC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old_group->count--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!old_group->rdc_writer && old_group->count == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Group now empty, so destroy */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(old_group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_unintercept_diskq(old_group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&old_group->diskqmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_close_diskq(old_group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&old_group->diskqmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&old_group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Assure the we've stopped and the flusher thread has not
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fallen back to sleep
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (old_group->ra_queue.qfill_sleeping != RDC_QFILL_DEAD) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old_group->ra_queue.qfflags |= RDC_QFILLSTOP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (old_group->ra_queue.qfflags & RDC_QFILLSTOP) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (old_group->ra_queue.qfill_sleeping ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_QFILL_ASLEEP)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&old_group->ra_queue.qfcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&old_group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&old_group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&old_group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_delgroup(old_group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Take this rdc structure off the old group list */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ktmp = next; ktmp->group_next != krdc; ktmp = ktmp->group_next)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ktmp->group_next = next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortebad:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Leave existing group status alone */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->disk_queue, tmpq, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Set flags for an rdc set, setting the group flags as necessary.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_set_flags(rdc_u_info_t *urdc, int flags)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc = &rdc_k_info[urdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int vflags, sflags, bflags, ssflags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE2(rdc_set_flags, int, krdc->index, int, flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vflags = flags & RDC_VFLAGS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sflags = flags & RDC_SFLAGS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bflags = flags & RDC_BFLAGS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ssflags = flags & RDC_SYNC_STATE_FLAGS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vflags) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* normal volume flags */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_conf_lock) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MUTEX_HELD(&krdc->group->lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ssflags)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&krdc->bmapmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->flags |= vflags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ssflags)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&krdc->bmapmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sflags) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Sync state flags that are protected by a different lock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_many_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->sync_flags |= sflags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bflags) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Bmap state flags that are protected by a different lock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&krdc->bmapmutex));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->bmap_flags |= bflags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Clear flags for an rdc set, clearing the group flags as necessary.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_clr_flags(rdc_u_info_t *urdc, int flags)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc = &rdc_k_info[urdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int vflags, sflags, bflags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE2(rdc_clr_flags, int, krdc->index, int, flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte vflags = flags & RDC_VFLAGS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sflags = flags & RDC_SFLAGS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bflags = flags & RDC_BFLAGS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (vflags) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* normal volume flags */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_conf_lock) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MUTEX_HELD(&krdc->group->lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->flags &= ~vflags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sflags) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Sync state flags that are protected by a different lock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_many_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->sync_flags &= ~sflags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bflags) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Bmap state flags that are protected by a different lock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&krdc->bmapmutex));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->bmap_flags &= ~bflags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Get the flags for an rdc set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_get_vflags(rdc_u_info_t *urdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (urdc->flags | urdc->sync_flags | urdc->bmap_flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Initialise flags for an rdc set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_init_flags(rdc_u_info_t *urdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->flags = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->mflags = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->sync_flags = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->bmap_flags = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Set flags for a many group.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_set_mflags(rdc_u_info_t *urdc, int flags)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc = &rdc_k_info[urdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *this = krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(!(flags & ~RDC_MFLAGS));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flags == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_many_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, flags); /* set flags on local urdc */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->mflags |= flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (krdc = krdc->many_next; krdc != this; krdc = krdc->many_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->mflags |= flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Clear flags for a many group.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_clr_mflags(rdc_u_info_t *urdc, int flags)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc = &rdc_k_info[urdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *this = krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *utmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(!(flags & ~RDC_MFLAGS));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flags == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_many_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, flags); /* clear flags on local urdc */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We must maintain the mflags based on the set of flags for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * all the urdc's that are chained up.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * First look through all the urdc's and remove bits from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the 'flags' variable that are in use elsewhere.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (krdc = krdc->many_next; krdc != this; krdc = krdc->many_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte utmp = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(utmp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flags &= ~(rdc_get_vflags(utmp) & RDC_MFLAGS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flags == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Now clear flags as necessary.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flags != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->mflags &= ~flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (krdc = krdc->many_next; krdc != this;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = krdc->many_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte utmp = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(utmp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte utmp->mflags &= ~flags;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_get_mflags(rdc_u_info_t *urdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (urdc->mflags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_set_flags_log(rdc_u_info_t *urdc, int flags, char *why)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE2(rdc_set_flags_log, int, urdc->index, int, flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (why == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flags & RDC_LOGGING)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!sndr: %s:%s entered logging mode: %s",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana urdc->secondary.intf, urdc->secondary.file, why);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flags & RDC_VOL_FAILED)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!sndr: %s:%s volume failed: %s",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana urdc->secondary.intf, urdc->secondary.file, why);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flags & RDC_BMP_FAILED)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!sndr: %s:%s bitmap failed: %s",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana urdc->secondary.intf, urdc->secondary.file, why);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_lor(source, dest, len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * logically OR memory pointed to by source and dest, copying result into dest.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_lor(const uchar_t *source, uchar_t *dest, int len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (source == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < len; i++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *dest++ |= *source++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortecheck_filesize(int index, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint64_t remote_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char tmp1[16], tmp2[16];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int status;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = rdc_net_getsize(index, &remote_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) spcs_s_inttostring(status, tmp1, sizeof (tmp1), 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EGETSIZE, urdc->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file, tmp1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_net_state(index, CCIO_ENABLELOG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EGETSIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (remote_size < (unsigned long long)urdc->volume_size) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) spcs_s_inttostring(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->volume_size, tmp1, sizeof (tmp1), 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Cheat, and covert to int, until we have
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * spcs_s_unsignedlonginttostring().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = (int)remote_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) spcs_s_inttostring(status, tmp2, sizeof (tmp2), 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_ESIZE, urdc->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->primary.file, tmp1, urdc->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file, tmp2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_net_state(index, CCIO_ENABLELOG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_ESIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_volume_update_svc(intptr_t arg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_update_t *update = (rdc_update_t *)arg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *this;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct net_bdata6 bd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_IIUPDATE
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!SNDR received update request for %s",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana update->volume);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((update->protocol != RDC_SVC_ONRETURN) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (update->protocol != RDC_SVC_VOL_ENABLED)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* don't understand what the client intends to do */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte update->denied = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(update->status, RDC_EVERSION);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = rdc_lookup_enabled(update->volume, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * warn II that this volume is in use by sndr so
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * II can validate the sizes of the master vs shadow
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and avoid trouble later down the line with
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * size mis-matches between urdc->volume_size and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * what is returned from nsc_partsize() which may
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * be the size of the master when replicating the shadow
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (update->protocol == RDC_SVC_VOL_ENABLED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte update->denied = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte this = krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(urdc) & RDC_LOGGING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_IIUPDATE
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!SNDR refused update request for %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte update->volume);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte update->denied = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(update->status, RDC_EMIRRORUP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* 1->many - all must be logging */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_MANY(krdc) && IS_STATE(urdc, RDC_PRIMARY)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (krdc = krdc->many_next; krdc != this;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana krdc = krdc->many_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (krdc != this);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_IIUPDATE
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!SNDR allowed update request for %s", update->volume);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bd.size = min(krdc->bitmap_size, (nsc_size_t)update->size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bd.data.data_val = (char *)update->bitmap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bd.offset = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bd.cd = index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc = RDC_OR_BITMAP(&bd)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte update->denied = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(update->status, rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->bits_set = RDC_COUNT_BITMAP(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_MANY(krdc) && IS_STATE(urdc, RDC_PRIMARY)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (krdc = krdc->many_next; krdc != this;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana krdc = krdc->many_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = krdc->index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (krdc != this);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* II (or something else) has updated us, so no need for a sync */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & (RDC_SYNC_NEEDED | RDC_RSYNC_NEEDED)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_SYNC_NEEDED | RDC_RSYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->bitmap_write > 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_write_bitmap(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_check()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return 0 if the set is configured, enabled and the supplied
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * addressing information matches the in-kernel config, otherwise
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return 1.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_check(rdc_k_info_t *krdc, rdc_set_t *rdc_set)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&krdc->group->lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(urdc->primary.file, rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_check: primary file mismatch %s vs %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->primary.file, rdc_set->primary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_set->primary.addr.len != 0 &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcmp(urdc->primary.addr.buf, rdc_set->primary.addr.buf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->primary.addr.len) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_check: primary address mismatch for %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->primary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(urdc->secondary.file, rdc_set->secondary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_check: secondary file mismatch %s vs %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file, rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_set->secondary.addr.len != 0 &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcmp(urdc->secondary.addr.buf, rdc_set->secondary.addr.buf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.addr.len) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_check: secondary addr mismatch for %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Lookup enabled sets for a bitmap match
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_lookup_bitmap(char *pathname)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 0; index < rdc_max_sets; index++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(krdc->index == index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(urdc->index == index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_PRIMARY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(pathname, urdc->primary.bitmap,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(pathname, urdc->secondary.bitmap,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Translate a pathname to index into rdc_k_info[].
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns first match that is enabled.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_lookup_enabled(char *pathname, int allow_disabling)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterestart:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 0; index < rdc_max_sets; index++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(krdc->index == index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(urdc->index == index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (allow_disabling == 0 && krdc->type_flag & RDC_UNREGISTER)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_PRIMARY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(pathname, urdc->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(pathname, urdc->secondary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (allow_disabling == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* None found, or only a disabling one found, so try again */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte allow_disabling = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto restart;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Translate a pathname to index into rdc_k_info[].
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns first match that is configured.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Used by enable & resume code.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Must be called with rdc_conf_lock held.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_lookup_configured(char *pathname)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_conf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 0; index < rdc_max_sets; index++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(krdc->index == index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(urdc->index == index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_CONFIGURED(krdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_PRIMARY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(pathname, urdc->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(pathname, urdc->secondary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Looks up a configured set with matching secondary interface:volume
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to check for illegal many-to-one volume configs. To be used during
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * enable and resume processing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Must be called with rdc_conf_lock held.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_lookup_many2one(rdc_set_t *rdc_set)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_conf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 0; index < rdc_max_sets; index++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_CONFIGURED(krdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(urdc->secondary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->secondary.file, NSC_MAXPATH) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(urdc->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->secondary.intf, MAX_RDC_HOST_SIZE) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < rdc_max_sets)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Looks up an rdc set to check if it is already configured, to be used from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * functions called from the config ioctl where the interface names can be
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * used for comparison.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Must be called with rdc_conf_lock held.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_lookup_byname(rdc_set_t *rdc_set)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_conf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 0; index < rdc_max_sets; index++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(krdc->index == index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(urdc->index == index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_CONFIGURED(krdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(urdc->primary.file, rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(urdc->primary.intf, rdc_set->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MAX_RDC_HOST_SIZE) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(urdc->secondary.file, rdc_set->secondary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(urdc->secondary.intf, rdc_set->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MAX_RDC_HOST_SIZE) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < rdc_max_sets)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Looks up a secondary hostname and device, to be used from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * functions called from the config ioctl where the interface names can be
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * used for comparison.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Must be called with rdc_conf_lock held.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_lookup_byhostdev(char *intf, char *file)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_conf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 0; index < rdc_max_sets; index++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(krdc->index == index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(urdc->index == index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_CONFIGURED(krdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(urdc->secondary.file, file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(urdc->secondary.intf, intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MAX_RDC_HOST_SIZE) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < rdc_max_sets)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Looks up an rdc set to see if it is currently enabled, to be used on the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * server so that the interface addresses must be used for comparison, as
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the interface names may differ from those used on the client.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_lookup_byaddr(rdc_set_t *rdc_set)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 0; index < rdc_max_sets; index++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(krdc->index == index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(urdc->index == index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(urdc->primary.file, rdc_set->primary.file) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strcmp(urdc->secondary.file, rdc_set->secondary.file) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bcmp(urdc->primary.addr.buf, rdc_set->primary.addr.buf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->primary.addr.len) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bcmp(urdc->secondary.addr.buf, rdc_set->secondary.addr.buf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.addr.len) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < rdc_max_sets)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return index of first multihop or 1-to-many
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Behavior controlled by setting ismany.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ismany TRUE (one-to-many)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ismany FALSE (multihops)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_lookup_multimany(rdc_k_info_t *krdc, const int ismany)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *utmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *ktmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *pathname;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int role;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_conf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_many_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_PRIMARY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* this host is the primary of the krdc set */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pathname = urdc->primary.file;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ismany) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1-many sets are linked by primary :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * look for matching primary on this host
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte role = RDC_PRIMARY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * multihop sets link primary to secondary :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * look for matching secondary on this host
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte role = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* this host is the secondary of the krdc set */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pathname = urdc->secondary.file;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ismany) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * 1-many sets are linked by primary, so if
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this host is the secondary of the set this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cannot require 1-many linkage.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * multihop sets link primary to secondary :
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * look for matching primary on this host
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte role = RDC_PRIMARY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 0; index < rdc_max_sets; index++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte utmp = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ktmp = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_CONFIGURED(ktmp)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (role == RDC_PRIMARY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Find a primary that is this host and is not
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * krdc but shares the same data volume as krdc.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rdc_get_vflags(utmp) & RDC_PRIMARY) &&
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana strncmp(utmp->primary.file, pathname,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana NSC_MAXPATH) == 0 && (krdc != ktmp)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Find a secondary that is this host and is not
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * krdc but shares the same data volume as krdc.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(utmp) & RDC_PRIMARY) &&
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana strncmp(utmp->secondary.file, pathname,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana NSC_MAXPATH) == 0 && (krdc != ktmp)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < rdc_max_sets)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Returns secondary match that is configured.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Used by enable & resume code.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Must be called with rdc_conf_lock held.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_lookup_secondary(char *pathname)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_conf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 0; index < rdc_max_sets; index++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(krdc->index == index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(urdc->index == index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_CONFIGURED(krdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_STATE(urdc, RDC_PRIMARY)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(pathname, urdc->secondary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic nsc_fd_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_open_direct(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->remote_fd == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->remote_fd = nsc_open(urdc->direct_file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_RDCHR_ID|NSC_DEVICE|NSC_RDWR, 0, 0, &rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (krdc->remote_fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_close_direct(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->direct_file[0] = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->remote_fd) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nsc_close(krdc->remote_fd) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->remote_fd = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_MANY
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteprint_many(rdc_k_info_t *start)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *p = start;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *q = &rdc_u_info[p->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_CONT, "!krdc %p, %s %s (many_nxt %p multi_nxt %p)\n",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana p, q->primary.file, q->secondary.file, p->many_next,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana p->multi_next);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(10);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = p->many_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &rdc_u_info[p->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (p && p != start);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* DEBUG_MANY */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteadd_to_multi(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *ktmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *utmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int mindex;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int domulti;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_conf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_many_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Now find companion krdc */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mindex = rdc_lookup_multimany(krdc, FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_MANY
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!add_to_multi: lookup_multimany: mindex %d prim %s sec %s",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana mindex, urdc->primary.file, urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mindex >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ktmp = &rdc_k_info[mindex];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte utmp = &rdc_u_info[mindex];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte domulti = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rdc_get_vflags(urdc) & RDC_PRIMARY) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ktmp->multi_next != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We are adding a new primary to a many
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * group that is the target of a multihop, just
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ignore it since we are linked in elsewhere.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte domulti = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (domulti) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_PRIMARY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Is previous leg using direct file I/O? */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (utmp->direct_file[0] != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* It is, so cannot proceed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Is this leg using direct file I/O? */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (urdc->direct_file[0] != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* It is, so cannot proceed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->multi_next = ktmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ktmp->multi_next = krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->multi_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_MANY
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!add_to_multi: NULL multi_next index %d",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana krdc->index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Add a new set to the circular list of 1-to-many primaries and chain
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * up any multihop as well.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteadd_to_many(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *okrdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int oindex;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_conf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (add_to_multi(krdc) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte oindex = rdc_lookup_multimany(krdc, TRUE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (oindex < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_MANY
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte print_many(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte okrdc = &rdc_k_info[oindex];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_MANY
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte print_many(okrdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->many_next = okrdc->many_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte okrdc->many_next = krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_MANY
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte print_many(okrdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Remove a set from the circular list of 1-to-many primaries.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteremove_from_many(rdc_k_info_t *old)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *uold = &rdc_u_info[old->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *p, *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_conf_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(old);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_MANY
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc: before remove_from_many");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte print_many(old);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (old->many_next == old) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* remove from multihop */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((q = old->multi_next) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(q->multi_next == old);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->multi_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old->multi_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(old);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* search */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (p = old->many_next; p->many_next != old; p = p->many_next)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p->many_next = old->many_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old->many_next = old;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((q = old->multi_next) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * old was part of a multihop, so switch multi pointers
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * to someone remaining on the many chain
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(p->multi_next == NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->multi_next = p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p->multi_next = q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte old->multi_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_MANY
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (p == old) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc: after remove_from_many empty");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc: after remove_from_many");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte print_many(p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_mflags(&rdc_u_info[p->index],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_get_vflags(uold) & RDC_MFLAGS));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(old);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_enable(rdc_set_t *rdc_set, int options, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *rhost;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct netbuf *addrp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_srv_t *svp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *local_file;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *local_bitmap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t maxfbas;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *grp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rdc_set->primary.intf[0] == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_set->primary.addr.len == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_set->primary.file[0] == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_set->primary.bitmap[0] == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_set->secondary.intf[0] == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_set->secondary.addr.len == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_set->secondary.file[0] == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_set->secondary.bitmap[0] == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EEMPTY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EEMPTY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Next check there aren't any enabled rdc sets which match. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_lookup_byname(rdc_set) >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EENABLED, rdc_set->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->primary.file, rdc_set->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EENABLED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_lookup_many2one(rdc_set) >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EMANY2ONE, rdc_set->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->primary.file, rdc_set->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EMANY2ONE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_set->netconfig->knc_proto == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_ENETCONFIG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_ENETCONFIG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_set->primary.addr.len == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_ENETBUF, rdc_set->primary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_ENETBUF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_set->secondary.addr.len == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_ENETBUF, rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_ENETBUF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check that the local data volume isn't in use as a bitmap */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_PRIMARY)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_file = rdc_set->primary.file;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_file = rdc_set->secondary.file;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_lookup_bitmap(local_file) >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EVOLINUSE, local_file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EVOLINUSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check that the secondary data volume isn't in use */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(options & RDC_OPT_PRIMARY)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_file = rdc_set->secondary.file;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_lookup_secondary(local_file) >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EVOLINUSE, local_file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EVOLINUSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check that the local data vol is not in use as a diskqueue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_PRIMARY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_lookup_diskq(rdc_set->primary.file) >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_EVOLINUSE, rdc_set->primary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EVOLINUSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check that the bitmap isn't in use as a data volume */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_PRIMARY)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_bitmap = rdc_set->primary.bitmap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_bitmap = rdc_set->secondary.bitmap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_lookup_configured(local_bitmap) >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EBMPINUSE, local_bitmap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EBMPINUSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check that the bitmap isn't already in use as a bitmap */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_lookup_bitmap(local_bitmap) >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EBMPINUSE, local_bitmap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EBMPINUSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check that the diskq (if here) is not in use */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte diskq = rdc_set->disk_queue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (diskq[0] && rdc_diskq_inuse(rdc_set, diskq)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EDISKQINUSE, diskq);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EDISKQINUSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Set urdc->volume_size */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = rdc_dev_open(rdc_set, options);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_PRIMARY)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EOPEN, rdc_set->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->primary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EOPEN, rdc_set->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EOPEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* copy relevant parts of rdc_set to urdc field by field */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->primary.intf, rdc_set->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MAX_RDC_HOST_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->secondary.intf, rdc_set->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MAX_RDC_HOST_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->group_name, rdc_set->group_name, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->disk_queue, rdc_set->disk_queue, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dup_rdc_netbuf(&rdc_set->primary.addr, &urdc->primary.addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->primary.file, rdc_set->primary.file, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->primary.bitmap, rdc_set->primary.bitmap,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dup_rdc_netbuf(&rdc_set->secondary.addr, &urdc->secondary.addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->secondary.file, rdc_set->secondary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->secondary.bitmap, rdc_set->secondary.bitmap,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->setid = rdc_set->setid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * before we try to add to group, or create one, check out
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if we are doing the wrong thing with the diskq
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (urdc->disk_queue[0] && (options & RDC_OPT_SYNC)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dev_close(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EQWRONGMODE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EQWRONGMODE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc = add_to_group(krdc, options, RDC_CMD_ENABLE)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dev_close(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == RDC_EQNOADD) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EQNOADD, rdc_set->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EQNOADD);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EGROUP,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->primary.intf, rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->secondary.intf, rdc_set->secondary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->group_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EGROUP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * maxfbas was set in rdc_dev_open as primary's maxfbas.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If diskq's maxfbas is smaller, then use diskq's.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grp = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (grp && RDC_IS_DISKQ(grp) && (grp->diskqfd != 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _rdc_rsrv_diskq(grp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_SUCCESS(rc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_maxfbas(grp->diskqfd, 0, &maxfbas);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->maxfbas != maxfbas)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!_rdc_enable: diskq maxfbas = %"
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana NSC_SZFMT ", primary maxfbas = %"
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana NSC_SZFMT, maxfbas, krdc->maxfbas);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->maxfbas = min(krdc->maxfbas, maxfbas);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!_rdc_enable: diskq maxfbas failed (%d)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_diskq(grp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!_rdc_enable: diskq reserve failed (%d)", rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_init_flags(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->direct_file, rdc_set->direct_file, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((options & RDC_OPT_PRIMARY) && rdc_set->direct_file[0]) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_open_direct(krdc) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_FCAL_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->many_next = krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(krdc->type_flag == 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->type_flag = RDC_CONFIGURED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_PRIMARY)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_PRIMARY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_ASYNC)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->type_flag |= RDC_ASYNCMODE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte set_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->syshostid = rdc_set->syshostid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (add_to_many(krdc) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EMULTI);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EMULTI;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Configured but not enabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(IS_CONFIGURED(krdc) && !IS_ENABLED(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Configured but not enabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(IS_CONFIGURED(krdc) && !IS_ENABLED(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The rdc set is configured but not yet enabled. Other operations must
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ignore this set until it is enabled.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->sync_pos = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_set->maxqfbas > 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->maxqfbas = rdc_set->maxqfbas;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->maxqfbas = rdc_maxthres_queue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_set->maxqitems > 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->maxqitems = rdc_set->maxqitems;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->maxqitems = rdc_max_qitems;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_set->asyncthr > 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->asyncthr = rdc_set->asyncthr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->asyncthr = rdc_asyncthr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (urdc->autosync == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Still unknown */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_set->autosync > 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->autosync = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->autosync = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->netconfig = rdc_set->netconfig;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_PRIMARY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rhost = rdc_set->secondary.intf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte addrp = &rdc_set->secondary.addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rhost = rdc_set->primary.intf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte addrp = &rdc_set->primary.addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_ASYNC)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_ASYNC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svp = rdc_create_svinfo(rhost, addrp, urdc->netconfig);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (svp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, ENOMEM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = ENOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->netconfig = NULL; /* This will be no good soon */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_kstat_create(index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Don't set krdc->intf here */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_enable_bitmap(krdc, options & RDC_OPT_SETBMP) < 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto bmpfail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_ZERO_BITREF(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->lsrv == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->lsrv = svp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!_rdc_enable: krdc->lsrv already set: %p",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (void *) krdc->lsrv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_destroy_svinfo(svp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Configured but not enabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(IS_CONFIGURED(krdc) && !IS_ENABLED(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* And finally */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->remote_index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Should we set the whole group logging? */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_ENABLED | RDC_LOGGING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_intercept(krdc) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_ENABLED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_PRIMARY)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EREGISTER, urdc->primary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EREGISTER,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!nsc_register_path failed %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->primary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EREGISTER;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto bmpfail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!SNDR: enabled %s %s", urdc->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
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 return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortebmpfail:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_PRIMARY)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EBITMAP, rdc_set->primary.bitmap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EBITMAP, rdc_set->secondary.bitmap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EBITMAP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_ENABLED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_unintercept(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefail:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_kstat_delete(index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->intf) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_if_t *ip = krdc->intf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->intf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_remove_from_if(ip);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Configured but not enabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(IS_CONFIGURED(krdc) && !IS_ENABLED(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dev_close(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_close_direct(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_destroy_svinfo(svp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Configured but not enabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(IS_CONFIGURED(krdc) && !IS_ENABLED(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Configured but not enabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(IS_CONFIGURED(krdc) && !IS_ENABLED(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte remove_from_group(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_MANY(krdc) || IS_MULTI(krdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte remove_from_many(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_init(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(krdc->type_flag & RDC_CONFIGURED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->type_flag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wakeup_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_enable(rdc_config_t *uparms, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char itmp[10];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(uparms->options & RDC_OPT_SYNC) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !(uparms->options & RDC_OPT_ASYNC)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EEINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) spcs_s_inttostring(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->options, itmp, sizeof (itmp), 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EEINVAL, itmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(uparms->options & RDC_OPT_PRIMARY) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !(uparms->options & RDC_OPT_SECONDARY)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EEINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) spcs_s_inttostring(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->options, itmp, sizeof (itmp), 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EEINVAL, itmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(uparms->options & RDC_OPT_SETBMP) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !(uparms->options & RDC_OPT_CLRBMP)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EEINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) spcs_s_inttostring(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->options, itmp, sizeof (itmp), 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EEINVAL, itmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _rdc_enable(uparms->rdc_set, uparms->options, kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_disable(rdc_k_info_t *krdc, rdc_config_t *uap, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_if_t *ip;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index = krdc->index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_t *rdc_set = uap->rdc_set;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(krdc->group != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(rdc_check(krdc, rdc_set) == 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((uap->options & RDC_OPT_FORCE_DISABLE) == 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_check(krdc, rdc_set)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_PRIMARY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte halt_sync(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(IS_ENABLED(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &krdc->group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_ASYNC(urdc) && RDC_IS_DISKQ(krdc->group) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((!IS_STATE(urdc, RDC_LOGGING)) && (!QEMPTY(q)))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->type_flag &= ~RDC_DISABLEPEND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EQNOTEMPTY, urdc->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EQNOTEMPTY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_unintercept(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!SNDR: disabled %s %s", urdc->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Configured but not enabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(IS_CONFIGURED(krdc) && !IS_ENABLED(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * No new io can come in through the io provider.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Wait for the async flusher to finish.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_ASYNC(urdc) && !RDC_IS_DISKQ(krdc->group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int tries = 2; /* in case of hopelessly stuck flusher threads */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_queue *qp = &krdc->group->ra_queue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!krdc->group->rdc_writer)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_writer(krdc->index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_drain_queue(krdc->index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (krdc->group->rdc_writer && tries--);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ok, force it to happen... */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_drain_queue(krdc->index) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&krdc->group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group->asyncdis = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&krdc->group->asyncqcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&krdc->group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!SNDR: async I/O pending and not flushed "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "for %s during disable",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->primary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!nitems: %" NSC_SZFMT " nblocks: %"
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana NSC_SZFMT " head: 0x%p tail: 0x%p",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana qp->nitems, qp->blocks,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (void *)qp->net_qhead,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (void *)qp->net_qtail);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (krdc->group->rdc_thrnum > 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ip = krdc->intf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->intf = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ip) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_remove_from_if(ip);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Configured but not enabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(IS_CONFIGURED(krdc) && !IS_ENABLED(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Must not hold group lock during this function */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (rdc_dump_alloc_bufs_cd(krdc->index) == EAGAIN)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_clear_state(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_free_bitmap(krdc, RDC_CMD_DISABLE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_close_bitmap(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dev_close(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_close_direct(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Configured but not enabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(IS_CONFIGURED(krdc) && !IS_ENABLED(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we should now unregister the queue, with no conflicting
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * locks held. This is the last(only) member of the group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->group && RDC_IS_DISKQ(krdc->group) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group->count == 1) { /* stop protecting queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_unintercept_diskq(krdc->group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Configured but not enabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(IS_CONFIGURED(krdc) && !IS_ENABLED(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wait_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_MANY(krdc) || IS_MULTI(krdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte remove_from_many(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte remove_from_group(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->remote_index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(krdc->type_flag & RDC_CONFIGURED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(krdc->type_flag & RDC_DISABLEPEND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->type_flag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->dcio_bitmap)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!_rdc_disable: possible mem leak, "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "dcio_bitmap");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->dcio_bitmap = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->bitmap_ref = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->bitmap_size = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->maxfbas = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->bitmap_write = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->disk_status = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_destroy_svinfo(krdc->lsrv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->lsrv = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->multi_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_init(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_kstat_delete(index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_disable(rdc_config_t *uparms, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = rdc_lookup_byname(uparms->rdc_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < 0 || (krdc->type_flag & RDC_DISABLEPEND)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->type_flag |= RDC_DISABLEPEND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wait_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->type_flag == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* A resume or enable failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _rdc_disable(krdc, uparms, kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Checks whether the state of one of the other sets in the 1-many or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * multi-hop config should prevent a sync from starting on this one.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Return NULL if no just cause or impediment is found, otherwise return
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a pointer to the offending set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic rdc_u_info_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_allow_pri_sync(rdc_u_info_t *urdc, int options)
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 rdc_k_info_t *kmulti = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(rdc_get_vflags(urdc) & RDC_PRIMARY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * In the reverse sync case we need to check the previous leg of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the multi-hop config. The link to that set can be from any of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the 1-many list, so as we go through we keep an eye open for it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((options & RDC_OPT_REVERSE) && (IS_MULTI(krdc))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* This set links to the first leg */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ktmp = krdc->multi_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte utmp = &rdc_u_info[ktmp->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_ENABLED(utmp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmulti = ktmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
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
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(utmp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_FORWARD) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Reverse sync needed is bad, as it means a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * reverse sync in progress or started and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * didn't complete, so this primary volume
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is not consistent. So we shouldn't copy
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it to its secondary.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_mflags(utmp) & RDC_RSYNC_NEEDED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (utmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Reverse, so see if we need to spot kmulti */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((kmulti == NULL) && (IS_MULTI(ktmp))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* This set links to the first leg */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmulti = ktmp->multi_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &rdc_u_info[kmulti->index]))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmulti = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Non-logging is bad, as the bitmap will
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * be updated with the bits for this sync.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(utmp) & RDC_LOGGING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (utmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (kmulti) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte utmp = &rdc_u_info[kmulti->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ktmp = kmulti; /* In case we decide we do need to use ktmp */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(options & RDC_OPT_REVERSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_REPLICATING(utmp)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Replicating is bad as data is already flowing to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the target of the requested sync operation.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (utmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(utmp) & RDC_SYNCING) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Forward sync in progress is bad, as data is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * already flowing to the target of the requested
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sync operation.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Reverse sync in progress is bad, as the primary
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * has already decided which data to copy.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (utmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Clear the "sync needed" flags, as the multi-hop secondary
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * will be updated via this requested sync operation, so does
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * not need to complete its aborted forward sync.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(utmp) & RDC_SYNC_NEEDED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(utmp, RDC_SYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_MANY(krdc) && (options & RDC_OPT_REVERSE)) {
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
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Clear any "reverse sync needed" flags, as the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * volume will be updated via this requested
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sync operation, so does not need to complete
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * its aborted reverse sync.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_mflags(utmp) & RDC_RSYNC_NEEDED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_mflags(utmp, RDC_RSYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_sync_wrthr(void *thrinfo)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_syncthr_t *syncinfo = (rdc_syncthr_t *)thrinfo;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_buf_t *handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc = syncinfo->krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int tries = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana DTRACE_PROBE2(rdc_sync_loop_netwrite_start, int, krdc->index,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana nsc_buf_t *, handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteretry:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_alloc_buf(RDC_U_FD(krdc), syncinfo->offset, syncinfo->len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_READ | NSC_NOCACHE, &handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(rc) || krdc->remote_index < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_sync_wrthr_alloc_buf_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((krdc->disk_status == 1) || (krdc->dcio_bitmap == NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc = rdc_net_write(krdc->index, krdc->remote_index, handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->sb_pos, handle->sb_len, RDC_NOSEQ, RDC_NOQUE, NULL)) > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The following is to handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the case where the secondary side
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * has thrown our buffer handle token away in a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * attempt to preserve its health on restart
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc == EPROTO) && (tries < 3)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tries++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(HZ >> 2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_sync_wrthr_remote_write_err);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_sync_wrthr: remote write failed (%d) "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "0x%x", rc, rdc_get_vflags(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefailed:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syncinfo->status->offset = syncinfo->offset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * see above comments on _rdc_sync_wrthr
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_sync_rdthr(void *thrinfo)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_syncthr_t *syncinfo = (rdc_syncthr_t *)thrinfo;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_buf_t *handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc = syncinfo->krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_alloc_buf(RDC_U_FD(krdc), syncinfo->offset, syncinfo->len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_WRITE | NSC_WRTHRU | NSC_NOCACHE, &handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(rc) || krdc->remote_index < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((krdc->disk_status == 1) || (krdc->dcio_bitmap == NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_net_read(krdc->index, krdc->remote_index, handle,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->sb_pos, handle->sb_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(rc)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_sync_rdthr: remote read failed(%d)", rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_STATE(urdc, RDC_FULL))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_bitmap_many(krdc, handle->sb_pos, handle->sb_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_write(handle, handle->sb_pos, handle->sb_len, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(rc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags_log(urdc, RDC_VOL_FAILED, "nsc_write failed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefailed:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syncinfo->status->offset = syncinfo->offset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _rdc_sync_wrthr
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sync loop write thread
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if there are avail threads, we have not
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * used up the pipe, so the sync loop will, if
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * possible use these to multithread the write/read
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_sync_thread(void *thrinfo)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_syncthr_t *syncinfo = (rdc_syncthr_t *)thrinfo;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc = syncinfo->krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_thrsync_t *sync = &krdc->syncs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t bitmask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _rdc_rsrv_devs(krdc, RDC_RAW, RDC_INTERNAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(rc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_STATE(urdc, RDC_SLAVE))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_sync_rdthr(thrinfo);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_sync_wrthr(thrinfo);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_devs(krdc, RDC_RAW);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->dcio_bitmap == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!_rdc_sync_wrthr: NULL bitmap");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*EMPTY*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (syncinfo->status->offset < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_SET_BITMASK(syncinfo->offset, syncinfo->len, &bitmask);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_CLR_BITMAP(krdc, syncinfo->offset, syncinfo->len, \
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bitmask, RDC_BIT_FORCE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefailed:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * done with this, get rid of it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the status is not freed, it should still be a status chain
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * that _rdc_sync() has the head of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(syncinfo, sizeof (*syncinfo));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * decrement the global sync thread num
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&sync_info.lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sync_info.active_thr--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_AVAIL_THR_TUNE(sync_info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&sync_info.lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * krdc specific stuff
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&sync->lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sync->complete++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&sync->cv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&sync->lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_setup_syncthr(rdc_syncthr_t **synthr, nsc_off_t offset,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t len, rdc_k_info_t *krdc, sync_status_t *stats)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_syncthr_t *tmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* alloc here, free in the sync thread */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_syncthr_t *)kmem_zalloc(sizeof (rdc_syncthr_t), KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (tmp == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp->offset = offset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp->len = len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp->status = stats;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tmp->krdc = krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *synthr = tmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesync_status_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_new_sync_status()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sync_status_t *s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s = (sync_status_t *)kmem_zalloc(sizeof (*s), KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s->offset = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (s);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_free_sync_status(sync_status_t *status)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sync_status_t *s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (status) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte s = status->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(status, sizeof (*status));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = s;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_sync_status_ok(sync_status_t *status, int *offset)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_SYNCSTATUS
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (status) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (status->offset >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *offset = status->offset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte status = status->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG_SYNCSTATUS
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte i++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUGSYNCSTATUS
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_sync_status_ok: checked %d statuses", i);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint mtsync = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _rdc_sync() : rdc sync loop
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_sync(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t size = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rtype;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sts;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int reserved = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_buf_t *alloc_h = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_buf_t *handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t mask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t maxbit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t offset = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sync_completed = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int tries = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int queuing = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint_t bitmask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sync_status_t *ss, *sync_status = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_thrsync_t *sync = &krdc->syncs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_syncthr_t *syncinfo;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsthread_t *trc = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_STATE(urdc, RDC_QUEUING) && !IS_STATE(urdc, RDC_FULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* flusher is handling the sync in the update case */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte queuing = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto sync_done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Main sync/resync loop
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_sync_loop_start);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtype = RDC_RAW;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sts = _rdc_rsrv_devs(krdc, rtype, RDC_INTERNAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_sync_loop_rsrv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sts != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed_noincr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reserved = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * pre-allocate a handle if we can - speeds up the sync.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_prealloc_handle) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte alloc_h = nsc_alloc_handle(RDC_U_FD(krdc), NULL, NULL, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!alloc_h) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!rdc sync: failed to pre-alloc handle");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte alloc_h = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(urdc->volume_size != 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte size = urdc->volume_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mask = ~(LOG_TO_FBA_NUM(1) - 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte maxbit = FBA_TO_LOG_NUM(size - 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * as this while loop can also move data, it is counted as a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sync loop thread
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_LOGGING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_SYNCING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group->synccount++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&sync_info.lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sync_info.active_thr++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_AVAIL_THR_TUNE(sync_info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&sync_info.lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (offset < size) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(krdc->aux_state & RDC_AUXSYNCIP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->disk_status == 1 || krdc->dcio_bitmap == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->disk_status == 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_sync_loop_disk_status_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_sync_loop_dcio_bitmap_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed; /* halt sync */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(urdc) & RDC_FULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&krdc->syncbitmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->syncbitpos = FBA_TO_LOG_NUM(offset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* skip unnecessary chunks */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (krdc->syncbitpos <= maxbit &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !RDC_BIT_ISSET(krdc, krdc->syncbitpos)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte offset += LOG_TO_FBA_NUM(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->syncbitpos++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check for boundary */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (offset >= size) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&krdc->syncbitmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto sync_done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* find maximal length we can transfer */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (krdc->syncbitpos <= maxbit &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_BIT_ISSET(krdc, krdc->syncbitpos)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len += LOG_TO_FBA_NUM(1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->syncbitpos++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* we can only read maxfbas anyways */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (len >= krdc->maxfbas)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = min(len, (size - offset));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = size - offset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* truncate to the io provider limit */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(krdc->maxfbas != 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = min(len, krdc->maxfbas);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (len > LOG_TO_FBA_NUM(1)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the update is larger than a bitmap chunk,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * then truncate to a whole number of bitmap
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * chunks.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If the update is smaller than a bitmap
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * chunk, this must be the last write.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len &= mask;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(urdc) & RDC_FULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->syncbitpos = FBA_TO_LOG_NUM(offset + len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&krdc->syncbitmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Find out if we can reserve a thread here ...
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * note: skip the mutex for the first check, if the number
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is up there, why bother even grabbing the mutex to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * only realize that we can't have a thread anyways
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (mtsync && sync_info.active_thr < RDC_MAX_SYNC_THREADS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&sync_info.lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sync_info.avail_thr >= 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sync_status == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss = sync_status =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_new_sync_status();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ss = ss->next = _rdc_new_sync_status();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ss == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&sync_info.lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_sync: can't "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "allocate status for mt sync");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * syncinfo protected by sync_info lock but
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * not part of the sync_info structure
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * be careful if moving
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_rdc_setup_syncthr(&syncinfo,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte offset, len, krdc, ss) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_free_sync_status(ss);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte trc = nst_create(sync_info.rdc_syncset,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_sync_thread, syncinfo, NST_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (trc == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&sync_info.lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_sync: unable to "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "mt sync");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_free_sync_status(ss);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(syncinfo, sizeof (*syncinfo));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte syncinfo = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&sync->lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sync->threads++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&sync->lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sync_info.active_thr++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_AVAIL_THR_TUNE(sync_info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&sync_info.lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto threaded;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&sync_info.lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteretry:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle = alloc_h;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_sync_loop_allocbuf_start);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_SLAVE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sts = nsc_alloc_buf(RDC_U_FD(krdc), offset, len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_WRITE | NSC_WRTHRU | NSC_NOCACHE, &handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sts = nsc_alloc_buf(RDC_U_FD(krdc), offset, len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_READ | NSC_NOCACHE, &handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_sync_loop_allocbuf_end);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sts > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (handle && handle != alloc_h) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_sync_loop_allocbuf_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_SLAVE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* overwrite buffer with remote data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sts = rdc_net_read(krdc->index, krdc->remote_index,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle, handle->sb_pos, handle->sb_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(sts)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!rdc sync: remote read failed (%d)", sts);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_sync_loop_remote_read_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(urdc) & RDC_FULL))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_bitmap_many(krdc, handle->sb_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->sb_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* commit locally */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sts = nsc_write(handle, handle->sb_pos,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana handle->sb_len, 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_SUCCESS(sts)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* reverse sync needed already set */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags_log(urdc, RDC_VOL_FAILED,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "write failed during sync");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_sync_loop_nsc_write_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* send local data to remote */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE2(rdc_sync_loop_netwrite_start,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana int, krdc->index, nsc_buf_t *, handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((sts = rdc_net_write(krdc->index,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->remote_index, handle, handle->sb_pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle->sb_len, RDC_NOSEQ, RDC_NOQUE, NULL)) > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The following is to handle
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the case where the secondary side
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * has thrown our buffer handle token away in a
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * attempt to preserve its health on restart
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((sts == EPROTO) && (tries < 3)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tries++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(HZ >> 2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!rdc sync: remote write failed (%d) 0x%x",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sts, rdc_get_vflags(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_sync_loop_netwrite_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_sync_loop_netwrite_end);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->dcio_bitmap == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!_rdc_sync: NULL bitmap");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*EMPTY*/
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_SET_BITMASK(offset, len, &bitmask);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_CLR_BITMAP(krdc, offset, len, bitmask, \
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana RDC_BIT_FORCE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(!IS_ASYNC(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Only release/reserve if someone is waiting
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->devices->id_release || nsc_waiting(RDC_U_FD(krdc))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_sync_loop_rlse_start);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (alloc_h) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_handle(alloc_h);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte alloc_h = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_devs(krdc, rtype);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reserved = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rtype = RDC_RAW;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sts = _rdc_rsrv_devs(krdc, rtype, RDC_INTERNAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sts != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte handle = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_sync_loop_rdc_rsrv_err);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte reserved = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_prealloc_handle) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte alloc_h = nsc_alloc_handle(RDC_U_FD(krdc),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana NULL, NULL, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!alloc_h) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_sync: "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "failed to pre-alloc handle");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_sync_loop_rlse_end);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortethreaded:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte offset += len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->sync_pos = offset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortesync_done:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sync_completed = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefailed:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group->synccount--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefailed_noincr:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&sync->lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (sync->complete != sync->threads) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_wait(&sync->cv, &sync->lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sync->complete = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sync->threads = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&sync->lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if sync_completed is 0 here,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we know that the main sync thread failed anyway
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * so just free the statuses and fail
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sync_completed && (_rdc_sync_status_ok(sync_status, &rc) < 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->sync_pos = rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sync_completed = 0; /* at least 1 thread failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_free_sync_status(sync_status);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we didn't increment, we didn't even sync,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * so don't dec sync_info.active_thr
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!queuing) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&sync_info.lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sync_info.active_thr--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_AVAIL_THR_TUNE(sync_info);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&sync_info.lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (handle) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_buf(handle);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (alloc_h) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_handle(alloc_h);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (reserved) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_devs(krdc, rtype);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortenotstarted:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(krdc->aux_state & RDC_AUXSYNCIP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_STATE(urdc, RDC_QUEUING))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_QUEUING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sync_completed) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_net_state(krdc->index, CCIO_DONE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_net_state(krdc->index, CCIO_ENABLELOG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_SYNCING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_SLAVE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_mflags(urdc, RDC_SLAVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->type_flag & RDC_ASYNCMODE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_ASYNC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sync_completed) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_mflags(urdc, RDC_RSYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->remote_index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags_log(urdc, RDC_LOGGING, "sync failed to complete");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&net_blk_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sync_completed)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->sync_done = RDC_COMPLETED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->sync_done = RDC_FAILED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&krdc->synccv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&net_blk_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_sync(rdc_config_t *uparms, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_t *rdc_set = uparms->rdc_set;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int options = uparms->options;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int busy = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *kmulti;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *umulti;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_srv_t *svp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sm, um, md;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sync_completed = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int thrcount;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = rdc_lookup_byname(rdc_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < 0 || (krdc->type_flag & RDC_DISABLEPEND)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EALREADY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto notstarted;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte set_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte busy = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((krdc->type_flag == 0) || (krdc->type_flag & RDC_DISABLEPEND)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* A resume or enable failed or we raced with a teardown */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EALREADY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto notstarted;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_STATE(urdc, RDC_LOGGING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_ESETNOTLOGGING, urdc->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana rc = RDC_ENOTLOGGING;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana goto notstarted_unlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_check(krdc, rdc_set)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EALREADY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto notstarted_unlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(urdc) & RDC_PRIMARY)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_ENOTPRIMARY, rdc_set->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->primary.file, rdc_set->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_ENOTPRIMARY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto notstarted_unlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((options & RDC_OPT_REVERSE) && (IS_STATE(urdc, RDC_QUEUING))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cannot reverse sync when queuing, need to go logging first
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EQNORSYNC, rdc_set->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->primary.file, rdc_set->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->secondary.file);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana rc = RDC_EQNORSYNC;
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana goto notstarted_unlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svp = krdc->lsrv;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->intf = rdc_add_to_if(svp, &(urdc->primary.addr),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &(urdc->secondary.addr), 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!krdc->intf) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EADDTOIF, urdc->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.intf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EADDTOIF;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto notstarted_unlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (urdc->volume_size == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Implies reserve failed when previous resume was done */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_get_details(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (urdc->volume_size == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_ENOBMAP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_ENOBMAP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto notstarted_unlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->dcio_bitmap == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_resume_bitmap(krdc) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_ENOBMAP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_ENOBMAP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto notstarted_unlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rdc_get_vflags(urdc) & RDC_BMP_FAILED) && (krdc->bitmapfd)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_reset_bitmap(krdc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EBITMAP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EBITMAP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto notstarted_unlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_MANY(krdc) || IS_MULTI(krdc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *ubad;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((ubad = rdc_allow_pri_sync(urdc, options)) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_ESTATE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ubad->primary.intf, ubad->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ubad->secondary.intf, ubad->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_ESTATE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto notstarted_unlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * there is a small window where _rdc_sync is still
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * running, but has cleared the RDC_SYNCING flag.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use aux_state which is only cleared
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * after _rdc_sync had done its 'death' broadcast.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->aux_state & RDC_AUXSYNCIP) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!rdc_get_vflags(urdc) & RDC_SYNCING) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_sync: "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "RDC_AUXSYNCIP set, SYNCING off");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_ESYNCING, rdc_set->primary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_ESYNCING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto notstarted_unlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->disk_status == 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_ESYNCING, rdc_set->primary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_ESYNCING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto notstarted_unlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((options & RDC_OPT_FORWARD) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_get_mflags(urdc) & RDC_RSYNC_NEEDED)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* cannot forward sync if a reverse sync is needed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_ERSYNCNEEDED, rdc_set->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->primary.file, rdc_set->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_ERSYNCNEEDED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto notstarted_unlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->sync_pos = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check if the rdc set is accessible on the remote node */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_net_getstate(krdc, &sm, &um, &md, FALSE) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Remote end may be inaccessible, or the rdc set is not
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * enabled at the remote end.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_ECONNOPEN, urdc->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_ECONNOPEN;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto notstarted_unlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_REVERSE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->remote_index = rdc_net_state(index, CCIO_RSYNC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->remote_index = rdc_net_state(index, CCIO_SLAVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->remote_index < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Remote note probably not in a valid state to be synced,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * as the state was fetched OK above.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_ERSTATE, urdc->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file, urdc->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->primary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_ERSTATE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto notstarted_unlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = check_filesize(index, kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_net_state(krdc->index, CCIO_ENABLELOG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto notstarted_unlock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->sync_done = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&krdc->bmapmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->aux_state |= RDC_AUXSYNCIP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&krdc->bmapmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_REVERSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_mflags(urdc, RDC_SLAVE | RDC_RSYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&krdc->bmapmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_VOL_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&krdc->bmapmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* LINTED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (kmulti = krdc->multi_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte umulti = &rdc_u_info[kmulti->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_ENABLED(umulti) && (rdc_get_vflags(umulti) &
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (RDC_VOL_FAILED | RDC_SYNC_NEEDED))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(umulti, RDC_SYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(umulti, RDC_VOL_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(umulti);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_FCAL_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_UPDATE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(urdc->volume_size != 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_net_getbmap(index,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte BMAP_LOG_BYTES(urdc->volume_size)) > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_ENOBMAP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_ENOBMAP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_net_state(index, CCIO_ENABLELOG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_SYNCING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_REVERSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_mflags(urdc, RDC_SLAVE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->type_flag & RDC_ASYNCMODE)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_ASYNC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->remote_index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags_log(urdc, RDC_LOGGING,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "failed to read remote bitmap");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_FULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This is a full sync (not an update sync), mark the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * entire bitmap dirty
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) RDC_FILL_BITMAP(krdc, FALSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_FULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * allow diskq->memq flusher to wake up
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&krdc->group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group->ra_queue.qfflags &= ~RDC_QFILLSLEEP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&krdc->group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if this is a full sync on a non-diskq set or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a diskq set that has failed, clear the async flag
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->type_flag & RDC_ASYNCMODE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((!(options & RDC_OPT_UPDATE)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (!RDC_IS_DISKQ(krdc->group)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (!(IS_STATE(urdc, RDC_QUEUING)))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* full syncs, or core queue are synchronous */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_ASYNC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if the queue failed because it was full, lets see
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if we can restart it. After _rdc_sync() is done
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the modes will switch and we will begin disk
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * queuing again. NOTE: this should only be called
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * once per group, as it clears state for all group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * members, also clears the async flag for all members
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_STATE(urdc, RDC_DISKQ_FAILED)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_unfail_diskq(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* don't add insult to injury by flushing a dead queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if we are updating, and a diskq and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the async thread isn't active, start
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it up.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((options & RDC_OPT_UPDATE) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (IS_STATE(urdc, RDC_QUEUING))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_SYNCING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&krdc->group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->group->ra_queue.qfill_sleeping ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_QFILL_ASLEEP)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&group->ra_queue.qfcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&krdc->group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte thrcount = urdc->asyncthr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((thrcount-- > 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !krdc->group->rdc_writer) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_writer(krdc->index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * For a reverse sync, merge the current bitmap with all other sets
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * that share this volume.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_REVERSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteretry_many:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_MANY(krdc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *kmany;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *umany;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (kmany = krdc->many_next; kmany != krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmany = kmany->many_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte umany = &rdc_u_info[kmany->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(umany))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(umany->flags & RDC_PRIMARY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!mutex_tryenter(&kmany->group->lock)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* May merge more than once */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry_many;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_merge_bitmaps(krdc, kmany);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&kmany->group->lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteretry_multi:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_MULTI(krdc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *kmulti = krdc->multi_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *umulti = &rdc_u_info[kmulti->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_ENABLED(umulti)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(!(umulti->flags & RDC_PRIMARY));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!mutex_tryenter(&kmulti->group->lock)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retry_multi;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_merge_bitmaps(krdc, kmulti);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&kmulti->group->lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->bitmap_write == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_write_bitmap_fill(krdc) >= 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->bitmap_write = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->bitmap_write > 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_write_bitmap(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->bits_set = RDC_COUNT_BITMAP(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_REVERSE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _rdc_sync_event_notify(RDC_SYNC_START,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->primary.file, urdc->group_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Now set off the sync itself */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&net_blk_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nsc_create_process(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void (*)(void *))_rdc_sync, (void *)krdc, FALSE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&net_blk_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_ENOPROC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We used to just return here,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * but we need to clear the AUXSYNCIP bit
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and there is a very small chance that
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * someone may be waiting on the disk_status flag.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_ENOPROC;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * need the group lock held at failed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wakeup_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte busy = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (krdc->sync_done == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_wait(&krdc->synccv, &net_blk_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&net_blk_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->sync_done == RDC_FAILED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char siztmp1[16];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) spcs_s_inttostring(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->sync_pos, siztmp1, sizeof (siztmp1),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EFAIL, siztmp1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EFAIL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sync_completed = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefailed:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We use this flag now to make halt_sync() wait for
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * us to terminate and let us take the group lock.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->aux_state &= ~RDC_AUXSYNCIP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->disk_status == 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->disk_status = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&krdc->haltcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortenotstarted_unlock:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (sync_completed && (options & RDC_OPT_REVERSE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) _rdc_sync_event_notify(RDC_SYNC_DONE,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->primary.file, urdc->group_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortenotstarted:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (busy) {
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 return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_suspend(rdc_k_info_t *krdc, rdc_set_t *rdc_set, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_if_t *ip;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index = krdc->index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(krdc->group != NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(rdc_check(krdc, rdc_set) == 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_check(krdc, rdc_set)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_PRIMARY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte halt_sync(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(IS_ENABLED(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_unintercept(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!SNDR: suspended %s %s", urdc->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Configured but not enabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(IS_CONFIGURED(krdc) && !IS_ENABLED(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_ASYNC(urdc) && !RDC_IS_DISKQ(krdc->group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int tries = 2; /* in case of possibly stuck flusher threads */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte net_queue *qp = &krdc->group->ra_queue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!krdc->group->rdc_writer)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_writer(krdc->index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_drain_queue(krdc->index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (krdc->group->rdc_writer && tries--);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* ok, force it to happen... */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_drain_queue(krdc->index) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&krdc->group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group->asyncdis = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&krdc->group->asyncqcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&krdc->group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!SNDR: async I/O pending and not flushed "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "for %s during suspend",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->primary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!nitems: %" NSC_SZFMT " nblocks: %"
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana NSC_SZFMT " head: 0x%p tail: 0x%p",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana qp->nitems, qp->blocks,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (void *)qp->net_qhead,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (void *)qp->net_qtail);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } while (krdc->group->rdc_thrnum > 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ip = krdc->intf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->intf = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ip) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_remove_from_if(ip);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Configured but not enabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(IS_CONFIGURED(krdc) && !IS_ENABLED(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Must not hold group lock during this function */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (rdc_dump_alloc_bufs_cd(krdc->index) == EAGAIN)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Don't rdc_clear_state, unlike _rdc_disable */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_free_bitmap(krdc, RDC_CMD_SUSPEND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_close_bitmap(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dev_close(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_close_direct(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Configured but not enabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(IS_CONFIGURED(krdc) && !IS_ENABLED(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we should now unregister the queue, with no conflicting
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * locks held. This is the last(only) member of the group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->group && RDC_IS_DISKQ(krdc->group) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group->count == 1) { /* stop protecting queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_unintercept_diskq(krdc->group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Configured but not enabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(IS_CONFIGURED(krdc) && !IS_ENABLED(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wait_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_MANY(krdc) || IS_MULTI(krdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte remove_from_many(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte remove_from_group(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->remote_index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(krdc->type_flag & RDC_CONFIGURED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(krdc->type_flag & RDC_DISABLEPEND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->type_flag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->dcio_bitmap)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!_rdc_suspend: possible mem leak, "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "dcio_bitmap");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->dcio_bitmap = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->bitmap_ref = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->bitmap_size = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->maxfbas = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->bitmap_write = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->disk_status = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_destroy_svinfo(krdc->lsrv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->lsrv = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->multi_next = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_init(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_kstat_delete(index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_suspend(rdc_config_t *uparms, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = rdc_lookup_byname(uparms->rdc_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < 0 || (krdc->type_flag & RDC_DISABLEPEND)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->type_flag |= RDC_DISABLEPEND;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wait_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->type_flag == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* A resume or enable failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _rdc_suspend(krdc, uparms->rdc_set, kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_resume(rdc_set_t *rdc_set, int options, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *rhost;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct netbuf *addrp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_srv_t *svp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *local_file;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *local_bitmap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc, rc1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t maxfbas;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *grp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rdc_set->primary.intf[0] == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_set->primary.addr.len == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_set->primary.file[0] == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_set->primary.bitmap[0] == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_set->secondary.intf[0] == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_set->secondary.addr.len == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_set->secondary.file[0] == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_set->secondary.bitmap[0] == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EEMPTY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EEMPTY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Next check there aren't any enabled rdc sets which match. */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_lookup_byname(rdc_set) >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EENABLED, rdc_set->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->primary.file, rdc_set->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EENABLED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_lookup_many2one(rdc_set) >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EMANY2ONE, rdc_set->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->primary.file, rdc_set->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EMANY2ONE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_set->netconfig->knc_proto == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_ENETCONFIG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_ENETCONFIG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_set->primary.addr.len == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_ENETBUF, rdc_set->primary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_ENETBUF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_set->secondary.addr.len == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_ENETBUF, rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_ENETBUF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check that the local data volume isn't in use as a bitmap */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_PRIMARY)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_file = rdc_set->primary.file;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_file = rdc_set->secondary.file;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_lookup_bitmap(local_file) >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EVOLINUSE, local_file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EVOLINUSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* check that the secondary data volume isn't in use */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(options & RDC_OPT_PRIMARY)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_file = rdc_set->secondary.file;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_lookup_secondary(local_file) >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EVOLINUSE, local_file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EVOLINUSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check that the bitmap isn't in use as a data volume */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_PRIMARY)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_bitmap = rdc_set->primary.bitmap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte local_bitmap = rdc_set->secondary.bitmap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_lookup_configured(local_bitmap) >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EBMPINUSE, local_bitmap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EBMPINUSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Check that the bitmap isn't already in use as a bitmap */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_lookup_bitmap(local_bitmap) >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EBMPINUSE, local_bitmap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EBMPINUSE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Set urdc->volume_size */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = rdc_dev_open(rdc_set, options);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_PRIMARY)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EOPEN, rdc_set->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->primary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EOPEN, rdc_set->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EOPEN);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* copy relevant parts of rdc_set to urdc field by field */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->primary.intf, rdc_set->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MAX_RDC_HOST_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->secondary.intf, rdc_set->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte MAX_RDC_HOST_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->group_name, rdc_set->group_name, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dup_rdc_netbuf(&rdc_set->primary.addr, &urdc->primary.addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->primary.file, rdc_set->primary.file, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->primary.bitmap, rdc_set->primary.bitmap,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dup_rdc_netbuf(&rdc_set->secondary.addr, &urdc->secondary.addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->secondary.file, rdc_set->secondary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->secondary.bitmap, rdc_set->secondary.bitmap,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->disk_queue, rdc_set->disk_queue, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->setid = rdc_set->setid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((options & RDC_OPT_SYNC) && urdc->disk_queue[0]) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dev_close(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EQWRONGMODE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EQWRONGMODE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * init flags now so that state left by failures in add_to_group()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * are preserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_init_flags(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc1 = add_to_group(krdc, options, RDC_CMD_RESUME)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc1 == RDC_EQNOADD) { /* something went wrong with queue */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_fail_diskq(krdc, RDC_WAIT, RDC_NOLOG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* don't return a failure here, continue with resume */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else { /* some other group add failure */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dev_close(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EGROUP,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->primary.intf, rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->secondary.intf, rdc_set->secondary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->group_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EGROUP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * maxfbas was set in rdc_dev_open as primary's maxfbas.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If diskq's maxfbas is smaller, then use diskq's.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grp = krdc->group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (grp && RDC_IS_DISKQ(grp) && (grp->diskqfd != 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _rdc_rsrv_diskq(grp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_SUCCESS(rc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_maxfbas(grp->diskqfd, 0, &maxfbas);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->maxfbas != maxfbas)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!_rdc_resume: diskq maxfbas = %"
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana NSC_SZFMT ", primary maxfbas = %"
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana NSC_SZFMT, maxfbas, krdc->maxfbas);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana krdc->maxfbas = min(krdc->maxfbas,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana maxfbas);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!_rdc_resume: diskq maxfbas failed (%d)",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_diskq(grp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!_rdc_resume: diskq reserve failed (%d)", rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->direct_file, rdc_set->direct_file, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((options & RDC_OPT_PRIMARY) && rdc_set->direct_file[0]) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_open_direct(krdc) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_FCAL_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->many_next = krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(krdc->type_flag == 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->type_flag = RDC_CONFIGURED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_PRIMARY)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_PRIMARY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_ASYNC)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->type_flag |= RDC_ASYNCMODE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte set_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->syshostid = rdc_set->syshostid;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (add_to_many(krdc) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EMULTI);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EMULTI;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Configured but not enabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(IS_CONFIGURED(krdc) && !IS_ENABLED(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (urdc->volume_size == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_PRIMARY)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_mflags(urdc, RDC_RSYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_SYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_VOL_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Configured but not enabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(IS_CONFIGURED(krdc) && !IS_ENABLED(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The rdc set is configured but not yet enabled. Other operations must
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ignore this set until it is enabled.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->sync_pos = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Set tunable defaults, we'll pick up tunables from the header later */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->maxqfbas = rdc_maxthres_queue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->maxqitems = rdc_max_qitems;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->autosync = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->asyncthr = rdc_asyncthr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->netconfig = rdc_set->netconfig;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_PRIMARY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rhost = rdc_set->secondary.intf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte addrp = &rdc_set->secondary.addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rhost = rdc_set->primary.intf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte addrp = &rdc_set->primary.addr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_ASYNC)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_ASYNC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svp = rdc_create_svinfo(rhost, addrp, urdc->netconfig);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (svp == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, ENOMEM);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = ENOMEM;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto fail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->netconfig = NULL; /* This will be no good soon */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Don't set krdc->intf here */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_kstat_create(index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* if the bitmap resume isn't clean, it will clear queuing flag */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_resume_bitmap(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(krdc->group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *q = &krdc->group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc1 == RDC_EQNOADD) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte IS_QSTATE(q, RDC_QBADRESUME)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_QUEUING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_ZERO_BITREF(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->lsrv == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->lsrv = svp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!_rdc_resume: krdc->lsrv already set: %p",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (void *) krdc->lsrv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_destroy_svinfo(svp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Configured but not enabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(IS_CONFIGURED(krdc) && !IS_ENABLED(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* And finally */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->remote_index = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Should we set the whole group logging? */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_ENABLED | RDC_LOGGING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_intercept(krdc) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_ENABLED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_PRIMARY)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EREGISTER, urdc->primary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EREGISTER,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!nsc_register_path failed %s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->primary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EREGISTER;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto bmpfail;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!SNDR: resumed %s %s", urdc->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
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 return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortebmpfail:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (options & RDC_OPT_PRIMARY)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EBITMAP, urdc->primary.bitmap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EBITMAP, urdc->secondary.bitmap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EBITMAP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_ENABLED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_unintercept(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefail:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_kstat_delete(index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Don't unset krdc->intf here, unlike _rdc_enable */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Configured but not enabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(IS_CONFIGURED(krdc) && !IS_ENABLED(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_dev_close(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_close_direct(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_destroy_svinfo(svp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Configured but not enabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(IS_CONFIGURED(krdc) && !IS_ENABLED(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Configured but not enabled */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(IS_CONFIGURED(krdc) && !IS_ENABLED(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte remove_from_group(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_MANY(krdc) || IS_MULTI(krdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte remove_from_many(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_init(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(krdc->type_flag & RDC_CONFIGURED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->type_flag = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wakeup_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_resume(rdc_config_t *uparms, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char itmp[10];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(uparms->options & RDC_OPT_SYNC) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !(uparms->options & RDC_OPT_ASYNC)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) spcs_s_inttostring(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->options, itmp, sizeof (itmp), 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EEINVAL, itmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EEINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(uparms->options & RDC_OPT_PRIMARY) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !(uparms->options & RDC_OPT_SECONDARY)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) spcs_s_inttostring(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->options, itmp, sizeof (itmp), 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EEINVAL, itmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EEINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _rdc_resume(uparms->rdc_set, uparms->options, kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if rdc_group_log is called because a volume has failed,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * we must disgard the queue to preserve write ordering.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * later perhaps, we can keep queuing, but we would have to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rewrite the i/o path to acommodate that. currently, if there
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is a volume failure, the buffers are satisfied remotely and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * there is no way to satisfy them from the current diskq config
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * phew, if we do that.. it will be difficult
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_can_queue(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (p = krdc->group_next; ; p = p->group_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &rdc_u_info[p->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_STATE(q, RDC_VOL_FAILED))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (p == krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * wait here, until all in flight async i/o's have either
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * finished or failed. Avoid the race with r_net_state()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * which tells remote end to log.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_inflwait(rdc_group_t *grp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int bail = RDC_CLNT_TMOUT * 2; /* to include retries */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte volatile int *inflitems;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(grp))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inflitems = (&(grp->diskq.inflitems));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte inflitems = (&(grp->ra_queue.inflitems));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (*inflitems && (--bail > 0))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(HZ);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_group_log(rdc_k_info_t *krdc, int flag, char *why)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int do_group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sm, um, md;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *dq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void (*flag_op)(rdc_u_info_t *urdc, int flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&krdc->group->lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((flag & RDC_QUEUING) && (!IS_STATE(urdc, RDC_SYNCING)) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_can_queue(krdc))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flag_op = rdc_set_flags; /* keep queuing, link error */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flag &= ~RDC_FLUSH;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flag_op = rdc_clr_flags; /* stop queuing, user request */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do_group = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(urdc) & RDC_PRIMARY))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do_group = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if ((urdc->group_name[0] == 0) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_get_vflags(urdc) & RDC_LOGGING) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_get_vflags(urdc) & RDC_SYNCING))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do_group = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (do_group) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (p = krdc->group_next; p != krdc; p = p->group_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &rdc_u_info[p->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(q))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rdc_get_vflags(q) & RDC_LOGGING) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rdc_get_vflags(q) & RDC_SYNCING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do_group = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!do_group && (flag & RDC_FORCE_GROUP))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte do_group = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dq = &krdc->group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (do_group) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!SNDR:Group point-in-time for grp: %s %s:%s",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->group_name, urdc->primary.intf, urdc->secondary.intf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DTRACE_PROBE(rdc_diskq_group_PIT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Set group logging at the same PIT under rdc_many_lock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags_log(urdc, RDC_LOGGING, why);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(krdc->group))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flag_op(urdc, RDC_QUEUING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (p = krdc->group_next; p != krdc; p = p->group_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &rdc_u_info[p->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(q))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags_log(q, RDC_LOGGING,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "consistency group member following leader");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(p->group))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flag_op(q, RDC_QUEUING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This can cause the async threads to fail,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * which in turn will call rdc_group_log()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * again. Release the lock and re-aquire.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (rdc_dump_alloc_bufs_cd(krdc->index) == EAGAIN)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_IS_DISKQ(krdc->group))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_ZERO_BITREF(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_inflwait(krdc->group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a little lazy, but neat. recall dump_alloc_bufs to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ensure that the queue pointers & seq are reset properly
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * after we have waited for inflight stuff
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (rdc_dump_alloc_bufs_cd(krdc->index) == EAGAIN)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(krdc->group) && (!(flag & RDC_QUEUING))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* fail or user request */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_ZERO_BITREF(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&krdc->group->diskq.disk_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_init_diskq_header(krdc->group,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &krdc->group->diskq.disk_hdr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QNXTIO(dq, QHEAD(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&krdc->group->diskq.disk_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & RDC_ALLREMOTE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Tell other node to start logging */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->lsrv && krdc->intf && !krdc->intf->if_down)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_net_state(krdc->index,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CCIO_ENABLELOG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & (RDC_ALLREMOTE | RDC_OTHERREMOTE)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (p = krdc->group_next; p != krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = p->group_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (p->lsrv && krdc->intf &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !krdc->intf->if_down) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_net_state(p->index,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana CCIO_ENABLELOG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (p = krdc->group_next; p != krdc; p = p->group_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &rdc_u_info[p->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(q))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte continue;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* No point in time is possible, just deal with single set */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_PRIMARY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte halt_sync(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_net_getstate(krdc, &sm, &um, &md, TRUE) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_SYNCING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags_log(urdc, RDC_LOGGING,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "failed to read remote state");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (rdc_dump_alloc_bufs_cd(krdc->index)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte == EAGAIN)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((RDC_IS_DISKQ(krdc->group)) &&
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (!(flag & RDC_QUEUING))) { /* fail! */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_init_diskq_header(krdc->group,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &krdc->group->diskq.disk_hdr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QNXTIO(dq, QHEAD(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_SYNCING)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(krdc->group))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte flag_op(urdc, RDC_QUEUING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((RDC_IS_DISKQ(krdc->group)) &&
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (!(flag & RDC_QUEUING))) { /* fail! */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_ZERO_BITREF(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_init_diskq_header(krdc->group,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &krdc->group->diskq.disk_hdr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QNXTIO(dq, QHEAD(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(urdc) & RDC_LOGGING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags_log(urdc, RDC_LOGGING, why);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (rdc_dump_alloc_bufs_cd(krdc->index) == EAGAIN)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_IS_DISKQ(krdc->group))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_ZERO_BITREF(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_inflwait(krdc->group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * a little lazy, but neat. recall dump_alloc_bufs to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ensure that the queue pointers & seq are reset
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * properly after we have waited for inflight stuff
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (rdc_dump_alloc_bufs_cd(krdc->index) == EAGAIN)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte delay(2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & RDC_ALLREMOTE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Tell other node to start logging */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->lsrv && krdc->intf &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte !krdc->intf->if_down) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_net_state(krdc->index,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CCIO_ENABLELOG);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * just in case any threads were in flight during log cleanup
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(krdc->group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_broadcast(&dq->qfullcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(dq));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_log(rdc_k_info_t *krdc, rdc_set_t *rdc_set, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_srv_t *svp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_check(krdc, rdc_set)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte svp = krdc->lsrv;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_PRIMARY)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->intf = rdc_add_to_if(svp, &(urdc->primary.addr),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &(urdc->secondary.addr), 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->intf = rdc_add_to_if(svp, &(urdc->secondary.addr),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &(urdc->primary.addr), 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!krdc->intf) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EADDTOIF, urdc->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.intf);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EADDTOIF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_log(krdc, RDC_FLUSH | RDC_ALLREMOTE, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_SYNCING) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_ESYNCING, urdc->primary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_ESYNCING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_log(rdc_config_t *uparms, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = rdc_lookup_byname(uparms->rdc_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < 0 || (krdc->type_flag & RDC_DISABLEPEND)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte set_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->type_flag == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* A resume or enable failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wakeup_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _rdc_log(krdc, uparms->rdc_set, kstatus);
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 return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_wait(rdc_config_t *uparms, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int need_check = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = rdc_lookup_byname(uparms->rdc_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < 0 || (krdc->type_flag & RDC_DISABLEPEND)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(urdc) & RDC_PRIMARY)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte set_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->type_flag == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* A resume or enable failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wakeup_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_check(krdc, uparms->rdc_set)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wakeup_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rdc_get_vflags(urdc) & (RDC_SYNCING | RDC_PRIMARY)) !=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (RDC_SYNCING | RDC_PRIMARY)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wakeup_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_SYNCING) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte need_check = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&net_blk_lock);
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) cv_wait_sig(&krdc->synccv, &net_blk_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&net_blk_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (need_check) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->sync_done == RDC_COMPLETED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (krdc->sync_done == RDC_FAILED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_health(rdc_config_t *uparms, spcs_s_info_t kstatus, int *rvp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = rdc_lookup_byname(uparms->rdc_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < 0 || (krdc->type_flag & RDC_DISABLEPEND)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte set_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->type_flag == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* A resume or enable failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wakeup_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_check(krdc, uparms->rdc_set)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EALREADY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_isactive_if(&(urdc->primary.addr), &(urdc->secondary.addr)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *rvp = RDC_ACTIVE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *rvp = RDC_INACTIVE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wakeup_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_reconfig(rdc_config_t *uparms, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = -2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = rdc_lookup_byname(uparms->rdc_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < 0 || (krdc->type_flag & RDC_DISABLEPEND)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte set_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->type_flag == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* A resume or enable failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wakeup_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_check(krdc, uparms->rdc_set)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EALREADY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rdc_get_vflags(urdc) & RDC_BMP_FAILED) && (krdc->bitmapfd))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_reset_bitmap(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Move to a new bitmap if necessary */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(urdc->primary.bitmap, uparms->rdc_set->primary.bitmap,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_PRIMARY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_move_bitmap(krdc,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->primary.bitmap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->primary.bitmap,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->primary.bitmap, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* simulate a succesful rdc_move_bitmap */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(urdc->secondary.bitmap, uparms->rdc_set->secondary.bitmap,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_PRIMARY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->secondary.bitmap,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.bitmap, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* simulate a succesful rdc_move_bitmap */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_move_bitmap(krdc,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.bitmap);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == -1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EBMPRECONFIG,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EBMPRECONFIG;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * At this point we fail any other type of reconfig
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if not in logging mode and we did not do a bitmap reconfig
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(urdc) & RDC_LOGGING) && rc == -2) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no other changes possible unless logging */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_ENOTLOGGING,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_ENOTLOGGING;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Change direct file if necessary */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rdc_get_vflags(urdc) & RDC_PRIMARY) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte strncmp(urdc->direct_file, uparms->rdc_set->direct_file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(urdc) & RDC_LOGGING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto notlogging;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_close_direct(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->direct_file, uparms->rdc_set->direct_file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (urdc->direct_file[0]) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_open_direct(krdc) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_FCAL_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_FCAL_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Change group if necessary */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (strncmp(urdc->group_name, uparms->rdc_set->group_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char orig_group[NSC_MAXPATH];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(urdc) & RDC_LOGGING))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto notlogging;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(orig_group, urdc->group_name, NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->group_name, uparms->rdc_set->group_name,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = change_group(krdc, uparms->options);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == RDC_EQNOADD) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EQNOADD,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->disk_queue);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (rc < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->group_name, orig_group,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EGROUP,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana urdc->primary.intf, urdc->primary.file,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana urdc->secondary.intf, urdc->secondary.file,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana uparms->rdc_set->group_name);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EGROUP;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(urdc) & RDC_LOGGING))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto notlogging;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (uparms->options & RDC_OPT_ASYNC) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->type_flag |= RDC_ASYNCMODE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (uparms->options & RDC_OPT_PRIMARY)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->bitmap_ref =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uchar_t *)kmem_zalloc(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (krdc->bitmap_size * BITS_IN_BYTE *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte BMAP_REF_PREF_SIZE), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_ASYNC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->type_flag &= ~RDC_ASYNCMODE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_ASYNC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->bitmap_ref) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(krdc->bitmap_ref,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (krdc->bitmap_size * BITS_IN_BYTE *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte BMAP_REF_PREF_SIZE));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->bitmap_ref = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((((uparms->options & RDC_OPT_ASYNC) == 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((krdc->type_flag & RDC_ASYNCMODE) != 0)) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (((uparms->options & RDC_OPT_ASYNC) != 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((krdc->type_flag & RDC_ASYNCMODE) == 0))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(urdc) & RDC_LOGGING))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto notlogging;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->group->count > 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EGROUPMODE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EGROUPMODE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Switch sync/async if necessary */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->group->count == 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Only member of group. Can change sync/async */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((uparms->options & RDC_OPT_ASYNC) == 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((krdc->type_flag & RDC_ASYNCMODE) != 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(urdc) & RDC_LOGGING))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto notlogging;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* switch to sync */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->type_flag &= ~RDC_ASYNCMODE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(krdc->group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group->flags &= ~RDC_DISKQUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->group->flags |= RDC_MEMQUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_unintercept_diskq(krdc->group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&krdc->group->diskqmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_close_diskq(krdc->group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&krdc->group->diskqmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&urdc->disk_queue,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (urdc->disk_queue));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_ASYNC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->bitmap_ref) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(krdc->bitmap_ref,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (krdc->bitmap_size * BITS_IN_BYTE *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte BMAP_REF_PREF_SIZE));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->bitmap_ref = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (((uparms->options & RDC_OPT_ASYNC) != 0) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((krdc->type_flag & RDC_ASYNCMODE) == 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(urdc) & RDC_LOGGING))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto notlogging;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* switch to async */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->type_flag |= RDC_ASYNCMODE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (uparms->options & RDC_OPT_PRIMARY)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->bitmap_ref =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uchar_t *)kmem_zalloc(
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (krdc->bitmap_size * BITS_IN_BYTE *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte BMAP_REF_PREF_SIZE), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_ASYNC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Reverse concept of primary and secondary */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((uparms->options & RDC_OPT_REVERSE_ROLE) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_t rdc_set;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct netbuf paddr, saddr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Disallow role reversal for advanced configurations
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_MANY(krdc) || IS_MULTI(krdc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana spcs_s_add(kstatus, RDC_EMASTER, urdc->primary.intf,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana urdc->primary.file, urdc->secondary.intf,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EMASTER);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero((void *) &rdc_set, sizeof (rdc_set_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dup_rdc_netbuf(&urdc->primary.addr, &saddr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dup_rdc_netbuf(&urdc->secondary.addr, &paddr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_rdc_netbuf(&urdc->primary.addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_rdc_netbuf(&urdc->secondary.addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dup_rdc_netbuf(&saddr, &urdc->secondary.addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dup_rdc_netbuf(&paddr, &urdc->primary.addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_rdc_netbuf(&paddr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte free_rdc_netbuf(&saddr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* copy primary parts of urdc to rdc_set field by field */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(rdc_set.primary.intf, urdc->primary.intf,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana MAX_RDC_HOST_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(rdc_set.primary.file, urdc->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(rdc_set.primary.bitmap, urdc->primary.bitmap,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Now overwrite urdc primary */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->primary.intf, urdc->secondary.intf,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana MAX_RDC_HOST_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->primary.file, urdc->secondary.file,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->primary.bitmap, urdc->secondary.bitmap,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Now ovwewrite urdc secondary */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->secondary.intf, rdc_set.primary.intf,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana MAX_RDC_HOST_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->secondary.file, rdc_set.primary.file,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(urdc->secondary.bitmap, rdc_set.primary.bitmap,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_get_vflags(urdc) & RDC_PRIMARY) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_PRIMARY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->intf) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->intf->issecondary = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->intf->isprimary = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->intf->if_down = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_PRIMARY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->intf) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->intf->issecondary = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->intf->isprimary = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->intf->if_down = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rdc_get_vflags(urdc) & RDC_PRIMARY) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((krdc->type_flag & RDC_ASYNCMODE) != 0)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!krdc->bitmap_ref)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->bitmap_ref =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (uchar_t *)kmem_zalloc((krdc->bitmap_size *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte BITS_IN_BYTE * BMAP_REF_PREF_SIZE),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->bitmap_ref == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!rdc_reconfig: bitmap_ref alloc %"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_SZFMT " failed",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->bitmap_size * BITS_IN_BYTE *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte BMAP_REF_PREF_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (-1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rdc_get_vflags(urdc) & RDC_PRIMARY) &&
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana (rdc_get_vflags(urdc) & RDC_SYNC_NEEDED)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Primary, so reverse sync needed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_SYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_mflags(urdc, RDC_RSYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if (rdc_get_vflags(urdc) & RDC_RSYNC_NEEDED) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Secondary, so forward sync needed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_RSYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_SYNC_NEEDED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rewrite bitmap header
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wakeup_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortenotlogging:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* no other changes possible unless logging */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wakeup_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_ENOTLOGGING, urdc->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->primary.file, urdc->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_ENOTLOGGING);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_reset(rdc_config_t *uparms, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cleared_error = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = rdc_lookup_byname(uparms->rdc_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < 0 || (krdc->type_flag & RDC_DISABLEPEND)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte set_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->type_flag == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* A resume or enable failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wakeup_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_check(krdc, uparms->rdc_set)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EALREADY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rdc_get_vflags(urdc) & RDC_BMP_FAILED) && (krdc->bitmapfd)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_reset_bitmap(krdc) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cleared_error++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Fix direct file if necessary */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rdc_get_vflags(urdc) & RDC_PRIMARY) && urdc->direct_file[0]) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_open_direct(krdc) == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags(urdc, RDC_FCAL_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_FCAL_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cleared_error++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rdc_get_vflags(urdc) & RDC_VOL_FAILED)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_clr_flags(urdc, RDC_VOL_FAILED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cleared_error++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cleared_error) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* cleared an error so we should be in logging mode */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_set_flags_log(urdc, RDC_LOGGING, "set reset");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rdc_get_vflags(urdc) & RDC_DISKQ_FAILED))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_unfail_diskq(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wakeup_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_tunable(rdc_config_t *uparms, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *q;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = rdc_lookup_byname(uparms->rdc_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < 0 || (krdc->type_flag & RDC_DISABLEPEND)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte set_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->type_flag == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* A resume or enable failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wakeup_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_check(krdc, uparms->rdc_set)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EALREADY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (uparms->rdc_set->maxqfbas > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->maxqfbas = uparms->rdc_set->maxqfbas;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (p = krdc->group_next; p != krdc; p = p->group_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &rdc_u_info[p->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->maxqfbas = urdc->maxqfbas;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (uparms->rdc_set->maxqitems > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->maxqitems = uparms->rdc_set->maxqitems;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (p = krdc->group_next; p != krdc; p = p->group_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &rdc_u_info[p->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->maxqitems = urdc->maxqitems;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (uparms->options & RDC_OPT_SET_QNOBLOCK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *que;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_IS_DISKQ(krdc->group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EQNOQUEUE, urdc->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->primary.file, urdc->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EQNOQUEUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte que = &krdc->group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(que));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte SET_QSTATE(que, RDC_QNOBLOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* queue will fail if this fails */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_stamp_diskq(krdc, 0, RDC_GROUP_LOCKED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(que));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (uparms->options & RDC_OPT_CLR_QNOBLOCK) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *que;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!RDC_IS_DISKQ(krdc->group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EQNOQUEUE, urdc->primary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->primary.file, urdc->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EQNOQUEUE;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte que = &krdc->group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(QLOCK(que));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte CLR_QSTATE(que, RDC_QNOBLOCK);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* queue will fail if this fails */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) rdc_stamp_diskq(krdc, 0, RDC_GROUP_LOCKED);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(QLOCK(que));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (uparms->rdc_set->asyncthr > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->asyncthr = uparms->rdc_set->asyncthr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (p = krdc->group_next; p != krdc; p = p->group_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &rdc_u_info[p->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->asyncthr = urdc->asyncthr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (uparms->rdc_set->autosync >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (uparms->rdc_set->autosync == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->autosync = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->autosync = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(urdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Changed autosync, so update rest of the group */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (p = krdc->group_next; p != krdc; p = p->group_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q = &rdc_u_info[p->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte q->autosync = urdc->autosync;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_write_state(q);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
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 return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_status(void *arg, int mode, rdc_config_t *uparms, spcs_s_info_t kstatus)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disk_queue *dqp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *ptr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte extern int rdc_status_copy32(const void *, void *, size_t, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = rdc_lookup_byname(uparms->rdc_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < 0 || (krdc->type_flag & RDC_DISABLEPEND)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte set_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->type_flag == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* A resume or enable failed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wakeup_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (RDC_EALREADY);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rdc_check(krdc, uparms->rdc_set)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_EALREADY, uparms->rdc_set->primary.file,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uparms->rdc_set->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_EALREADY;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sneak out qstate in urdc->flags
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * this is harmless because it's value is not used
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in urdc->flags. the real qstate is kept in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * group->diskq->disk_hdr.h.state
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (RDC_IS_DISKQ(krdc->group)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dqp = &krdc->group->diskq;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_QSTATE(dqp, RDC_QNOBLOCK))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->flags |= RDC_QNOBLOCK;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_model_convert_from(mode & FMODELS) == DDI_MODEL_ILP32) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ptr = (char *)arg + offsetof(struct rdc_config32, rdc_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_status_copy32(urdc, ptr, sizeof (struct rdc_set32),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ptr = (char *)arg + offsetof(struct rdc_config, rdc_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = ddi_copyout(urdc, ptr, sizeof (struct rdc_set), mode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* clear out qstate from flags */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->flags &= ~RDC_QNOBLOCK;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wakeup_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Overwrite the bitmap with one supplied by the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * user.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copy into all bitmaps that are tracking this volume.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_bitmapset(int op, char *sechost, char *secdev, void *bmapaddr, int bmapsz,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t off, int mode)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int *indexvec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int indexit;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmutex_t **grouplocks;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int i;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int groupind;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (off % FBA_SIZE(1)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Must be modulo FBA */
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!bitmapset: Offset is not on an FBA "
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "boundary %llu", (unsigned long long)off);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (bmapsz % FBA_SIZE(1)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Must be modulo FBA */
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!bitmapset: Size is not on an FBA "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "boundary %d", bmapsz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte index = rdc_lookup_byhostdev(sechost, secdev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index < 0 || (krdc->type_flag & RDC_DISABLEPEND)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = ENODEV;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte indexvec = kmem_alloc(rdc_max_sets * sizeof (int), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grouplocks = kmem_alloc(rdc_max_sets * sizeof (kmutex_t *), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * I now have this set, and I want to take the group
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * lock on it, and all the group locks of all the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * sets on the many and multi-hop links.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * I have to take the many lock while traversing the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * many/multi links.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * I think I also need to set the busy count on this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * set, otherwise when I drop the conf_lock, what
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * will stop some other process from coming in and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * issuing a disable?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte set_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteretrylock:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte groupind = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte indexit = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_enter(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Take this initial sets group lock first.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!mutex_tryenter(&krdc->group->lock)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retrylock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grouplocks[groupind] = &krdc->group->lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte groupind++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_checkforbitmap(index, off + bmapsz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte indexvec[indexit] = index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte indexit++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_MANY(krdc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *ktmp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (ktmp = krdc->many_next; ktmp != krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ktmp = ktmp->many_next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * attempt to take the group lock,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * if we don't already have it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ktmp->group == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = ENODEV;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < groupind; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (grouplocks[i] == &ktmp->group->lock)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* already have the group lock */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * didn't find our lock in our collection,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * attempt to take group lock.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (i >= groupind) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!mutex_tryenter(&ktmp->group->lock)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < groupind; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(grouplocks[i]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retrylock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grouplocks[groupind] = &ktmp->group->lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte groupind++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_checkforbitmap(ktmp->index, off + bmapsz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte indexvec[indexit] = ktmp->index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte indexit++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (IS_MULTI(krdc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *kmulti = krdc->multi_next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (kmulti->group == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = ENODEV;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This can't be in our group already.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!mutex_tryenter(&kmulti->group->lock)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < groupind; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(grouplocks[i]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto retrylock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte grouplocks[groupind] = &kmulti->group->lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte groupind++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_checkforbitmap(kmulti->index, off + bmapsz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte indexvec[indexit] = kmulti->index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte indexit++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto done;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_installbitmap(op, bmapaddr, bmapsz, off, mode, indexvec,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte indexit);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortedone:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (i = 0; i < groupind; i++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(grouplocks[i]);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_many_exit(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte wakeup_busy(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(indexvec, rdc_max_sets * sizeof (int));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(grouplocks, rdc_max_sets * sizeof (kmutex_t *));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_checkforbitmap(int index, nsc_off_t limit)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(rdc_get_vflags(urdc) & RDC_LOGGING)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENXIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->dcio_bitmap == NULL) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!checkforbitmap: No bitmap for set (%s:%s)",
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana urdc->secondary.intf, urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENOENT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (limit > krdc->bitmap_size) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!checkbitmap: Bitmap exceeded, "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "incore %" NSC_SZFMT " user supplied %" NSC_SZFMT
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana " for set (%s:%s)", krdc->bitmap_size,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana limit, urdc->secondary.intf, urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENOSPC);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copy the user supplied bitmap to this set.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_installbitmap(int op, void *bmapaddr, int bmapsz,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t off, int mode, int *vec, int veccnt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t sfba;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t efba;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t fba;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte void *ormem = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int left;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int copied;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ormem = kmem_alloc(RDC_MAXDATA, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte left = bmapsz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte copied = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (left > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (left > RDC_MAXDATA) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = RDC_MAXDATA;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len = left;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_copyin((char *)bmapaddr + copied, ormem,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len, mode)) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!installbitmap: Copyin failed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sfba = FBA_NUM(off + copied);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte efba = FBA_NUM(off + copied + len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (index = 0; index < veccnt; index++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[vec[index]];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[vec[index]];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&krdc->bmapmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (op == RDC_BITMAPSET) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(ormem, krdc->dcio_bitmap + off + copied,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_lor(ormem,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->dcio_bitmap + off + copied, len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Maybe this should be just done once outside of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the the loop? (Less work, but leaves a window
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * where the bits_set doesn't match the bitmap).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->bits_set = RDC_COUNT_BITMAP(krdc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&krdc->bmapmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->bitmap_write > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (fba = sfba; fba < efba; fba++) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc = rdc_write_bitmap_fba(krdc,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fba)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "!installbitmap: "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "write_bitmap_fba failed "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "on fba number %" NSC_SZFMT
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana " set %s:%s", fba,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.intf,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->secondary.file);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte copied += len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte left -= len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ormem, RDC_MAXDATA);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _rdc_config
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_rdc_config(void *arg, int mode, spcs_s_info_t kstatus, int *rvp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct netbuf fsvaddr, tsvaddr;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct knetconfig *knconf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte char *p = NULL, *pf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte struct rdc_config *uap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STRUCT_DECL(knetconfig, knconf_tmp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STRUCT_DECL(rdc_config, uparms);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int enable, disable;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int cmd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STRUCT_HANDLE(rdc_set, rs);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STRUCT_HANDLE(rdc_addr, pa);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STRUCT_HANDLE(rdc_addr, sa);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STRUCT_INIT(uparms, mode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(STRUCT_BUF(uparms), STRUCT_SIZE(uparms));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&fsvaddr, sizeof (fsvaddr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&tsvaddr, sizeof (tsvaddr));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte knconf = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_copyin(arg, STRUCT_BUF(uparms), STRUCT_SIZE(uparms), mode)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EFAULT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STRUCT_SET_HANDLE(rs, mode, STRUCT_FGETP(uparms, rdc_set));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STRUCT_SET_HANDLE(pa, mode, STRUCT_FADDR(rs, primary));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STRUCT_SET_HANDLE(sa, mode, STRUCT_FADDR(rs, secondary));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmd = STRUCT_FGET(uparms, command);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cmd == RDC_CMD_ENABLE || cmd == RDC_CMD_RESUME) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fsvaddr.len = STRUCT_FGET(pa, addr.len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fsvaddr.maxlen = STRUCT_FGET(pa, addr.maxlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fsvaddr.buf = kmem_zalloc(fsvaddr.len, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_copyin(STRUCT_FGETP(pa, addr.buf),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana fsvaddr.buf, fsvaddr.len, mode)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(fsvaddr.buf, fsvaddr.len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!copyin failed primary.addr 2");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EFAULT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tsvaddr.len = STRUCT_FGET(sa, addr.len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tsvaddr.maxlen = STRUCT_FGET(sa, addr.maxlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tsvaddr.buf = kmem_zalloc(tsvaddr.len, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_copyin(STRUCT_FGETP(sa, addr.buf),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana tsvaddr.buf, tsvaddr.len, mode)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!copyin failed secondary addr");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(fsvaddr.buf, fsvaddr.len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(tsvaddr.buf, tsvaddr.len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EFAULT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fsvaddr.len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fsvaddr.maxlen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fsvaddr.buf = kmem_zalloc(fsvaddr.len, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tsvaddr.len = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tsvaddr.maxlen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte tsvaddr.buf = kmem_zalloc(tsvaddr.len, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (STRUCT_FGETP(uparms, rdc_set->netconfig) != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STRUCT_INIT(knconf_tmp, mode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte knconf = kmem_zalloc(sizeof (*knconf), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_copyin(STRUCT_FGETP(uparms, rdc_set->netconfig),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte STRUCT_BUF(knconf_tmp), STRUCT_SIZE(knconf_tmp), mode)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!copyin failed netconfig");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(fsvaddr.buf, fsvaddr.len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(tsvaddr.buf, tsvaddr.len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(knconf, sizeof (*knconf));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EFAULT);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte knconf->knc_semantics = STRUCT_FGET(knconf_tmp, knc_semantics);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte knconf->knc_protofmly = STRUCT_FGETP(knconf_tmp, knc_protofmly);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte knconf->knc_proto = STRUCT_FGETP(knconf_tmp, knc_proto);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifndef _SunOS_5_6
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((mode & DATAMODEL_LP64) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte knconf->knc_rdev =
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte expldev(STRUCT_FGET(knconf_tmp, knc_rdev));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte knconf->knc_rdev = STRUCT_FGET(knconf_tmp, knc_rdev);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifndef _SunOS_5_6
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pf = kmem_alloc(KNC_STRSIZE, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = kmem_alloc(KNC_STRSIZE, KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = ddi_copyin(knconf->knc_protofmly, pf, KNC_STRSIZE, mode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!copyin failed parms protofmly");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = ddi_copyin(knconf->knc_proto, p, KNC_STRSIZE, mode);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!copyin failed parms proto");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = EFAULT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto out;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte knconf->knc_protofmly = pf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte knconf->knc_proto = p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } /* !NULL netconfig */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uap = kmem_alloc(sizeof (*uap), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* copy relevant parts of rdc_config to uap field by field */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(uap->rdc_set[0].primary.intf, STRUCT_FGETP(pa, intf),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana MAX_RDC_HOST_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(uap->rdc_set[0].primary.file, STRUCT_FGETP(pa, file),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(uap->rdc_set[0].primary.bitmap, STRUCT_FGETP(pa, bitmap),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uap->rdc_set[0].netconfig = knconf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uap->rdc_set[0].flags = STRUCT_FGET(uparms, rdc_set->flags);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uap->rdc_set[0].index = STRUCT_FGET(uparms, rdc_set->index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uap->rdc_set[0].setid = STRUCT_FGET(uparms, rdc_set->setid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uap->rdc_set[0].sync_pos = STRUCT_FGET(uparms, rdc_set->sync_pos);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uap->rdc_set[0].volume_size = STRUCT_FGET(uparms, rdc_set->volume_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uap->rdc_set[0].bits_set = STRUCT_FGET(uparms, rdc_set->bits_set);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uap->rdc_set[0].autosync = STRUCT_FGET(uparms, rdc_set->autosync);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uap->rdc_set[0].maxqfbas = STRUCT_FGET(uparms, rdc_set->maxqfbas);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uap->rdc_set[0].maxqitems = STRUCT_FGET(uparms, rdc_set->maxqitems);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uap->rdc_set[0].asyncthr = STRUCT_FGET(uparms, rdc_set->asyncthr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uap->rdc_set[0].syshostid = STRUCT_FGET(uparms, rdc_set->syshostid);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uap->rdc_set[0].primary.addr = fsvaddr; /* struct copy */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uap->rdc_set[0].secondary.addr = tsvaddr; /* struct copy */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(uap->rdc_set[0].secondary.intf, STRUCT_FGETP(sa, intf),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana MAX_RDC_HOST_SIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(uap->rdc_set[0].secondary.file, STRUCT_FGETP(sa, file),
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(uap->rdc_set[0].secondary.bitmap,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana STRUCT_FGETP(sa, bitmap), NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(uap->rdc_set[0].direct_file,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana STRUCT_FGETP(rs, direct_file), NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(uap->rdc_set[0].group_name, STRUCT_FGETP(rs, group_name),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) strncpy(uap->rdc_set[0].disk_queue, STRUCT_FGETP(rs, disk_queue),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_MAXPATH);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uap->command = STRUCT_FGET(uparms, command);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uap->options = STRUCT_FGET(uparms, options);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte enable = (uap->command == RDC_CMD_ENABLE ||
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana uap->command == RDC_CMD_RESUME);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte disable = (uap->command == RDC_CMD_DISABLE ||
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana uap->command == RDC_CMD_SUSPEND);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Initialise the threadset if it has not already been done.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This has to be done now, not in rdcattach(), because
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdcattach() can be called before nskernd is running (eg.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * boot -r) in which case the nst_init() would fail and hence
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * the attach would fail.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Threadset creation is locked by the rdc_conf_lock,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * destruction is inherently single threaded as it is done in
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _rdc_unload() which must be the last thing performed by
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdcdetach().
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (enable && _rdc_ioset == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (_rdc_ioset == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_thread_configure();
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc || _rdc_ioset == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte spcs_s_add(kstatus, RDC_ENOTHREADS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = RDC_ENOTHREADS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto outuap;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte switch (uap->command) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RDC_CMD_ENABLE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_enable(uap, kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RDC_CMD_DISABLE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_disable(uap, kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RDC_CMD_COPY:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_sync(uap, kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RDC_CMD_LOG:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_log(uap, kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RDC_CMD_RECONFIG:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_reconfig(uap, kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RDC_CMD_RESUME:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_resume(uap, kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RDC_CMD_SUSPEND:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_suspend(uap, kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RDC_CMD_TUNABLE:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_tunable(uap, kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RDC_CMD_WAIT:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_wait(uap, kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RDC_CMD_HEALTH:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_health(uap, kstatus, rvp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RDC_CMD_STATUS:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_status(arg, mode, uap, kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RDC_CMD_RESET:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_reset(uap, kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RDC_CMD_ADDQ:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_add_diskq(uap, kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RDC_CMD_REMQ:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc = rdc_rem_diskq(uap, kstatus)) != 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* FALLTHRU */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RDC_CMD_KILLQ:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_kill_diskq(uap, kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte case RDC_CMD_INITQ:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = rdc_init_diskq(uap, kstatus);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte default:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = EINVAL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Tune the threadset size after a successful rdc_set addition
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or removal.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((enable || disable) && rc == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_thread_tune(enable ? 2 : -2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_conf_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteoutuap:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(uap, sizeof (*uap));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteout:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(fsvaddr.buf, fsvaddr.len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(tsvaddr.buf, tsvaddr.len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pf, KNC_STRSIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (p)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(p, KNC_STRSIZE);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (knconf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(knconf, sizeof (*knconf));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * krdc->group->lock held on entry to halt_sync()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortehalt_sync(rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc = &rdc_u_info[krdc->index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&krdc->group->lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(IS_ENABLED(urdc));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If a sync is in progress, halt it
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rdc_get_vflags(urdc) & RDC_PRIMARY) &&
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (krdc->aux_state & RDC_AUXSYNCIP)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->disk_status = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (krdc->disk_status == 1) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cv_wait_sig(&krdc->haltcv, &krdc->group->lock) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * return size in blocks
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteuint64_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortemirror_getsize(int index)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc, rs;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = _rdc_rsrv_devs(krdc, RDC_RAW, RDC_INTERNAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rs = nsc_partsize(RDC_U_FD(krdc), &size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc->volume_size = size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _rdc_rlse_devs(krdc, RDC_RAW);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rs == 0 ? urdc->volume_size : 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Create a new dataset for this transfer, and add it to the list
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * of datasets via the net_dataset pointer in the krdc.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_net_dataset_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_net_add_set(int index)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_u_info_t *urdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_dataset_t *dset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= rdc_max_sets) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_net_add_set: bad index %d", index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte urdc = &rdc_u_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset = kmem_alloc(sizeof (*dset), KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset == NULL) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_net_add_set: kmem_alloc failed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE(sizeof (*dset));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->inuse = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->nitems = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->delpend = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->head = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->tail = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&krdc->dc_sleep);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!IS_ENABLED(urdc)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* raced with a disable command */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(dset, sizeof (*dset));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE(-sizeof (*dset));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&krdc->dc_sleep);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Shared the id generator, (and the locks).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&rdc_net_hnd_id_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (++rdc_net_hnd_id == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_hnd_id = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->id = rdc_net_hnd_id;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&rdc_net_hnd_id_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (krdc->net_dataset != NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_dataset_t *dset2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (dset2 = krdc->net_dataset; dset2; dset2 = dset2->next) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset2->id == dset->id) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_PANIC,
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana "rdc_net_add_set duplicate id %p:%d %p:%d",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)dset, dset->id,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)dset2, dset2->id);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->next = krdc->net_dataset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc->net_dataset = dset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&krdc->dc_sleep);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fetch the previously added dataset.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_net_dataset_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_net_get_set(int index, int id)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_dataset_t *dset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= rdc_max_sets) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_net_get_set: bad index %d", index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&krdc->dc_sleep);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset = krdc->net_dataset;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (dset && (dset->id != id))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset = dset->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->inuse++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&krdc->dc_sleep);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Decrement the inuse counter. Data may be freed.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_net_put_set(int index, rdc_net_dataset_t *dset)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= rdc_max_sets) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_net_put_set: bad index %d", index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&krdc->dc_sleep);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->inuse--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(dset->inuse >= 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((dset->inuse == 0) && (dset->delpend)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_free_set(krdc, dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&krdc->dc_sleep);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Mark that we are finished with this set. Decrement inuse
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * counter, mark as needing deletion, and
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * remove from linked list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_net_del_set(int index, rdc_net_dataset_t *dset)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_k_info_t *krdc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= rdc_max_sets) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_net_del_set: bad index %d", index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte krdc = &rdc_k_info[index];
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&krdc->dc_sleep);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->inuse--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(dset->inuse >= 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->delpend = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (dset->inuse == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_free_set(krdc, dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&krdc->dc_sleep);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * free all the memory associated with this set, and remove from
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * list.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Enters and exits with dc_sleep lock held.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_net_free_set(rdc_k_info_t *krdc, rdc_net_dataset_t *dset)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_dataset_t **dsetp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int found = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&krdc->dc_sleep));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (dsetp = &krdc->net_dataset; *dsetp; dsetp = &((*dsetp)->next)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*dsetp == dset) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *dsetp = dset->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte found = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (found == 0) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_WARN, "!rdc_net_free_set: Unable to find "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "dataset 0x%p in krdc list", (void *)dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * unlinked from list. Free all the data
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_ditemsfree(dset);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * free my core.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(dset, sizeof (*dset));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE(-sizeof (*dset));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Free all the dataitems and the data it points to.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_ditemsfree(rdc_net_dataset_t *dset)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_dataitem_t *ditem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_net_dataitem_t *nitem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem = dset->head;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (ditem) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nitem = ditem->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ditem->dptr, ditem->mlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE(-ditem->mlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte dset->nitems--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(ditem, sizeof (*ditem));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte RDC_DSMEMUSE(-sizeof (*ditem));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ditem = nitem;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(dset->nitems == 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * allocate and initialize a rdc_aio_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_aio_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_aio_tbuf_get(void *n, void *h, int pos, int len, int flag, int index, int s)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_aio_t *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = kmem_zalloc(sizeof (rdc_aio_t), KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (p == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DEBUG
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!_rdcaiotbufget: kmem_alloc failed bp aio");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p->next = n; /* overload */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p->handle = h;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p->pos = pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p->qpos = -1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p->len = len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p->flag = flag;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p->index = index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p->iostatus = s; /* overload */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* set up seq later, in case thr create fails */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_aio_buf_get
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * get an aio_buf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteaio_buf_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_aio_buf_get(rdc_buf_t *h, int index)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio_buf_t *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (index >= rdc_max_sets) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc: rdc_aio_buf_get bad index %x", index);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&h->aio_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = h->rdc_anon;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (p && (p->kindex != index))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = p->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&h->aio_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_aio_buf_del
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * delete a aio_buf
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_aio_buf_del(rdc_buf_t *h, rdc_k_info_t *krdc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio_buf_t *p, **pp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&h->aio_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (pp = &h->rdc_anon; *pp; pp = &((*pp)->next)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((*pp)->kindex == krdc->index) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = *pp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte break;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (p) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *pp = p->next;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(p, sizeof (*p));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&h->aio_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * rdc_aio_buf_add
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Add a aio_buf.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteaio_buf_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_aio_buf_add(int index, rdc_buf_t *h)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte aio_buf_t *p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p = kmem_zalloc(sizeof (*p), KM_NOSLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (p == NULL) {
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_aio_buf_add: kmem_alloc failed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p->rdc_abufp = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p->kindex = index;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&h->aio_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte p->next = h->rdc_anon;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte h->rdc_anon = p;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&h->aio_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (p);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * kmemalloc a new group structure and setup the common
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic rdc_group_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_newgroup()
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_group_t *group;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group = kmem_zalloc(sizeof (rdc_group_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->diskq.lastio = kmem_zalloc(sizeof (rdc_aio_t), KM_SLEEP);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->count = 1;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->seq = RDC_NEWSEQ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->seqack = RDC_NEWSEQ;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&group->lock, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&group->ra_queue.net_qlock, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&group->diskqmutex, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&group->diskq.disk_qlock, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&group->diskq.head_lock, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_init(&group->addthrnumlk, NULL, MUTEX_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_init(&group->unregistercv, NULL, CV_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_init(&group->asyncqcv, NULL, CV_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_init(&group->diskq.busycv, NULL, CV_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_init(&group->diskq.qfullcv, NULL, CV_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_init(&group->ra_queue.qfcv, NULL, CV_DRIVER, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->ra_queue.qfill_sleeping = RDC_QFILL_DEAD;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->diskq.busycnt = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(group->synccount == 0); /* group was kmem_zalloc'ed */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * add default number of threads to the flusher thread set, plus
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * one extra thread for the disk queue flusher
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nst_add_thread(_rdc_flset, 3) != 3)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_newgroup: nst_add_thread failed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forterdc_delgroup(rdc_group_t *group)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(group->asyncstall == 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(group->rdc_thrnum == 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(group->count == 0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(MUTEX_HELD(&rdc_many_lock));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rdc_sleepqdiscard(group);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* try to remove flusher threads that this group added to _rdc_flset */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (nst_del_thread(_rdc_flset, group->rdc_addthrnum + 3) !=
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte group->rdc_addthrnum + 3)
3270659f55e0928d6edec3d26217cc29398a8149Srikanth, Ramana cmn_err(CE_NOTE, "!rdc_delgroup: nst_del_thread failed");
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&group->lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&group->ra_queue.net_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&group->diskqmutex);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&group->diskq.disk_qlock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&group->diskq.head_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_destroy(&group->addthrnumlk);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_destroy(&group->unregistercv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_destroy(&group->asyncqcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_destroy(&group->diskq.busycv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_destroy(&group->diskq.qfullcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cv_destroy(&group->ra_queue.qfcv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(group->diskq.lastio, sizeof (rdc_aio_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(group, sizeof (rdc_group_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}