/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* LDoms virtual disk client (vdc) device driver
*
* This driver runs on a guest logical domain and communicates with the virtual
* disk server (vds) driver running on the service domain which is exporting
* virtualized "disks" to the guest logical domain.
*
* The driver can be divided into four sections:
*
* 1) generic device driver housekeeping
* _init, _fini, attach, detach, ops structures, etc.
*
* 2) communication channel setup
* Setup the communications link over the LDC channel that vdc uses to
* talk to the vDisk server. Initialise the descriptor ring which
* allows the LDC clients to transfer data via memory mappings.
*
* 3) Support exported to upper layers (filesystems, etc)
* The upper layers call into vdc via strategy(9E) and DKIO(7I)
* ioctl calls. vdc will copy the data to be written to the descriptor
* ring or maps the buffer to store the data read by the vDisk
* server into the descriptor ring. It then sends a message to the
* vDisk server requesting it to complete the operation.
*
* 4) Handling responses from vDisk server.
* The vDisk server will ACK some or all of the messages vdc sends to it
* (this is configured during the handshake). Upon receipt of an ACK
* vdc will check the descriptor ring and signal to the upper layer
* code waiting on the IO.
*/
#include <sys/efi_partition.h>
#include <sys/mach_descrip.h>
#include <sys/archsystm.h>
#include <sys/sysmacros.h>
#include <sys/vio_common.h>
#include <sys/vio_mailbox.h>
#include <sys/vio_util.h>
#include <sys/vdsk_common.h>
#include <sys/vdsk_mailbox.h>
/*
* function prototypes
*/
/* standard driver functions */
/* setup */
struct extvtoc *);
/* handshake with vds */
/* processing incoming messages from vDisk server */
/* dkio */
int *rvalp);
static void vdc_validate_task(void *arg);
static void vdc_eio_thread(void *arg);
/*
* Module variables
*/
/*
* Number of handshake retries with the current server before switching to
* a different server. These retries are done so that we stick with the same
* server if vdc receives a LDC reset event during the initiation of the
* handshake. This can happen if vdc reset the LDC channel and then immediately
* retry a connexion before it has received the LDC reset event.
*
* If there is only one server then we "switch" to the same server. We also
* switch if the handshake has reached the attribute negotiate step whatever
* the number of handshake retries might be.
*/
/*
* If the handshake done during the attach fails then the two following
* variables will also be used to control the number of retries for the
* next handshakes. In that case, when a handshake is done after the
* attach (i.e. the vdc lifecycle is VDC_ONLINE_PENDING) then the handshake
* will be retried until we have done an attribution negotiation with each
* server, with a specified minimum total number of negotations (the value
* of the vdc_hattr_min_initial or vdc_hattr_min variable).
*
* attribute negotiations can not be done, and to limit the amount of time
* the service is up but the backend does not exist. In that case, vds will
* after the following amount of time:
*
* 50 seconds x max(number of servers, vdc->hattr_min)
*
* After that the handshake done during the attach has failed then the next
* handshake will use vdc_attr_min_initial. This handshake will correspond to
* the very first I/O to the device. If this handshake also fails then
* vdc_hattr_min will be used for subsequent handshakes. We typically allow
* more retries for the first handshake (VDC_HATTR_MIN_INITIAL = 3) to give more
* time for the backend to become available (50s x VDC_HATTR_MIN_INITIAL = 150s)
* in case this is a critical vdisk (e.g. vdisk access during boot). Then we use
* a smaller value (VDC_HATTR_MIN = 1) to avoid waiting too long for each I/O.
*/
/*
* Tunable variables to control how long vdc waits before timing out on
* various operations
*/
/* values for dumping - need to run in a tighter loop */
/* Count of the number of vdc instances attached */
/* Tunable to log all SCSI errors */
/* Soft state pointer */
static void *vdc_state;
/*
*
* vdc_msglevel - controls level of messages
* vdc_matchinst - 64-bit variable where each bit corresponds
* to the vdc instance the vdc_msglevel applies.
*/
/*
* Supported vDisk protocol version pairs.
*
* The first array entry is the latest and preferred version.
*/
vdc_open, /* cb_open */
vdc_close, /* cb_close */
vdc_strategy, /* cb_strategy */
vdc_print, /* cb_print */
vdc_dump, /* cb_dump */
vdc_read, /* cb_read */
vdc_write, /* cb_write */
vdc_ioctl, /* cb_ioctl */
nodev, /* cb_devmap */
nodev, /* cb_mmap */
nodev, /* cb_segmap */
nochpoll, /* cb_chpoll */
vdc_prop_op, /* cb_prop_op */
NULL, /* cb_str */
CB_REV, /* cb_rev */
vdc_aread, /* cb_aread */
vdc_awrite /* cb_awrite */
};
DEVO_REV, /* devo_rev */
0, /* devo_refcnt */
vdc_getinfo, /* devo_getinfo */
nulldev, /* devo_identify */
nulldev, /* devo_probe */
vdc_attach, /* devo_attach */
vdc_detach, /* devo_detach */
nodev, /* devo_reset */
&vdc_cb_ops, /* devo_cb_ops */
NULL, /* devo_bus_ops */
nulldev, /* devo_power */
ddi_quiesce_not_needed, /* devo_quiesce */
};
"virtual disk client",
&vdc_ops,
};
&modldrv,
};
/* -------------------------------------------------------------------------- */
/*
* Device Driver housekeeping and setup
*/
int
_init(void)
{
int status;
return (status);
return (status);
}
int
{
}
int
_fini(void)
{
int status;
return (status);
return (0);
}
static int
{
switch (cmd) {
case DDI_INFO_DEVT2DEVINFO:
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
case DDI_INFO_DEVT2INSTANCE:
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
}
static int
{
int instance;
int rv;
switch (cmd) {
case DDI_DETACH:
/* the real work happens below */
break;
case DDI_SUSPEND:
/* nothing to do for this non-device */
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
return (DDI_FAILURE);
}
if (vdc_is_opened(vdc)) {
return (DDI_FAILURE);
}
if (vdc->dkio_flush_pending) {
"[%d] Cannot detach: %d outstanding DKIO flushes\n",
return (DDI_FAILURE);
}
if (vdc->validate_pending) {
"[%d] Cannot detach: %d outstanding validate request\n",
return (DDI_FAILURE);
}
/* If we took ownership, release ownership */
if (rv == 0) {
}
}
/* mark instance as detaching */
/*
* Try and disable callbacks to prevent another handshake. We have to
* disable callbacks for all servers.
*/
}
}
/* wake up any thread waiting for connection to come online */
"[%d] write reset - move to resetting state...\n",
instance);
}
/* now wait until state transitions to VDC_STATE_DETACH */
}
if (vdc->eio_thread) {
vdc->failfast_interval = 0;
} else {
eio_tid = 0;
}
} else {
ownership_tid = 0;
}
if (eio_tid != 0)
if (ownership_tid != 0)
}
}
}
}
return (DDI_SUCCESS);
}
static int
{
int instance;
int status;
instance);
return (DDI_FAILURE);
}
return (DDI_FAILURE);
}
/*
* We assign the value to initialized in this case to zero out the
* variable and then set bits in it to indicate what has been done
*/
vdc->session_id = 0;
vdc->vio_bshift = 0;
/*
* We assume, for now, that the vDisk server will export 'read'
* operations to us at a minimum (this is needed because of checks
* in vdc for supported operations early in the handshake process).
* The vDisk server will return ENOTSUP if this is not the case.
* The value will be overwritten during the attribute exchange with
* the bitmask of operations exported by server.
*/
vdc->threads_pending = 0;
/* init blocking msg read functionality */
/* get device and port MD node for this disk instance */
instance);
return (DDI_FAILURE);
}
return (DDI_FAILURE);
}
(void) md_fini_handle(mdp);
/* Create the kstats for saving the I/O statistics used by iostat(1M) */
/* Initialize remaining structures before starting the msg thread */
/* initialize the thread responsible for managing state with server */
instance);
return (DDI_FAILURE);
}
/*
* If there are multiple servers then start the eio thread.
*/
"I/O thread", instance);
return (DDI_FAILURE);
}
}
/*
* Check the disk label. This will send requests and do the handshake.
* We don't really care about the disk label now. What we really need is
* the handshake do be done so that we know the type of the disk (slice
* or full disk) and the appropriate device nodes can be created.
*/
(void) vdc_validate_geometry(vdc);
/*
* Now that we have the device info we can create the device nodes
*/
if (status) {
instance);
goto return_status;
}
/*
* Fill in the fields of the error statistics kstat that were not
* available when creating the kstat
*/
return (status);
}
static int
{
int status;
switch (cmd) {
case DDI_ATTACH:
return (status);
case DDI_RESUME:
/* nothing to do for this non-device */
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
}
static int
{
int status = 0;
&srvr->ldc_handle);
if (status != 0) {
return (status);
}
}
if (status != 0) {
goto init_exit;
}
if (status != 0) {
goto init_exit;
}
}
/*
* At this stage we have initialised LDC, we will now try and open
* the connection.
*/
if (status != 0) {
goto init_exit;
}
}
if (status) {
}
return (status);
}
static int
{
int status = 0;
return (status);
}
static int
{
int status;
return (status);
}
static void
{
return;
}
} else {
}
}
static void
{
return;
}
"%serr", VDC_DRIVER_NAME);
" will not be gathered", instance);
return;
}
}
static void
{
return;
}
static int
{
DDI_NT_BLOCK, 0) != DDI_SUCCESS) {
return (EIO);
}
/* if any device node is created we set this flag */
DDI_NT_BLOCK, 0) != DDI_SUCCESS) {
return (EIO);
}
return (0);
}
static int
{
DDI_NT_BLOCK, 0) != DDI_SUCCESS) {
return (EIO);
}
/* if any device node is created we set this flag */
DDI_NT_BLOCK, 0) != DDI_SUCCESS) {
return (EIO);
}
return (0);
}
/*
* Function:
* vdc_create_device_nodes
*
* Description:
* This function creates the block and character device nodes under
* /devices. It is called as part of the attach(9E) of the instance
* during the handshake with vds after vds has sent the attributes
* to vdc.
*
* If the device is of type VD_DISK_TYPE_SLICE then the minor node
* of 2 is used in keeping with the Solaris convention that slice 2
* refers to a whole disk. Slices start at 'a'
*
* Parameters:
* vdc - soft state pointer
*
* Return Values
* 0 - Success
* EIO - Failed to create node
*/
static int
{
int i;
switch (vdc->vdisk_type) {
case VD_DISK_TYPE_DISK:
case VD_DISK_TYPE_UNK:
break;
case VD_DISK_TYPE_SLICE:
num_slices = 1;
break;
default:
ASSERT(0);
}
/*
* Minor nodes are different for EFI disks: EFI disks do not have
* a minor node 'g' for the minor number corresponding to slice
* VD_EFI_WD_SLICE (slice 7) instead they have a minor node 'wd'
* representing the whole disk.
*/
for (i = 0; i < num_slices; i++) {
if (i == VD_EFI_WD_SLICE) {
else
if (status != 0)
return (status);
continue;
}
return (EIO);
}
/* if any device node is created we set this flag */
return (EIO);
}
}
return (0);
}
/*
* Driver prop_op(9e) entry point function. Return the number of blocks for
* the partition in question or forward the request to the property facilities.
*/
static int
{
}
(void) vdc_validate_geometry(vdc);
}
}
/*
* Function:
* vdc_is_opened
*
* Description:
* This function checks if any slice of a given virtual disk is
* currently opened.
*
* Parameters:
* vdc - soft state pointer
*
* Return Values
* B_TRUE - at least one slice is opened.
* B_FALSE - no slice is opened.
*/
static boolean_t
{
int i;
/* check if there's any layered open */
for (i = 0; i < V_NUMPAR; i++) {
return (B_TRUE);
}
/* check if there is any other kind of open */
for (i = 0; i < OTYPCNT; i++) {
return (B_TRUE);
}
return (B_FALSE);
}
static int
{
int i;
/*
* If we have a single-slice disk which was unavailable during the
* attach then a device was created for each 8 slices. Now that
* the type is known, we prevent opening any slice other than 0
* even if a device still exists.
*/
return (EIO);
/* check if slice is already exclusively opened */
return (EBUSY);
/* if open exclusive, check if slice is already opened */
return (EBUSY);
for (i = 0; i < OTYPCNT; i++) {
return (EBUSY);
}
}
/* mark slice as opened */
} else {
}
return (0);
}
static void
{
} else {
}
}
static int
{
return (EINVAL);
return (ENXIO);
}
return (EROFS);
}
if (status != 0) {
return (status);
}
/*
* If the disk type is unknown then we have to wait for the
* handshake to complete because we don't know if the slice
* device we are opening effectively exists.
*/
/* don't resubmit a validate request if there's already one */
if (vdc->validate_pending > 0) {
return (0);
}
/* call vdc_validate() asynchronously to avoid blocking */
return (ENXIO);
}
vdc->validate_pending++;
return (0);
}
}
return (status);
}
static int
{
int instance;
int slice;
return (EINVAL);
return (ENXIO);
}
/*
* Attempt to flush the W$ on a close operation. If this is
* not a supported IOCTL command or the backing device is read-only
* do not fail the close operation.
*/
return (EIO);
}
return (0);
}
static int
{
}
static int
{
return (0);
}
static int
{
return (ENXIO);
}
/* convert logical block to vio block */
return (EINVAL);
}
/*
* If we are panicking, we need the state to be "running" so that we
*/
if (rv) {
return (rv);
}
return (0);
}
/* -------------------------------------------------------------------------- */
/*
* Disk access routines
*
*/
/*
* vdc_strategy()
*
* Return Value:
* 0: As per strategy(9E), the strategy() function must return 0
* [ bioerror(9f) sets b_flags to the proper error code ]
*/
static int
{
int slice;
return (0);
}
/* I/O using an absolute disk offset */
} else {
}
/*
* In the buf structure, b_lblkno represents a logical block number
* using a block size of 512 bytes. For the VIO request, this block
* number has to be converted to be represented with the block size
* used by the VIO protocol.
*/
return (0);
}
/* submit the I/O, any error will be reported in the buf structure */
return (0);
}
/*
* Function:
* vdc_min
*
* Description:
* Routine to limit the size of a data transfer. Used in
* conjunction with physio(9F).
*
* Arguments:
* bp - pointer to the indicated buf(9S) struct.
*
*/
static void
{
}
}
static int
{
}
static int
{
}
static int
{
}
static int
{
}
/* -------------------------------------------------------------------------- */
/*
* Handshake support
*/
/*
* Function:
* vdc_init_ver_negotiation()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
{
/*
* set the Session ID to a unique value
* (the lower 32 bits of the clock tick)
*/
if (msglen != sizeof (vio_ver_msg_t))
}
return (status);
}
/*
* Function:
* vdc_ver_negotiation()
*
* Description:
*
* Arguments:
* vdcp - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
{
int status;
return (status);
/* release lock and wait for response */
if (status) {
"[%d] Failed waiting for Ver negotiation response, rv(%d)",
return (status);
}
/* check type and sub_type ... */
return (EPROTO);
}
}
/*
* Function:
* vdc_init_attr_negotiation()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
{
int status;
/* fill in tag */
/* fill in payload */
if (msglen != sizeof (vd_attr_msg_t))
}
return (status);
}
/*
* Function:
* vdc_attr_negotiation()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
{
int status;
return (status);
/* release lock and wait for response */
if (status) {
"[%d] Failed waiting for Attr negotiation response, rv(%d)",
return (status);
}
/* check type and sub_type ... */
return (EPROTO);
}
}
/*
* Function:
* vdc_init_dring_negotiate()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
{
int retry;
break;
}
if (status != 0) {
return (status);
}
/* fill in tag */
/* fill in payload */
pkt.dring_ident = 0;
if (status != 0) {
}
return (status);
}
/*
* Function:
* vdc_dring_negotiation()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
{
int status;
return (status);
/* release lock and wait for response */
if (status) {
"[%d] Failed waiting for Dring negotiation response,"
return (status);
}
/* check type and sub_type ... */
return (EPROTO);
}
return (vdc_handle_dring_reg_msg(vdcp,
(vio_dring_reg_msg_t *)&vio_msg));
}
/*
* Function:
* vdc_send_rdx()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
{
int status;
/*
* Send an RDX message to vds to indicate we are ready
* to send data
*/
if (status != 0) {
}
return (status);
}
/*
* Function:
* vdc_handle_rdx()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
* msgp - received msg
*
* Return Code:
* 0 - Success
*/
static int
{
return (0);
}
/*
* Function:
* vdc_rdx_exchange()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
{
int status;
return (status);
/* release lock and wait for response */
if (status) {
return (status);
}
/* check type and sub_type ... */
return (EPROTO);
}
}
/* -------------------------------------------------------------------------- */
/*
* LDC helper routines
*/
static int
{
int status;
/*
* Until we get a blocking ldc read we have to retry until the entire
* LDC message has arrived before ldc_read() will return that message.
* If ldc_read() succeed but returns a zero length message then that
* means that the LDC queue is empty and we have to wait for a
* notification from the LDC callback which will set the read_state to
* VDC_READ_PENDING. Note we also bail out if the channel is reset or
* goes away.
*/
for (;;) {
/*
* vdc->curr_server is protected by vdc->lock but to avoid
* contentions we don't take the lock here. We can do this
* safely because vdc_recv() is only called from thread
* process_msg_thread() which is also the only thread that
* can change vdc->curr_server.
*/
delay_time *= 2;
if (delay_time >= vdc_ldc_read_max_delay)
continue;
}
if (status != 0) {
break;
}
if (len != 0) {
break;
}
/* detect if the connection has been reset */
return (ECONNRESET);
}
}
}
return (status);
}
#ifdef DEBUG
void
{
Q(VIO_TYPE_ERR)
#undef Q
default: ms = "unknown"; break;
}
#undef Q
default: ss = "unknown"; break;
}
Q(VIO_VER_INFO)
Q(VIO_RDX)
Q(VIO_PKT_DATA)
#undef Q
default: ses = "unknown"; break;
}
}
#endif
/*
* Function:
* vdc_send()
*
* Description:
* The function encapsulates the call to write a message using LDC.
* If LDC indicates that the call failed due to the queue being full,
* we retry the ldc_write(), otherwise we return the error returned by LDC.
*
* Arguments:
* ldc_handle - LDC handle for the channel this instance of vdc uses
* pkt - address of LDC message to be sent
* msglen - the size of the message being sent. When the function
* returns, this contains the number of bytes written.
*
* Return Code:
* 0 - Success.
* EINVAL - pkt or msglen were NULL
* ECONNRESET - The connection was not up.
* EWOULDBLOCK - LDC queue is full
* xxx - other error codes returned by ldc_write
*/
static int
{
int status = 0;
#ifdef DEBUG
#endif
/*
* Wait indefinitely to send if channel
* is busy, but bail out if we succeed or
* if the channel closes or is reset.
*/
do {
if (status == EWOULDBLOCK) {
/* geometric backoff */
delay_ticks *= 2;
if (delay_ticks > vdc_hz_max_ldc_delay)
}
} while (status == EWOULDBLOCK);
/* if LDC had serious issues --- reset vdc state */
/* LDC had serious issues --- reset vdc state */
/* wake up any waiters in the reset thread */
}
return (ECONNRESET);
}
/* return the last size written */
return (status);
}
/*
* Function:
* vdc_get_md_node
*
* Description:
* Get the MD, the device node for the given disk instance. The
* caller is responsible for cleaning up the reference to the
* returned MD (mdpp) by calling md_fini_handle().
*
* Arguments:
* dip - dev info pointer for this instance of the device driver.
* mdpp - the returned MD.
* vd_nodep - the returned device node.
*
* Return Code:
* 0 - Success.
* ENOENT - Expected node or property did not exist.
* ENXIO - Unexpected error communicating with MD framework
*/
static int
{
int num_nodes;
int num_vdevs;
int listsz;
int idx;
int obp_inst;
/*
* Get the OBP instance number for comparison with the MD instance
*
* The "cfg-handle" property of a vdc node in an MD contains the MD's
* notion of "instance", or unique identifier, for that node; OBP
* stores the value of the "cfg-handle" MD property as the value of
* the "reg" property on the node in the device tree it builds from
* the MD and passes to Solaris. Thus, we look up the devinfo node's
* "reg" property value to uniquely identify this device instance.
* If the "reg" property cannot be found, the device tree state is
* presumably so broken that there is no point in continuing.
*/
return (ENOENT);
}
OBP_REG, -1);
/*
* We now walk the MD nodes to find the node for this vdisk.
*/
return (ENXIO);
}
/* allocate memory for nodes */
/*
* Search for all the virtual devices, we will then check to see which
* ones are disk nodes.
*/
if (num_vdevs <= 0) {
goto done;
}
continue;
}
found_inst = B_TRUE;
break;
}
}
}
if (!found_inst) {
goto done;
}
done:
return (status);
}
/*
* Function:
* vdc_init_ports
*
* Description:
* Initialize all the ports for this vdisk instance.
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
* mdp - md pointer
* vd_nodep - device md node.
*
* Return Code:
* 0 - Success.
* ENOENT - Expected node or property did not exist.
*/
static int
{
int status = 0;
int idx;
int num_nodes;
int num_vports;
int num_chans;
int listsz;
/*
* We now walk the MD nodes to find the port nodes for this vdisk.
*/
/* allocate memory for nodes */
if (num_vports == 0) {
DMSGX(0, "Found no '%s' node for '%s' port\n",
goto done;
}
vdc->num_servers = 0;
/* initialize this port */
/* get port id */
continue;
}
/* set the connection timeout */
}
/* get the ldc id */
/* expecting at least one channel */
if (num_chans <= 0) {
continue;
} else if (num_chans != 1) {
DMSGX(0, "Expected 1 '%s' node for '%s' port, "
}
/*
* We use the first channel found (index 0), irrespective of how
* many are there in total.
*/
continue;
}
/*
* now initialise LDC channel which will be used to
* communicate with this server
*/
continue;
}
/* add server to list */
if (prev_srvr)
else
/* inc numbers of servers */
vdc->num_servers++;
}
/* pick first server as current server */
status = 0;
} else {
}
done:
return (status);
}
/*
* Function:
* vdc_do_ldc_up
*
* Description:
* Bring the channel for the current server up.
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success.
* EINVAL - Driver is detaching / LDC error
* ECONNREFUSED - Other end is not listening
*/
static int
{
int status;
return (EINVAL);
switch (status) {
case ECONNREFUSED: /* listener not ready at other end */
status = 0;
break;
default:
break;
}
}
vdc->seq_num_reply = 0;
}
}
return (status);
}
/*
* Function:
* vdc_terminate_ldc()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
* srvr - vdc per-server info structure
*
* Return Code:
* None
*/
static void
{
}
}
}
}
/*
* Function:
* vdc_fini_ports()
*
* Description:
* Finalize all ports by closing the channel associated with each
* port and also freeing the server structure.
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* None
*/
static void
{
while (srvr) {
/* next server */
/* free server */
}
vdc->num_servers = 0;
}
/* -------------------------------------------------------------------------- */
/*
* Descriptor Ring helper routines
*/
/*
* Function:
* vdc_init_descriptor_ring()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
{
int status = 0;
int i;
/* ensure we have enough room to store max sized block */
/*
* Calculate the maximum block size we can transmit using one
* Descriptor Ring entry from the attributes returned by the
* vDisk server. This is subject to a minimum of 'maxphys'
* as we do not have the capability to split requests over
* multiple DRing entries.
*/
} else {
}
(sizeof (ldc_mem_cookie_t) *
return (status);
}
}
vdc->dring_cookie =
&vdc->dring_cookie[0],
if (status != 0) {
"(%lx) to channel (%lx) status=%d\n",
return (status);
}
}
if (status != 0) {
"[%d] Failed to get info for descriptor ring (%lx)\n",
return (status);
}
/* Allocate the local copy of this dring */
vdc->local_dring =
KM_SLEEP);
}
/*
* Mark all DRing entries as free and initialize the private
* descriptor's memory handles. If any entry is initialized,
* we need to free it later so we set the bit in 'initialized'
* at the start.
*/
if (status != 0) {
return (status);
}
}
/* Initialize the starting index */
return (status);
}
/*
* Function:
* vdc_destroy_descriptor_ring()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* None
*/
static void
{
int i; /* loop */
continue;
"ldc_mem_info returned an error: %d\n",
status);
/*
* This must mean that the mem handle
* is not valid. Clear it out so that
* no one tries to use it.
*/
continue;
}
(void) ldc_mem_unbind_handle(mhdl);
}
(void) ldc_mem_free_handle(mhdl);
}
}
}
if (status == 0) {
} else {
}
}
if (status == 0) {
} else {
}
}
}
/*
* Function:
* vdc_map_to_shared_dring()
*
* Description:
* Copy contents of the local descriptor to the shared
* memory descriptor.
*
* Arguments:
* vdcp - soft state pointer for this instance of the device driver.
* idx - descriptor ring index
*
* Return Code:
* None
*/
static int
{
int rv;
/* for now leave in the old pop_mem_hdl stuff */
if (rv) {
return (rv);
}
}
/*
* fill in the data details into the DRing
*/
return (0);
}
/*
* Function:
* vdc_send_request
*
* Description:
* This routine writes the data to be transmitted to vds into the
* descriptor, notifies vds that the ring has been updated and
* then waits for the request to be processed.
*
* Arguments:
* vdcp - the soft state pointer
* operation - operation we want vds to perform (VD_OP_XXX)
* slice - the disk slice this request is for
* offset - relative disk offset
* bufp - buf of operation
*
* Return Codes:
* 0
* ENXIO
*/
static int
{
int rv = 0;
/*
* to indicate that the request is being put on the waitq to be
* serviced. Operations which are resubmitted are already in the waitq.
*
* We do it here (a common routine for both synchronous and strategy
* calls) for performance reasons - we are already holding vdc->lock
* so there is no extra locking overhead. We would have to explicitly
* grab the 'lock' mutex to update the stats if we were to do this
* higher up the stack in vdc_strategy() et. al.
*/
!(flags & VDC_OP_RESUBMIT)) {
}
/*
* If the request does not expect the state to be VDC_STATE_RUNNING
* then we just try to populate the descriptor ring once.
*/
if (!(flags & VDC_OP_STATE_RUNNING)) {
goto done;
}
do {
/* return error if detaching */
goto done;
}
/*
* If we are panicking and the disk is not ready then
* we can't send any request because we can't complete
* the handshake now.
*/
if (ddi_in_panic()) {
goto done;
}
/*
* If the state is faulted, notify that a new I/O is
* being submitted to force the system to check if any
* server has recovered.
*/
}
/* if service is still faulted then fail the request */
goto done;
}
}
done:
/*
* to indicate that this request has been placed on the queue for
* processing (i.e sent to the vDisk server) - iostat(1M) will
* report the time waiting for the vDisk server under the %b column
*
* In the case of an error we take it off the wait queue only if
* the I/O was not resubmited.
*/
if (rv == 0) {
} else {
if (!(flags & VDC_OP_RESUBMIT)) {
}
}
}
return (rv);
}
/*
* Function:
* vdc_populate_descriptor
*
* Description:
* This routine writes the data to be transmitted to vds into the
* descriptor, notifies vds that the ring has been updated and
* then waits for the request to be processed.
*
* Arguments:
* vdcp - the soft state pointer
* operation - operation we want vds to perform (VD_OP_XXX)
* slice - the disk slice this request is for
* offset - relative disk offset
* bufp - buf of operation
*
* Return Codes:
* 0
* EAGAIN
* ECONNRESET
* ENXIO
*/
static int
{
int next_idx;
int rv;
vdcp->threads_pending++;
loop:
if (flags & VDC_OP_DRING_RESERVED) {
/* use D-Ring reserved entry */
} else {
/* Get next available D-Ring entry */
goto loop;
}
vdcp->threads_pending--;
return (ECONNRESET);
}
}
if (rv) {
if (flags & VDC_OP_DRING_RESERVED) {
/*
* We can't wait if we are using reserved slot.
* Free the descriptor and return.
*/
vdcp->threads_pending--;
return (rv);
}
/* free the descriptor */
goto loop;
}
vdcp->threads_pending--;
return (ECONNRESET);
}
/*
* Send a msg with the DRing details to vds
*/
/*
* note we're still holding the lock here to
* make sure the message goes out in order !!!...
*/
switch (rv) {
case ECONNRESET:
/*
* vdc_send initiates the reset on failure.
* Since the transaction has already been put
* on the local dring, it will automatically get
* retried when the channel is reset. Given that,
* it is ok to just return success even though the
* send failed.
*/
rv = 0;
break;
case 0: /* EOK */
break;
default:
break;
}
vdcp->threads_pending--;
return (rv);
}
/*
* Function:
* vdc_do_op
*
* Description:
* Wrapper around vdc_submit_request(). Each request is associated with a
* buf structure. If a buf structure is provided (bufp != NULL) then the
* request will be submitted with that buf, and the caller can wait for
* completion of the request with biowait(). If a buf structure is not
* provided (bufp == NULL) then a buf structure is created and the function
* waits for the completion of the request.
*
* If the flag VD_OP_STATE_RUNNING is set then vdc_submit_request() will
* submit the request only when the vdisk is in state VD_STATE_RUNNING.
* If the vdisk is not in that state then the vdc_submit_request() will
* wait for that state to be reached. After the request is submitted, the
* reply will be processed asynchronously by the vdc_process_msg_thread()
* thread.
*
* If the flag VD_OP_STATE_RUNNING is not set then vdc_submit_request()
* submit the request whatever the state of the vdisk is. Then vdc_do_op()
* will wait for a reply message, process the reply and complete the
* request.
*
* Arguments:
* vdc - the soft state pointer
* op - operation we want vds to perform (VD_OP_XXX)
* slice - the disk slice this request is for
* offset - relative disk offset
* bufp - buf structure associated with the request (can be NULL).
* flags - flags for the request.
*
* Return Codes:
* 0 - the request has been succesfully submitted and completed.
* != 0 - the request has failed. In that case, if a buf structure
* was provided (bufp != NULL) then the B_ERROR flag is set
* and the b_error field of the buf structure is set to EIO.
*/
static int
{
int rv;
/*
* We use buf just as a convenient way to get a notification
* that the request is completed, so we initialize buf to the
* minimum we need.
*/
}
if (rv != 0)
goto done;
/*
* If the request should be done in VDC_STATE_RUNNING state then the
* reply will be received and processed by vdc_process_msg_thread()
* and we just have to handle the panic case. Otherwise we have to
* wait for the reply message and process it.
*/
if (flags & VDC_OP_STATE_RUNNING) {
if (ddi_in_panic()) {
goto done;
}
} else {
/* wait for the response message */
if (rv == 0)
if (rv) {
/*
* statistics kstat to take it off the run queue.
* If it is a resubmit then it needs to stay in
* in the waitq, and it will be removed when the
* I/O is eventually completed or cancelled.
*/
if (flags & VDC_OP_RESUBMIT) {
} else {
}
}
goto done;
}
}
done:
} else if (rv != 0) {
}
return (rv);
}
/*
* Function:
* vdc_do_sync_op
*
* Description:
* Wrapper around vdc_do_op that serializes requests.
*
* Arguments:
* vdcp - the soft state pointer
* operation - operation we want vds to perform (VD_OP_XXX)
* slice - the disk slice this request is for
* offset - relative disk offset
* rconflict - check for reservation conflict in case of failure
*
* rconflict should be set to B_TRUE by most callers. Callers invoking the
* VD_OP_SCSICMD operation can set rconflict to B_FALSE if they check the
* result of a successful operation with vdc_scsi_status().
*
* Return Codes:
* 0
* EAGAIN
* EFAULT
* ENXIO
* EIO
*/
static int
{
int status;
/*
* Grab the lock, if blocked wait until the server
* response causes us to wake up again.
*/
vdcp->sync_op_cnt++;
if (ddi_in_panic()) {
/* don't block if we are panicking */
vdcp->sync_op_cnt--;
return (EIO);
} else {
}
}
vdcp->sync_op_cnt--;
return (ENXIO);
}
/* now block anyone other thread entering after us */
if (!rconflict)
}
vdcp->sync_op_cnt--;
/* signal the next waiting thread */
return (status);
}
/*
* Function:
* vdc_drain_response()
*
* Description:
* When a guest is panicking, the completion of requests needs to be
* handled differently because interrupts are disabled and vdc
* will not get messages. We have to poll for the messages instead.
*
* Note: since we are panicking we don't implement the io:::done
* DTrace probe or update the I/O statistics kstats.
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
* buf - if buf is NULL then we drain all responses, otherwise we
* described by buf.
*
* Return Code:
* 0 - Success. If we were expecting a response to a particular
* request then this means that a response has been received.
*/
static int
{
retries = 0;
for (;;) {
&msglen);
if (rv) {
break;
}
/*
* if there are no packets wait and check again
*/
if (retries++ > vdc_dump_retries) {
break;
}
continue;
}
/*
* DRing requests.
*/
continue;
}
/*
* Record if the packet was ACK'ed or not. If the packet was not
* ACK'ed then we will just mark the request as failed; we don't
* want to reset the connection at this point.
*/
case VIO_SUBTYPE_ACK:
break;
case VIO_SUBTYPE_NACK:
break;
default:
continue;
}
continue;
}
continue;
}
rv = 0;
goto done;
}
/* if this is the last descriptor - break out of loop */
/*
* If we were expecting a response for a particular
* request then we return with an error otherwise we
* have successfully completed the drain.
*/
break;
}
}
done:
return (rv);
}
/*
* Function:
* vdc_depopulate_descriptor()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
* idx - Index of the Descriptor Ring entry being modified
*
* Return Code:
* 0 - Success
*/
static int
{
int rv = 0;
/*
* If no buffers were used to transfer information to the server when
* populating the descriptor then no memory handles need to be unbound
* and we can return now.
*/
return (status);
}
/*
* If the upper layer passed in a misaligned address we copied the
* data into an aligned buffer before sending it to LDC - we now
* copy it back to the original buffer.
*/
if (ldep->align_addr) {
}
if (rv != 0) {
/*
* The error returned by the vDisk server is more informative
* and thus has a higher priority but if it isn't set we ensure
* that this function returns an error.
*/
if (status == 0)
}
return (status);
}
/*
* Function:
* vdc_populate_mem_hdl()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
* idx - Index of the Descriptor Ring entry being modified
* addr - virtual address being mapped in
* nybtes - number of bytes in 'addr'
* operation - the vDisk operation being performed (VD_OP_xxx)
*
* Return Code:
* 0 - Success
*/
static int
{
int rv = 0;
int i;
case VIO_read_dir:
break;
case VIO_write_dir:
break;
case VIO_both_dir:
perm = LDC_MEM_RW;
break;
default:
ASSERT(0); /* catch bad programming in vdc */
}
/*
* LDC expects any addresses passed in to be 8-byte aligned. We need
* to copy the contents of any misaligned buffers to a newly allocated
* buffer and bind it instead (and copy the the contents back to the
* original buffer passed in when depopulating the descriptor)
*/
ldep->align_addr =
kmem_alloc(sizeof (caddr_t) *
"(buf=%p nb=%ld op=%d)\n",
}
if (rv != 0) {
"(mhdl=%p, buf=%p, err=%d)\n",
if (ldep->align_addr) {
}
return (EAGAIN);
}
/*
* Get the other cookies (if any).
*/
if (rv != 0) {
(void) ldc_mem_unbind_handle(mhdl);
"(mhdl=%lx cnum=%d), err=%d",
if (ldep->align_addr) {
}
return (EAGAIN);
}
}
return (rv);
}
/*
* Interrupt handlers for messages from LDC
*/
/*
* Function:
* vdc_handle_cb()
*
* Description:
*
* Arguments:
* event - Type of event (LDC_EVT_xxx) that triggered the callback
* arg - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static uint_t
{
int rv = 0;
/* If callback is not for the current server, ignore it */
return (LDC_SUCCESS);
}
/*
* Depending on the type of event that triggered this callback,
* we modify the handshake state or read the data.
*
* NOTE: not done as a switch() as event could be triggered by
* a state change and a read request. Also the ordering of the
* check for the event types is deliberate.
*/
if (event & LDC_EVT_UP) {
/* get LDC state */
if (rv != 0) {
return (LDC_SUCCESS);
}
/*
* Reset the transaction sequence numbers when
* LDC comes up. We then kick off the handshake
* negotiation with the vDisk server.
*/
vdc->seq_num_reply = 0;
}
}
if (event & LDC_EVT_READ) {
return (LDC_SUCCESS);
}
/*
* Need to wake up any readers so they will
* detect that a reset has occurred.
*/
/* wake up any threads waiting for connection to come up */
}
}
return (LDC_SUCCESS);
}
/*
* Function:
* vdc_wait_for_response()
*
* Description:
* Block waiting for a response from the server. If there is
* no data the thread block on the read_cv that is signalled
* by the callback when an EVT_READ occurs.
*
* Arguments:
* vdcp - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
{
int status;
if (status) {
return (status);
}
if (nbytes < sizeof (vio_msg_tag_t)) {
return (ENOMSG);
}
/*
* Verify the Session ID of the message
*
* Every message after the Version has been negotiated should
* have the correct session ID set.
*/
"expected 0x%lx [seq num %lx @ %d]",
return (ENOMSG);
}
return (0);
}
/*
* Function:
* vdc_resubmit_backup_dring()
*
* Description:
* Resubmit each descriptor in the backed up dring to
* vDisk server. The Dring was backed up during connection
* reset.
*
* Arguments:
* vdcp - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - Success
*/
static int
{
int processed = 0;
int count;
int b_idx;
int rv = 0;
int dring_size;
/* the pending requests have already been processed */
return (0);
}
/*
* Walk the backup copy of the local descriptor ring and
* resubmit all the outstanding transactions.
*/
/* only resubmit outstanding transactions */
if (rv) {
goto done;
}
/*
* Mark this entry as free so that we will not resubmit
* this "done" request again, if we were to use the same
* backup_dring again in future. This could happen when
* a reset happens while processing the backup_dring.
*/
processed++;
}
/* get the next element to submit */
b_idx = 0;
}
/* all done - now clear up pending dring copy */
sizeof (vdcp->local_dring_backup[0]);
done:
return (rv);
}
/*
* Function:
* vdc_cancel_backup_dring
*
* Description:
* Cancel each descriptor in the backed up dring to vDisk server.
* The Dring was backed up during connection reset.
*
* Arguments:
* vdcp - soft state pointer for this instance of the device driver.
*
* Return Code:
* None
*/
void
{
int count;
int b_idx;
int dring_size;
int cancelled = 0;
/* the pending requests have already been processed */
return;
}
/*
* Walk the backup copy of the local descriptor ring and
* cancel all the outstanding transactions.
*/
/* only cancel outstanding transactions */
cancelled++;
/*
* All requests have already been cleared from the
* local descriptor ring and the LDC channel has been
* reset so we will never get any reply for these
* requests. Now we just have to notify threads waiting
* for replies that the request has failed.
*/
}
}
/* get the next element to cancel */
b_idx = 0;
}
/* all done - now clear up pending dring copy */
sizeof (vdcp->local_dring_backup[0]);
}
/*
* Function:
* vdc_connection_timeout
*
* Description:
* This function is invoked if the timeout set to establish the connection
* with vds expires. This will happen if we spend too much time in the
* VDC_STATE_INIT_WAITING, VDC_STATE_NEGOTIATE or VDC_STATE_HANDLE_PENDING
* states.
*
* Arguments:
* arg - argument of the timeout function actually a soft state
* pointer for the instance of the device driver.
*
* Return Code:
* None
*/
void
{
}
/*
* Function:
* vdc_backup_local_dring()
*
* Description:
* Backup the current dring in the event of a reset. The Dring
* transactions will be resubmitted to the server when the
* connection is restored.
*
* Arguments:
* vdcp - soft state pointer for this instance of the device driver.
*
* Return Code:
* NONE
*/
static void
{
/*
* If the backup dring is stil around, it means
* that the last restore did not complete. However,
* since we never got back into the running state,
* the backup copy we have is still valid.
*/
return;
}
/*
* The backup dring can be NULL and the local dring may not be
* initialized. This can happen if we had a reset while establishing
* a new connection but after the connection has timed out. In that
* case the backup dring is NULL because the requests have been
* cancelled and the request occured before the local dring is
* initialized.
*/
return;
/*
* runq. We update the I/O statistics to indicate that they are now
* back in the waitq.
*/
}
/* get the next element */
b_idx = 0;
}
}
static void
{
int rv;
/* if there is only one server return back */
return;
}
/* Get current and next server */
/* bring current server's channel down */
if (rv) {
return;
}
/* switch the server */
}
static void
{
int instance;
return;
switch (svc_state) {
case VDC_SERVICE_OFFLINE:
break;
case VDC_SERVICE_CONNECTED:
break;
case VDC_SERVICE_ONLINE:
break;
case VDC_SERVICE_FAILED:
break;
case VDC_SERVICE_FAULTED:
break;
default:
ASSERT(0);
break;
}
}
/*
* Function:
* vdc_handshake_retry
*
* Description:
* This function indicates if the handshake should be retried or not.
* This depends on the lifecycle of the driver:
*
* VDC_LC_ATTACHING: the handshake is retried until we have tried
* a handshake with each server. We don't care how far each handshake
* went, the goal is just to try the handshake. We want to minimize the
* the time spent doing the attach because this is locking the device
* tree.
*
* VDC_LC_ONLINE_PENDING: the handshake is retried while we haven't done
* consecutive attribute negotiations with each server, and we haven't
* reached a minimum total of consecutive negotiations (hattr_min). The
* number of attribution negotiations determines the time spent before
*
* VDC_LC_ONLINE: the handshake is always retried, until we have a
* successful handshake with a server.
*
* VDC_LC_DETACHING: N/A
*
* Arguments:
* hshake_cnt - number of handshake attempts
* hattr_cnt - number of attribute negotiation attempts
*
* Return Code:
* B_TRUE - handshake should be retried
* B_FALSE - handshake should not be retried
*/
static boolean_t
{
int hattr_total = 0;
/* update handshake counters */
/*
* If no attribute negotiation was done then we reset the total
* number otherwise we cumulate the number.
*/
if (hattr_cnt == 0)
else
/*
* If we are online (i.e. at least one handshake was successfully
* completed) then we always retry the handshake.
*/
return (B_TRUE);
/*
* If we are attaching then we retry the handshake only if we haven't
* tried with all servers.
*/
if (srvr->hshake_cnt == 0) {
return (B_TRUE);
}
}
return (B_FALSE);
}
/*
* Here we are in the case where we haven't completed any handshake
* successfully yet.
*/
/*
* We retry the handshake if we haven't done an attribute negotiation
* with each server. This is to handle the case where one service domain
* is down.
*/
return (B_TRUE);
}
}
/*
* We retry the handshake if we haven't reached the minimum number of
* attribute negotiation.
*/
}
/* -------------------------------------------------------------------------- */
/*
* The following functions process the incoming messages from vds
*/
/*
* Function:
* vdc_process_msg_thread()
*
* Description:
*
* Main VDC message processing thread. Each vDisk instance
* consists of a copy of this thread. This thread triggers
* all the handshakes and data exchange with the server. It
* also handles all channel resets
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* None
*/
static void
{
int status;
int ctimeout;
int hshake_cnt = 0;
int hattr_cnt = 0;
for (;;) {
"UNKNOWN");
#undef Q
case VDC_STATE_INIT:
/*
* If requested, start a timeout to check if the
* connection with vds is established in the
* specified delay. If the timeout expires, we
* will cancel any pending request.
*
* If some reset have occurred while establishing
* the connection, we already have a timeout armed
* and in that case we don't need to arm a new one.
*
* The same rule applies when there are multiple vds'.
* If either a connection cannot be established or
* the handshake times out, the connection thread will
* try another server. The 'ctimeout' will report
* back an error after it expires irrespective of
* whether the vdisk is trying to connect to just
* one or multiple servers.
*/
ctimeout = (vdc_timeout != 0)?
}
/* Switch to STATE_DETACH if drv is detaching */
break;
}
/* Check if the timeout has been reached */
if (vdcp->ctimeout_reached) {
tmid = 0;
break;
}
/*
* Switch to another server when we reach the limit of
* the number of handshake per server or if we have done
* an attribute negotiation.
*/
hattr_cnt)) {
break;
}
hshake_cnt = 0;
hattr_cnt = 0;
}
hshake_cnt++;
/* Bring up connection with vds via LDC */
} else {
}
break;
case VDC_STATE_INIT_WAITING:
/* if channel is UP, start negotiation */
break;
}
/*
* Wait for LDC_UP. If it times out and we have multiple
* servers then we will retry using a different server.
*/
if (status == -1 &&
/* timed out & still waiting */
break;
}
"state moved to %d out from under us...\n",
}
break;
case VDC_STATE_NEGOTIATE:
case 0:
break;
default:
status);
goto reset;
}
hattr_cnt++;
case 0:
break;
default:
status);
goto reset;
}
case 0:
break;
default:
status);
goto reset;
}
case 0:
goto done;
default:
status);
goto reset;
}
status);
done:
break;
case VDC_STATE_HANDLE_PENDING:
/*
* If we have multiple servers, check that the backend
* is effectively available before resubmitting any IO.
*/
vdc_eio_check(vdcp, 0) != 0) {
break;
}
if (tmid != 0) {
tmid = 0;
}
/*
* Setup devid
*/
(void) vdc_setup_devid(vdcp);
if (status) {
} else {
}
break;
case VDC_STATE_FAULTED:
/*
* Server is faulted because the backend is unavailable.
* If all servers are faulted then we mark the service
* as failed, otherwise we reset to switch to another
* server.
*/
/* check if all servers are faulted */
if (svc_state != VDC_SERVICE_FAULTED)
break;
}
} else {
}
break;
case VDC_STATE_FAILED:
/*
* We reach this state when we are unable to access the
* backend from any server, either because of a maximum
* connection retries or timeout, or because the backend
* is unavailable.
*
* Then we cancel the backup DRing so that errors get
* reported and we wait for a new I/O before attempting
* another connection.
*/
} else {
}
/* cancel any timeout */
if (tmid != 0) {
tmid = 0;
}
/* wait for new I/O */
while (!vdcp->io_pending)
/*
* There's a new IO pending. Try to re-establish a
* connection. Mark all services as offline, so that
* we don't stop again before having retried all
* servers.
*/
srvr->hshake_cnt = 0;
srvr->hattr_total = 0;
}
/* reset variables */
hshake_cnt = 0;
hattr_cnt = 0;
break;
/* enter running state */
case VDC_STATE_RUNNING:
break;
}
if (failure_msg) {
}
/*
* Signal anyone waiting for the connection
* to come on line.
*/
/* backend has to be checked after reset */
if (vdcp->failfast_interval != 0 ||
/* ownership is lost during reset */
for (;;) {
if (status) break;
if (status) {
status);
break;
}
}
/* all servers are now offline */
srvr->hshake_cnt = 0;
srvr->hattr_total = 0;
}
hshake_cnt = 0;
hattr_cnt = 0;
break;
case VDC_STATE_RESETTING:
/*
* When we reach this state, we either come from the
* VDC_STATE_RUNNING state and we can have pending
* request but no timeout is armed; or we come from
* the VDC_STATE_INIT_WAITING, VDC_NEGOTIATE or
* VDC_HANDLE_PENDING state and there is no pending
* request or pending requests have already been copied
* into the backup dring. So we can safely keep the
* connection timeout armed while we are in this state.
*/
if (vdcp->self_reset) {
"[%d] calling stop_ldc_connection.\n",
}
/*
* Wait for all threads currently waiting
* for a free dring entry to use.
*/
while (vdcp->threads_pending) {
/* give the waiters enough time to wake up */
}
/* Sanity check that no thread is receiving */
/*
* be resubmitted.
*/
/* cleanup the old d-ring */
/* go and start again */
break;
case VDC_STATE_DETACH:
/* cancel any pending timeout */
if (tmid != 0) {
tmid = 0;
}
/*
* Signal anyone waiting for connection
* to come online
*/
while (vdcp->sync_op_cnt > 0) {
/* give the waiters enough time to wake up */
}
thread_exit();
break;
}
}
}
/*
* Function:
* vdc_process_data_msg()
*
* Description:
* This function is called by the message processing thread each time
* a message with a msgtype of VIO_TYPE_DATA is received. It will either
* be an ACK or NACK from vds[1] which vdc handles as follows.
* ACK - wake up the waiting thread
* NACK - resend any messages necessary
*
* [1] Although the message format allows it, vds should not send a
* VIO_SUBTYPE_INFO message to vdc asking it to read data; if for
* some bizarre reason it does, vdc will reset the connection.
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
* msg - the LDC message sent by vds
*
* Return Code:
* 0 - Success.
* > 0 - error value returned by LDC
*/
static int
{
int status = 0;
int idx;
int op;
/*
* Check to see if the message has bogus data
*/
/*
* Update the I/O statistics to indicate that an error ocurred.
* write request is being completed in response to this 'msg'.
*/
return (EINVAL);
}
/*
* Verify that the sequence number is what vdc expects.
*/
case VDC_SEQ_NUM_TODO:
break; /* keep processing this message */
case VDC_SEQ_NUM_SKIP:
return (0);
case VDC_SEQ_NUM_INVALID:
/*
* Update the I/O statistics to indicate that an error ocurred.
* write request is being completed in response to this 'msg'.
*/
return (ENXIO);
}
/*
* Update the I/O statistics to indicate that an error ocurred.
* the thread calling this function.
*/
return (EIO);
/*
* Update the I/O statistics to indicate that an error occurred.
* write request is being completed in response to this 'msg'.
*/
return (EPROTO);
}
if (status != 0) {
}
"I/O complete req=%ld bytes resp=%ld bytes\n",
/*
* If the request has failed and we have multiple servers or
* failfast is enabled then we will have to defer the completion
* of the request until we have checked that the vdisk backend
* is effectively available (if multiple server) or that there
* is no reservation conflict (if failfast).
*/
if (status != 0 &&
(vdcp->failfast_interval != 0 &&
/*
* The I/O has failed and we need to check the error.
*/
} else {
if (status == 0) {
} else {
}
}
}
}
/* let the arrival signal propogate */
/* probe gives the count of how many entries were processed */
return (0);
}
/*
* Function:
* vdc_handle_ver_msg()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
* ver_msg - LDC message sent by vDisk server
*
* Return Code:
* 0 - Success
*/
static int
{
int status = 0;
return (EPROTO);
}
return (EINVAL);
}
case VIO_SUBTYPE_ACK:
/*
* We check to see if the version returned is indeed supported
* (The server may have also adjusted the minor number downwards
* and if so 'ver_msg' will contain the actual version agreed)
*/
if (vdc_is_supported_version(ver_msg)) {
} else {
}
break;
case VIO_SUBTYPE_NACK:
/*
* call vdc_is_supported_version() which will return the next
* supported version (if any) in 'ver_msg'
*/
(void) vdc_is_supported_version(ver_msg);
/* reset the necessary fields and resend */
} else {
}
break;
case VIO_SUBTYPE_INFO:
/*
* Handle the case where vds starts handshake
* (for now only vdc is the instigator)
*/
break;
default:
break;
}
return (status);
}
/*
* Function:
* vdc_handle_attr_msg()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
* attr_msg - LDC message sent by vDisk server
*
* Return Code:
* 0 - Success
*/
static int
{
int status = 0;
return (EPROTO);
}
case VIO_SUBTYPE_ACK:
/*
* We now verify the attributes sent by vds.
*/
if (attr_msg->vdisk_size == 0) {
break;
}
if (attr_msg->max_xfer_sz == 0) {
break;
}
attr_msg->vdisk_size = 0;
}
/* update the VIO block size */
if (attr_msg->vdisk_block_size > 0 &&
attr_msg->vdisk_block_size) != 0) {
break;
}
/* update disk, block and transfer sizes */
else
vdc->vdisk_media = 0;
(attr_msg->operations == 0) ||
break;
}
/*
* Now that we have received all attributes we can create a
* fake geometry for the disk.
*/
/*
* If the disk type was previously unknown and device nodes
* were created then the driver would have created 8 device
* nodes. If we now find out that this is a single-slice disk
* then we need to re-create the appropriate device nodes.
*/
if (old_type == VD_DISK_TYPE_UNK &&
if (vdc_create_device_nodes(vdc) != 0) {
}
}
break;
case VIO_SUBTYPE_NACK:
/*
* vds could not handle the attributes we sent so we
* stop negotiating.
*/
break;
case VIO_SUBTYPE_INFO:
/*
* Handle the case where vds starts the handshake
* (for now; vdc is the only supported instigatior)
*/
break;
default:
break;
}
return (status);
}
/*
* Function:
* vdc_handle_dring_reg_msg()
*
* Description:
*
* Arguments:
* vdc - soft state pointer for this instance of the driver.
* dring_msg - LDC message sent by vDisk server
*
* Return Code:
* 0 - Success
*/
static int
{
int status = 0;
return (EPROTO);
}
case VIO_SUBTYPE_ACK:
/* save the received dring_ident */
break;
case VIO_SUBTYPE_NACK:
/*
* vds could not handle the DRing info we sent so we
* stop negotiating.
*/
break;
case VIO_SUBTYPE_INFO:
/*
* Handle the case where vds starts handshake
* (for now only vdc is the instigatior)
*/
break;
default:
}
return (status);
}
/*
* Function:
* vdc_verify_seq_num()
*
* Description:
* This functions verifies that the sequence number sent back by the vDisk
* server with the latest message is what is expected (i.e. it is greater
* than the last seq num sent by the vDisk server and less than or equal
* to the last seq num generated by vdc).
*
* It then checks the request ID to see if any requests need processing
* in the DRing.
*
* Arguments:
* vdc - soft state pointer for this instance of the driver.
* dring_msg - pointer to the LDC message sent by vds
*
* Return Code:
* VDC_SEQ_NUM_TODO - Message needs to be processed
* VDC_SEQ_NUM_SKIP - Message has already been processed
* VDC_SEQ_NUM_INVALID - The seq numbers are so out of sync,
* vdc cannot deal with them
*/
static int
{
/*
* Check to see if the messages were responded to in the correct
* order by vds.
*/
"%lu > expected <= %lu (last proc req %lu sent %lu)\n",
return (VDC_SEQ_NUM_INVALID);
}
return (VDC_SEQ_NUM_TODO);
else
return (VDC_SEQ_NUM_SKIP);
}
/*
* Function:
* vdc_is_supported_version()
*
* Description:
* 'ver_msg' are supported. If not it finds the next version that is
* in the supported version list 'vdc_version[]' and sets the fields in
* 'ver_msg' to those values
*
* Arguments:
* ver_msg - LDC message sent by vDisk server
*
* Return Code:
* B_TRUE - Success
* B_FALSE - Version not supported
*/
static boolean_t
{
for (int i = 0; i < vdc_num_versions; i++) {
ASSERT((i == 0) ||
/*
* If the major versions match, adjust the minor version, if
* necessary, down to the highest value supported by this
* client. The server should support all minor versions lower
* than the value it sent
*/
DMSGX(0,
"Adjusting minor version from %u to %u",
}
return (B_TRUE);
}
/*
* If the message contains a higher major version number, set
* and return false, so this message will get resent with
* these values, and the server will potentially try again
* with the same or a lower version
*/
return (B_FALSE);
}
/*
* Otherwise, the message's major version is less than the
* current major version, so continue the loop to the next
* (lower) supported version
*/
}
/*
* No common version was found; "ground" the version pair in the
* message to terminate negotiation
*/
return (B_FALSE);
}
/* -------------------------------------------------------------------------- */
/*
* DKIO(7) support
*/
typedef struct vdc_dk_arg {
int mode;
} vdc_dk_arg_t;
/*
* Function:
* vdc_dkio_flush_cb()
*
* Description:
* This routine is a callback for DKIOCFLUSHWRITECACHE which can be called
* by kernel code.
*
* Arguments:
* arg - a pointer to a vdc_dk_arg_t structure.
*/
void
{
int rv;
return;
}
if (rv != 0) {
}
/*
* Trigger the call back to notify the caller the the ioctl call has
* been completed.
*/
}
/* Indicate that one less DKIO write flush is outstanding */
/* free the mem that was allocated when the callback was dispatched */
}
/*
* Function:
* vdc_dkio_gapart()
*
* Description:
* This function implements the DKIOCGAPART ioctl.
*
* Arguments:
* vdc - soft state pointer
* arg - a pointer to a dk_map[NDKMAP] or dk_map32[NDKMAP] structure
* flag - ioctl flags
*/
static int
{
union {
} data;
return (rv);
}
return (EOVERFLOW);
}
}
} else {
}
}
return (EFAULT);
return (0);
}
/*
* Function:
* vdc_dkio_partition()
*
* Description:
* This function implements the DKIOCPARTITION ioctl.
*
* Arguments:
* vdc - soft state pointer
* arg - a pointer to a struct partition64 structure
* flag - ioctl flags
*/
static int
{
int rv;
return (EFAULT);
}
return (rv);
}
return (ESRCH);
}
sizeof (struct uuid));
return (EFAULT);
}
return (0);
}
/*
* Function:
* vdc_dioctl_rwcmd()
*
* Description:
* This function implements the DIOCTL_RWCMD ioctl. This ioctl is used
* for DKC_DIRECT disks to read or write at an absolute disk offset.
*
* Arguments:
* dev - device
* arg - a pointer to a dadkio_rwcmd or dadkio_rwcmd32 structure
* flag - ioctl flags
*/
static int
{
sizeof (struct dadkio_rwcmd32), flag)) {
return (EFAULT);
}
} else {
sizeof (struct dadkio_rwcmd), flag)) {
return (EFAULT);
}
}
case DADKIO_RWCMD_READ:
break;
case DADKIO_RWCMD_WRITE:
break;
default:
return (EINVAL);
}
/*
* We use the private field of buf to specify that this is an
* I/O using an absolute offset.
*/
return (status);
}
/*
* Allocate a buffer for a VD_OP_SCSICMD operation. The size of the allocated
* buffer is returned in alloc_len.
*/
static vd_scsi_t *
int *alloc_len)
{
*alloc_len = vd_scsi_len;
return (vd_scsi);
}
/*
* Convert the status of a SCSI command to a Solaris return code.
*
* Arguments:
* vd_scsi - The SCSI operation buffer.
* log_error - indicate if an error message should be logged.
*
* Note that our SCSI error messages are rather primitive for the moment
* and could be improved by decoding some data like the SCSI command and
* the sense key.
*
* Return value:
* 0 - Status is good.
* EACCES - Status reports a reservation conflict.
* ENOTSUP - Status reports a check condition and sense key
* reports an illegal request.
* EIO - Any other status.
*/
static int
{
int rv;
/* no error */
return (0);
/* when the tunable vdc_scsi_log_error is true we log all errors */
if (vdc_scsi_log_error)
if (log_error) {
}
/* default returned value */
switch (vd_scsi->cmd_status) {
case STATUS_CHECK:
case STATUS_TERMINATED:
if (log_error)
/* check sense buffer */
if (log_error)
break;
}
if (log_error) {
"\tASC: 0x%x, ASCQ: 0x%x\n",
}
break;
case STATUS_BUSY:
if (log_error)
break;
/*
* If the command was PERSISTENT_RESERVATION_[IN|OUT] then
* reservation conflict could be due to various reasons like
* incorrect keys, not registered or not reserved etc. So,
* we should not panic in that case.
*/
if (vdc->failfast_interval != 0 &&
/* failfast is enabled so we have to panic */
}
if (log_error)
break;
case STATUS_QFULL:
if (log_error)
break;
case STATUS_MET:
case STATUS_INTERMEDIATE:
case STATUS_SCSI2:
case STATUS_INTERMEDIATE_MET:
case STATUS_ACA_ACTIVE:
if (log_error)
"\tUnexpected SCSI status received: 0x%x\n",
break;
default:
if (log_error)
"\tInvalid SCSI status received: 0x%x\n",
break;
}
return (rv);
}
/*
* Implemented the USCSICMD uscsi(7I) ioctl. This ioctl is converted to
* a VD_OP_SCSICMD operation which is sent to the vdisk server. If a SCSI
* reset is requested (i.e. a flag USCSI_RESET* is set) then the ioctl is
* converted to a VD_OP_RESET operation.
*/
static int
{
int vd_scsi_len;
int rv;
mode) != 0)
return (EFAULT);
} else {
mode) != 0)
return (EFAULT);
}
/* a uscsi reset is converted to a VD_OP_RESET operation */
USCSI_RESET_ALL)) {
return (rv);
}
/* cdb buffer length */
/* data in and out buffers length */
dataout_len = 0;
} else {
datain_len = 0;
}
/* sense buffer length */
else
sense_len = 0;
/* allocate buffer for the VD_SCSICMD_OP operation */
&vd_scsi_len);
/*
* The documentation of USCSI_ISOLATE and USCSI_DIAGNOSE is very vague,
* but basically they prevent a SCSI command from being retried in case
* of an error.
*/
/* set task attribute */
vd_scsi->task_attribute = 0;
} else {
else
vd_scsi->task_attribute = 0;
}
/* set timeout */
/* copy-in cdb data */
goto done;
}
/* keep a pointer to the sense buffer */
/* keep a pointer to the data-in buffer */
/* copy-in request data to the data-out buffer */
mode)) {
goto done;
}
}
/* submit the request */
0, 0, VIO_both_dir, B_FALSE);
if (rv != 0)
goto done;
/* update scsi status */
/* update sense data */
goto done;
}
}
}
/* update request data */
goto done;
}
} else {
}
}
/* copy-out result */
mode) != 0) {
goto done;
}
} else {
mode) != 0) {
goto done;
}
}
/* get the return code from the SCSI command status */
done:
return (rv);
}
/*
* Create a VD_OP_SCSICMD buffer for a SCSI PERSISTENT IN command.
*
* Arguments:
* cmd - SCSI PERSISTENT IN command
* len - length of the SCSI input buffer
* vd_scsi_len - return the length of the allocated buffer
*
* Returned Value:
* a pointer to the allocated VD_OP_SCSICMD buffer.
*/
static vd_scsi_t *
{
sense_len = sizeof (struct scsi_extended_sense);
datain_len = len;
dataout_len = 0;
/* set cdb */
return (vd_scsi);
}
/*
* Create a VD_OP_SCSICMD buffer for a SCSI PERSISTENT OUT command.
*
* Arguments:
* cmd - SCSI PERSISTENT OUT command
* len - length of the SCSI output buffer
* vd_scsi_len - return the length of the allocated buffer
*
* Returned Code:
* a pointer to the allocated VD_OP_SCSICMD buffer.
*/
static vd_scsi_t *
{
sense_len = sizeof (struct scsi_extended_sense);
datain_len = 0;
dataout_len = len;
/* set cdb */
return (vd_scsi);
}
/*
* Implement the MHIOCGRP_INKEYS mhd(7i) ioctl. The ioctl is converted
* to a SCSI PERSISTENT IN READ KEYS command which is sent to the vdisk
* server with a VD_OP_SCSICMD operation.
*/
static int
{
void *user_keys;
int vd_scsi_len;
/* copyin arguments */
if (rv != 0)
return (EFAULT);
if (rv != 0)
return (EFAULT);
} else {
if (rv != 0)
return (EFAULT);
if (rv != 0)
return (EFAULT);
}
/* build SCSI VD_OP request */
sizeof (sd_prin_readkeys_t) - sizeof (caddr_t) +
/* submit the request */
0, 0, VIO_both_dir, B_FALSE);
if (rv != 0)
goto done;
if (rv != 0) {
goto done;
}
if (rv != 0) {
goto done;
}
} else {
if (rv != 0) {
goto done;
}
if (rv != 0) {
goto done;
}
}
/* copy out keys */
if (rv != 0)
}
if (rv == 0)
done:
return (rv);
}
/*
* Implement the MHIOCGRP_INRESV mhd(7i) ioctl. The ioctl is converted
* to a SCSI PERSISTENT IN READ RESERVATION command which is sent to
* the vdisk server with a VD_OP_SCSICMD operation.
*/
static int
{
int vd_scsi_len;
/* copyin arguments */
if (rv != 0)
return (EFAULT);
if (rv != 0)
return (EFAULT);
} else {
if (rv != 0)
return (EFAULT);
if (rv != 0)
return (EFAULT);
}
/* build SCSI VD_OP request */
sizeof (sd_prin_readresv_t) - sizeof (caddr_t) +
/* submit the request */
0, 0, VIO_both_dir, B_FALSE);
if (rv != 0)
goto done;
if (rv != 0) {
goto done;
}
if (rv != 0) {
goto done;
}
} else {
if (rv != 0) {
goto done;
}
if (rv != 0) {
goto done;
}
}
/* copy out reservations */
for (i = 0; i < listlen; i++) {
if (rv != 0) {
goto done;
}
resv++;
user_resv++;
}
}
if (rv == 0)
done:
return (rv);
}
/*
* Implement the MHIOCGRP_REGISTER mhd(7i) ioctl. The ioctl is converted
* to a SCSI PERSISTENT OUT REGISTER command which is sent to the vdisk
* server with a VD_OP_SCSICMD operation.
*/
static int
{
/* copyin arguments */
if (rv != 0)
return (EFAULT);
/* build SCSI VD_OP request */
sizeof (sd_prout_t), &vd_scsi_len);
/* set parameters */
/* submit the request */
0, 0, VIO_both_dir, B_FALSE);
if (rv == 0)
return (rv);
}
/*
* Implement the MHIOCGRP_RESERVE mhd(7i) ioctl. The ioctl is converted
* to a SCSI PERSISTENT OUT RESERVE command which is sent to the vdisk
* server with a VD_OP_SCSICMD operation.
*/
static int
{
/* copyin arguments */
if (rv != 0)
return (EFAULT);
/* build SCSI VD_OP request */
sizeof (sd_prout_t), &vd_scsi_len);
/* set parameters */
/* submit the request */
0, 0, VIO_both_dir, B_FALSE);
if (rv == 0)
return (rv);
}
/*
* Implement the MHIOCGRP_PREEMPTANDABORT mhd(7i) ioctl. The ioctl is
* converted to a SCSI PERSISTENT OUT PREEMPT AND ABORT command which
* is sent to the vdisk server with a VD_OP_SCSICMD operation.
*/
static int
{
/* copyin arguments */
if (rv != 0)
return (EFAULT);
/* build SCSI VD_OP request */
sizeof (sd_prout_t), &vd_scsi_len);
/* set parameters */
/* submit the request */
0, 0, VIO_both_dir, B_FALSE);
if (rv == 0)
return (rv);
}
/*
* Implement the MHIOCGRP_REGISTERANDIGNOREKEY mhd(7i) ioctl. The ioctl
* is converted to a SCSI PERSISTENT OUT REGISTER AND IGNORE EXISTING KEY
* command which is sent to the vdisk server with a VD_OP_SCSICMD operation.
*/
static int
{
/* copyin arguments */
if (rv != 0)
return (EFAULT);
/* build SCSI VD_OP request */
sizeof (sd_prout_t), &vd_scsi_len);
/* set parameters */
/* submit the request */
0, 0, VIO_both_dir, B_FALSE);
if (rv == 0)
return (rv);
}
/*
* This function is used to send a (simple) SCSI command and check errors.
*/
static int
{
int rv;
if (scmd == SCMD_WRITE_G1)
else
sense_len = sizeof (struct scsi_extended_sense);
/* set cdb */
/*
* Submit the request. Note the operation should not request that any
* error is checked because this function is precisely called when
* checking errors.
*/
if (rv == 0)
return (rv);
}
/*
* This function is used to check if a SCSI backend is accessible. It will
* also detect reservation conflict if failfast is enabled, and panic the
* system in that case.
*
* Returned Code:
* 0 - disk is accessible
* != 0 - disk is inaccessible or unable to check if disk is accessible
*/
static int
{
int failure = 0;
int rv;
/*
* Send a TEST UNIT READY command. The command will panic
* the system if it fails with a reservation conflict and
* failfast is enabled. If there is a reservation conflict
* and failfast is not enabled then the function will return
* EACCES. In that case, there's no problem with accessing
* the backend, it is just reserved.
*/
failure++;
/* we don't need to do more checking if failfast is not enabled */
if (vdc->failfast_interval == 0)
return (failure);
/*
* With SPC-3 compliant devices TEST UNIT READY will succeed on
* a reserved device, so we also do a WRITE(10) of zero byte in
* order to provoke a Reservation Conflict status on those newer
* devices.
*/
failure++;
return (failure);
}
/*
* This function is used to check if a backend is effectively accessible.
*
* Returned Code:
* 0 - disk is accessible
* != 0 - disk is inaccessible or unable to check if disk is accessible
*/
static int
{
char *buffer;
int rv;
/*
* If the backend does not support SCSI operations then we simply
* check if the backend is accessible by reading some data blocks.
* We first try to read a random block, to try to avoid getting
* a block that might have been cached on the service domain. Then
* we try the last block, and finally the first block.
*
* We return success as soon as we are able to read any block.
*/
if (vdc->vdisk_size > 0) {
/* try a random block */
sizeof (diskaddr_t));
if (rv == 0)
goto done;
/* try the last block */
if (rv == 0)
goto done;
}
/* try block 0 */
blkno = 0;
done:
return (rv);
}
/*
* Add a pending I/O to the eio queue. An I/O is added to this queue
* when it has failed and failfast is enabled or the vdisk has multiple
* servers. It will then be handled by the eio thread (vdc_eio_thread).
* The eio queue is ordered starting with the most recent I/O added.
*/
static vdc_io_t *
{
/* notify the eio thread that a new I/O is queued */
return (vio);
}
/*
*/
static void
{
if (deadline != 0) {
/*
* Skip any io queued after the deadline. The eio queue is
* ordered starting with the last I/O added to the queue.
*/
}
}
/* nothing to unqueue */
return;
/* update the queue */
else
/*
* have a block I/O data transfer structure (buf) and they are
* completed by calling biodone().
*/
if (complete_io) {
}
}
}
}
/*
* Error I/O Thread. There is one eio thread for each virtual disk that
* has multiple servers or for which failfast is enabled. Failfast can only
* be enabled for vdisk supporting SCSI commands.
*
* While failfast is enabled, the eio thread sends a TEST UNIT READY
* and a zero size WRITE(10) SCSI commands on a regular basis to check that
* we still have access to the disk. If a command fails with a RESERVATION
* CONFLICT error then the system will immediatly panic.
*
* The eio thread is also woken up when an I/O has failed. It then checks
* the access to the disk to ensure that the I/O failure was not due to a
* reservation conflict or to the backend been inaccessible.
*
*/
static void
{
int status;
/*
* Wait if there is nothing in the eio queue or if the state
* is not VDC_STATE_RUNNING.
*/
if (vdc->failfast_interval != 0) {
timeout = ddi_get_lbolt() +
timeout);
} else {
}
continue;
}
starttime = ddi_get_lbolt();
/* check error */
/*
* We have dropped the lock to check the backend so we have
* to check that the eio thread is still enabled.
*/
break;
/*
* If the eio queue is empty or we are not in running state
* anymore then there is nothing to do.
*/
continue;
if (status == 0) {
/*
* The backend access has been successfully checked,
* we can complete any I/O queued before the last check.
*/
/*
* The backend is inaccessible for a disk with multiple
* servers. So we force a reset to switch to another
* server. The reset will also clear the eio queue and
*/
} else {
/*
* There is only one path and the backend is not
* of that. So we can complete I/O queued before the
* last check.
*/
}
}
/*
* The thread is being stopped so we can complete any queued I/O.
*/
thread_exit();
}
/*
* Implement the MHIOCENFAILFAST mhd(7i) ioctl.
*/
static int
{
unsigned int mh_time;
return (EFAULT);
v.v_maxsyspri - 2);
}
return (0);
}
/*
* Implement the MHIOCTKOWN and MHIOCRELEASE mhd(7i) ioctls. These ioctls are
* converted to VD_OP_SET_ACCESS operations.
*/
static int
{
int rv;
/* submit owership command request */
return (rv);
}
/*
* Implement the MHIOCSTATUS mhd(7i) ioctl. This ioctl is converted to a
* VD_OP_GET_ACCESS operation.
*/
static int
{
int rv;
/* submit owership command request */
return (rv);
}
/*
* Disk Ownership Thread.
*
* When we have taken the ownership of a disk, this thread waits to be
* notified when the LDC channel is reset so that it can recover the
* ownership.
*
* Note that the thread handling the LDC reset (vdc_process_msg_thread())
* can not be used to do the ownership recovery because it has to be
* running to handle the reply message to the ownership operation.
*/
static void
{
/*
* There was a reset so the ownership has been lost,
* try to recover. We do this without using the preempt
* option so that we don't steal the ownership from
* someone who has preempted us.
*/
if (status == 0) {
} else {
}
}
/*
* If we have the ownership then we just wait for an event
* to happen (LDC reset), otherwise we will retry to recover
* after a delay.
*/
timeout = 0;
else
/* Release the ownership_lock and wait on the vdc lock */
if (timeout == 0)
else
}
thread_exit();
}
static void
{
/* start ownership thread */
v.v_maxsyspri - 2);
} else {
/* notify the ownership thread */
}
}
/*
* Get the size and the block size of a virtual disk from the vdisk server.
*/
static int
{
int rv = 0;
0, 0, VIO_both_dir, B_TRUE);
return (rv);
}
/*
* Check the disk capacity. Disk size information is updated if size has
* changed.
*
* Return 0 if the disk capacity is available, or non-zero if it is not.
*/
static int
{
int rv;
/*
* If the vdisk does not support the VD_OP_GET_CAPACITY operation
* then the disk capacity has been retrieved during the handshake
* and there's nothing more to do here.
*/
return (0);
return (rv);
return (EINVAL);
/*
* First try to update the VIO block size (which is the same as the
* vdisk block size). If this returns an error then that means that
* we can not use that block size so basically the vdisk is unusable
* and we return an error.
*/
if (rv == 0)
return (rv);
}
/*
* This structure is used in the DKIO(7I) array below.
*/
typedef struct vdc_dk_ioctl {
/* function to convert between vDisk and Solaris structure formats */
/*
* Subset of DKIO(7I) operations currently supported
*/
{VD_OP_GET_WCE, DKIOCGETWCE, sizeof (int),
{VD_OP_SET_WCE, DKIOCSETWCE, sizeof (int),
{VD_OP_GET_EFI, DKIOCGETEFI, 0,
{VD_OP_SET_EFI, DKIOCSETEFI, 0,
/* DIOCTL_RWCMD is converted to a read or a write */
/* mhd(7I) non-shared multihost disks ioctls */
{0, MHIOCTKOWN, 0, vdc_null_copy_func},
{0, MHIOCRELEASE, 0, vdc_null_copy_func},
{0, MHIOCSTATUS, 0, vdc_null_copy_func},
{0, MHIOCQRESERVE, 0, vdc_null_copy_func},
/* mhd(7I) shared multihost disks ioctls */
{0, MHIOCGRP_INKEYS, 0, vdc_null_copy_func},
{0, MHIOCGRP_INRESV, 0, vdc_null_copy_func},
{0, MHIOCGRP_REGISTER, 0, vdc_null_copy_func},
{0, MHIOCGRP_RESERVE, 0, vdc_null_copy_func},
{0, MHIOCGRP_PREEMPTANDABORT, 0, vdc_null_copy_func},
/* mhd(7I) failfast ioctl */
{0, MHIOCENFAILFAST, 0, vdc_null_copy_func},
/*
* These particular ioctls are not sent to the server - vdc fakes up
* the necessary info.
*/
{0, DKIOCPARTITION, 0, vdc_null_copy_func },
{0, DKIOCGAPART, 0, vdc_null_copy_func },
{0, DKIOCREMOVABLE, 0, vdc_null_copy_func},
{0, CDROMREADOFFSET, 0, vdc_null_copy_func}
};
/*
* This function handles ioctl requests from the vd_efi_alloc_and_read()
* function and forward them to the vdisk.
*/
static int
{
int rval;
}
/*
* Function:
* vd_process_ioctl()
*
* Description:
* This routine processes disk specific ioctl calls
*
* Arguments:
* dev - the device number
* cmd - the operation [dkio(7I)] to be processed
* arg - pointer to user provided structure
* (contains data to be set or reference parameter for get)
* mode - bit flag, indicating open settings, 32/64 bit type, etc
* rvalp - pointer to return value for calling process.
*
* Return Code:
* 0
* EFAULT
* ENXIO
* EIO
* ENOTSUP
*/
static int
{
instance);
return (ENXIO);
}
/* the return value of the ioctl is 0 by default */
*rvalp = 0;
}
/*
* Validate the ioctl operation to be performed.
*
* If we have looped through the array without finding a match then we
* don't support this ioctl.
*/
break;
}
return (ENOTSUP);
}
/* size is not fixed for EFI ioctls, it depends on ioctl arg */
if (rv != 0)
return (EFAULT);
} else {
}
/* check if the ioctl is applicable */
switch (cmd) {
case CDROMREADOFFSET:
case DKIOCREMOVABLE:
return (ENOTTY);
case USCSICMD:
case MHIOCTKOWN:
case MHIOCSTATUS:
case MHIOCQRESERVE:
case MHIOCRELEASE:
case MHIOCGRP_INKEYS:
case MHIOCGRP_INRESV:
case MHIOCGRP_REGISTER:
case MHIOCGRP_RESERVE:
case MHIOCGRP_PREEMPTANDABORT:
case MHIOCENFAILFAST:
return (ENXIO);
return (ENOTTY);
break;
case DIOCTL_RWCMD:
return (ENXIO);
return (ENOTTY);
break;
case DKIOCINFO:
return (ENXIO);
break;
case DKIOCGMEDIAINFO:
return (ENXIO);
if (vdc_check_capacity(vdc) != 0)
/* disk capacity is not available */
return (EIO);
break;
}
/*
* Deal with ioctls which require a processing different than
* converting ioctl arguments and sending a corresponding
* VD operation.
*/
switch (cmd) {
case USCSICMD:
{
}
case MHIOCTKOWN:
{
/*
* We have to set VDC_OWNERSHIP_WANTED now so that the ownership
* can be flagged with VDC_OWNERSHIP_RESET if the LDC is reset
* while we are processing the ioctl.
*/
if (rv == 0) {
} else {
}
return (rv);
}
case MHIOCRELEASE:
{
if (rv == 0) {
}
return (rv);
}
case MHIOCSTATUS:
{
return (rv);
}
case MHIOCQRESERVE:
{
return (rv);
}
case MHIOCGRP_INKEYS:
{
}
case MHIOCGRP_INRESV:
{
}
case MHIOCGRP_REGISTER:
{
}
case MHIOCGRP_RESERVE:
{
}
case MHIOCGRP_PREEMPTANDABORT:
{
}
{
}
case MHIOCENFAILFAST:
{
return (rv);
}
case DIOCTL_RWCMD:
{
}
case DKIOCGAPART:
{
}
case DKIOCPARTITION:
{
}
case DKIOCINFO:
{
if (rv != 0)
return (EFAULT);
return (0);
}
case DKIOCGMEDIAINFO:
{
if (rv != 0)
return (EFAULT);
return (0);
}
case DKIOCFLUSHWRITECACHE:
{
/*
* If arg is NULL, then there is no callback function
* registered and the call operates synchronously; we
* break and continue with the rest of the function and
* wait for vds to return (i.e. after the request to
* vds returns successfully, all writes completed prior
* to the ioctl will have been flushed from the disk
* write cache to persistent media.
*
* If a callback function is registered, we dispatch
* the request on a task queue and return immediately.
* The callback will deal with informing the calling
* thread that the flush request is completed.
*/
break;
/*
* the asynchronous callback is only supported if
* invoked from within the kernel
*/
return (ENOTSUP);
/* put the request on a task queue */
/* clean up if dispatch fails */
}
}
}
/* catch programming error in vdc - should be a VD_OP_XXX ioctl */
/* check if the vDisk server handles the operation for this vDisk */
return (ENOTSUP);
}
/* LDC requires that the memory being mapped is 8-byte aligned */
if (alloc_len > 0)
/*
* Call the conversion function for this ioctl which, if necessary,
* converts from the Solaris format to the format ARC'ed
* as part of the vDisk protocol (FWARC 2006/195)
*/
if (rv != 0) {
return (rv);
}
/*
* send request to vds to service the ioctl.
*/
if (rv != 0) {
/*
* This is not necessarily an error. The ioctl could
* be returning a value such as ENOTTY to indicate
* that the ioctl is not applicable.
*/
return (rv);
}
/*
* Call the conversion function (if it exists) for this ioctl
* which converts from the format ARC'ed as part of the vDisk
* protocol (FWARC 2006/195) back to a format understood by
* the rest of Solaris.
*/
if (rv != 0) {
return (rv);
}
return (rv);
}
/*
* Function:
*
* Description:
* This is an empty conversion function used by ioctl calls which
*/
static int
{
return (0);
}
static int
{
return (0); /* nothing to do */
return (EFAULT);
return (0);
}
static int
{
if (dir == VD_COPYOUT)
return (0); /* nothing to do */
return (EFAULT);
return (0);
}
/*
* Function:
* vdc_get_vtoc_convert()
*
* Description:
* This routine performs the necessary convertions from the DKIOCGVTOC
* Solaris structure to the format defined in FWARC 2006/195.
*
* In the struct vtoc definition, the timestamp field is marked as not
* supported so it is not part of vDisk protocol (FWARC 2006/195).
* However SVM uses that field to check it can write into the VTOC,
* so we fake up the info of that field.
*
* Arguments:
* vdc - the vDisk client
* from - the buffer containing the data to be copied from
* to - the buffer to be copied to
* mode - flags passed to ioctl() call
* dir - the "direction" of the copy - VD_COPYIN or VD_COPYOUT
*
* Return Code:
* 0 - Success
* ENXIO - incorrect buffer passed in.
* EFAULT - ddi_copyout routine encountered an error.
*/
static int
{
int i;
int rv;
if (dir != VD_COPYOUT)
return (0); /* nothing to do */
return (ENXIO);
return (EOVERFLOW);
/* fake the VTOC timestamp field */
for (i = 0; i < V_NUMPAR; i++) {
}
/* LINTED E_ASSIGN_NARROW_CONV */
if (rv != 0)
} else {
if (rv != 0)
}
return (rv);
}
/*
* Function:
* vdc_set_vtoc_convert()
*
* Description:
* This routine performs the necessary convertions from the DKIOCSVTOC
* Solaris structure to the format defined in FWARC 2006/195.
*
* Arguments:
* vdc - the vDisk client
* from - Buffer with data
* to - Buffer where data is to be copied to
* mode - flags passed to ioctl
* dir - direction of copy (in or out)
*
* Return Code:
* 0 - Success
* ENXIO - Invalid buffer passed in
* EFAULT - ddi_copyin of data failed
*/
static int
{
void *uvtoc;
int i, rv;
return (ENXIO);
return (EOVERFLOW);
if (rv != 0)
return (EFAULT);
} else {
if (rv != 0)
return (EFAULT);
}
if (dir == VD_COPYOUT) {
/*
* The disk label may have changed. Revalidate the disk
* geometry. This will also update the device nodes.
*/
/*
* We also need to keep track of the timestamp fields.
*/
for (i = 0; i < V_NUMPAR; i++) {
}
} else {
}
return (0);
}
static int
{
int i, rv;
if (dir != VD_COPYOUT)
return (0); /* nothing to do */
return (ENXIO);
/* fake the VTOC timestamp field */
for (i = 0; i < V_NUMPAR; i++) {
}
if (rv != 0)
return (rv);
}
static int
{
void *uvtoc;
int i, rv;
return (ENXIO);
if (rv != 0)
return (EFAULT);
if (dir == VD_COPYOUT) {
/*
* The disk label may have changed. Revalidate the disk
* geometry. This will also update the device nodes.
*/
/*
* We also need to keep track of the timestamp fields.
*/
for (i = 0; i < V_NUMPAR; i++) {
}
} else {
}
return (0);
}
/*
* Function:
* vdc_get_geom_convert()
*
* Description:
* This routine performs the necessary convertions from the DKIOCGGEOM,
* DKIOCG_PHYSGEOM and DKIOG_VIRTGEOM Solaris structures to the format
* defined in FWARC 2006/195
*
* Arguments:
* vdc - the vDisk client
* from - Buffer with data
* to - Buffer where data is to be copied to
* mode - flags passed to ioctl
* dir - direction of copy (in or out)
*
* Return Code:
* 0 - Success
* ENXIO - Invalid buffer passed in
* EFAULT - ddi_copyout of data failed
*/
static int
{
int rv = 0;
if (dir != VD_COPYOUT)
return (0); /* nothing to do */
return (ENXIO);
if (rv != 0)
return (rv);
}
/*
* Function:
* vdc_set_geom_convert()
*
* Description:
* This routine performs the necessary convertions from the DKIOCSGEOM
* Solaris structure to the format defined in FWARC 2006/195.
*
* Arguments:
* vdc - the vDisk client
* from - Buffer with data
* to - Buffer where data is to be copied to
* mode - flags passed to ioctl
* dir - direction of copy (in or out)
*
* Return Code:
* 0 - Success
* ENXIO - Invalid buffer passed in
* EFAULT - ddi_copyin of data failed
*/
static int
{
int rv = 0;
return (0); /* nothing to do */
return (ENXIO);
if (rv != 0) {
return (EFAULT);
}
return (0);
}
static int
{
int rv = 0;
void *uaddr;
return (ENXIO);
if (rv != 0)
return (EFAULT);
} else {
if (rv != 0)
return (EFAULT);
mode);
if (rv != 0)
return (EFAULT);
}
return (0);
}
static int
{
void *uaddr;
if (dir == VD_COPYOUT) {
/*
* The disk label may have changed. Revalidate the disk
* geometry. This will also update the device nodes.
*/
return (0);
}
return (ENXIO);
return (EFAULT);
return (EFAULT);
return (0);
}
/* -------------------------------------------------------------------------- */
/*
* Function:
* vdc_create_fake_geometry()
*
* Description:
* This routine fakes up the disk info needed for some DKIO ioctls such
* as DKIOCINFO and DKIOCGMEDIAINFO [just like lofi(7D) and ramdisk(7D) do]
*
* Note: This function must not be called until the vDisk attributes have
* been exchanged as part of the handshake with the vDisk server.
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* none.
*/
static void
{
/*
* DKIOCINFO support
*/
/* max_xfer_sz is #blocks so we don't need to divide by vdisk_bsize */
/*
* We set the controller type to DKC_SCSI_CCS only if the VD_OP_SCSICMD
* operation is supported, otherwise the controller type is DKC_DIRECT.
* Version 1.0 does not support the VD_OP_SCSICMD operation, so the
* controller type is always DKC_DIRECT in that case.
*
* an ISO image, modify the controller type to indicate this
*/
switch (vdc->vdisk_media) {
case VD_MEDIA_CD:
case VD_MEDIA_DVD:
break;
case VD_MEDIA_FIXED:
else
break;
default:
/* in the case of v1.0 we default to a fixed disk */
break;
}
/*
* The partition number will be created on the fly depending on the
* actual slice (i.e. minor node) that is used to request the data.
*/
/*
* DKIOCGMEDIAINFO support
*/
} else {
}
}
static ushort_t
{
int count;
sum = 0;
while (count--) {
}
return (sum);
}
static void
{
/*
* If the disk size is unknown or sizes are unchanged then don't
* update anything.
*/
return;
/*
* We don't know at compile time what the vDisk server will think
* are good values but we apply a large (arbitrary) upper bound to
* prevent memory exhaustion in vdc if it was allocating a DRing
* based of huge values sent by the server. We probably will never
* exceed this except if the message was garbage.
*/
}
}
/*
* Update information about the VIO block size. The VIO block size is the
* same as the vdisk block size which is stored in vdc->vdisk_bsize so we
* do not store that information again.
*
* However, buf structures will always use a logical block size of 512 bytes
* (DEV_BSIZE) and we will need to convert logical block numbers to VIO block
* numbers for each read or write operation using vdc_strategy(). To speed up
* this conversion, we expect the VIO block size to be a power of 2 and a
* multiple 512 bytes (DEV_BSIZE), and we cache some useful information.
*
* The function return EINVAL if the new VIO block size (blk_size) is not a
* power of 2 or not a multiple of 512 bytes, otherwise it returns 0.
*/
static int
{
int nshift = 0;
vdc->vio_bshift = 0;
return (EINVAL);
if ((n & 0x1) != 0) {
/* blk_size is not a power of 2 */
return (EINVAL);
}
nshift++;
}
return (0);
}
/*
* Function:
* vdc_validate_geometry
*
* Description:
* This routine discovers the label and geometry of the disk. It stores
* the disk label and related information in the vdc structure. If it
* fails to validate the geometry or to discover the disk label then
* the label is marked as unknown (VD_DISK_LABEL_UNK).
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - success.
* EINVAL - unknown disk label.
* ENOTSUP - geometry not applicable (EFI label).
* EIO - error accessing the disk.
*/
static int
{
/*
* Check the disk capacity in case it has changed. If that fails then
* we proceed and we will be using the disk size we currently have.
*/
(void) vdc_check_capacity(vdc);
if (rv == 0)
/*
* If the device does not support VTOC then we try
* to read an EFI label.
*
* We need to know the block size and the disk size to
* be able to read an EFI label.
*/
if (vdc->vdisk_size == 0) {
return (EIO);
}
if (rv) {
return (EIO);
}
return (ENOTSUP);
}
if (rv != 0) {
return (rv);
}
/* check that geometry and vtoc are valid */
return (EINVAL);
}
/*
* We have a disk and a valid VTOC. However this does not mean
* that the disk currently have a VTOC label. The returned VTOC may
* be a default VTOC to be used for configuring the disk (this is
* what is done for disk image). So we read the label from the
* beginning of the disk to ensure we really have a VTOC label.
*
* FUTURE: This could be the default way for reading the VTOC
* from the disk as opposed to sending the VD_OP_GET_VTOC
* to the server. This will be the default if vdc is implemented
* ontop of cmlb.
*/
/*
* Single slice disk does not support read using an absolute disk
* offset so we just rely on the DKIOCGVTOC ioctl in that case.
*/
return (EINVAL);
}
return (0);
}
return (EINVAL);
}
/*
* generated by the disk driver. So the on-disk label check
* below may fail and we return now to avoid this problem.
*/
return (0);
}
/*
* Read disk label from start of disk
*/
return (EINVAL);
}
return (0);
}
/*
* Function:
* vdc_validate
*
* Description:
* This routine discovers the label of the disk and create the
* appropriate device nodes if the label has changed.
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* none.
*/
static void
{
int rv;
/* save the current label and vtoc */
/* check the geometry */
(void) vdc_validate_geometry(vdc);
/* if the disk label has changed, update device nodes */
else
if (rv != 0) {
}
}
}
static void
{
vdc->validate_pending--;
}
/*
* Function:
* vdc_setup_devid()
*
* Description:
* This routine discovers the devid of a vDisk. It requests the devid of
* the underlying device from the vDisk server, builds an encapsulated
* devid based on the retrieved devid and registers that new devid to
* the vDisk.
*
* Arguments:
* vdc - soft state pointer for this instance of the device driver.
*
* Return Code:
* 0 - A devid was succesfully registered for the vDisk
*/
static int
{
int rv;
char *devid_str;
/*
* At first sight, we don't know the size of the devid that the
* server will return but this size will be encoded into the
* reply. So we do a first request using a default size then we
* check if this size was large enough. If not then we do a second
* request with the correct size returned by the server. Note that
* ldc requires size to be 8-byte aligned.
*/
sizeof (uint64_t));
if (rv) {
return (rv);
}
/*
* The returned devid is larger than the buffer used. Try again
* with a buffer with the right size.
*/
sizeof (uint64_t));
if (rv) {
return (rv);
}
}
/*
* The virtual disk should have the same device id as the one associated
* with the physical disk it is mapped on, otherwise sharing a disk
* between a LDom and a non-LDom may not work (for example for a shared
* SVM disk set).
*
* The DDI framework does not allow creating a device id with any
* type so we first create a device id of type DEVID_ENCAP and then
* we restore the orignal type of the physical device.
*/
/* build an encapsulated devid based on the returned devid */
return (1);
}
/* check that the devid hasn't changed */
return (0);
}
if (devid_str)
if (devid_str)
return (1);
}
return (1);
}
return (0);
}
static void
{
int i, nparts;
for (i = 0; i < nparts && i < VD_EFI_WD_SLICE; i++) {
if (gpe[i].efi_gpe_StartingLBA == 0 &&
gpe[i].efi_gpe_EndingLBA == 0) {
continue;
}
}
}
static void
{
int i;
}
}
static void
{
}