vds.c revision 690555a1dfb3e9c3b00be26ece1988ed10a6fbe5
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * CDDL HEADER START
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * The contents of this file are subject to the terms of the
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Common Development and Distribution License (the "License").
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * You may not use this file except in compliance with the License.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * See the License for the specific language governing permissions
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * and limitations under the License.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * When distributing Covered Code, include this CDDL HEADER in each
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * If applicable, add the following below this CDDL HEADER, with the
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * fields enclosed by brackets "[]" replaced with your own identifying
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * information: Portions Copyright [yyyy] [name of copyright owner]
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * CDDL HEADER END
3c96341aef2b4da56c902941f089284b52bd573fnarayan * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Use is subject to license terms.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#pragma ident "%Z%%M% %I% %E% SMI"
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Virtual disk server
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* Virtual disk server initialization flags */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* Virtual disk server tunable parameters */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* Identification parameters for MD, synthetic dkio(7i) structures, etc. */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* Virtual disk initialization flags */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* Flags for opening/closing backing devices via LDI */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * By Solaris convention, slice/partition 2 represents the entire disk;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * unfortunately, this convention does not appear to be codified.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* Return a cpp token as a string */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Print a message prefixed with the current function name to the message log
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * (and optionally to the console for verbose boots); these macros use cpp's
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * concatenation of string literals and C99 variable-length-argument-list
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* Return a pointer to the "i"th vdisk dring element */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define VD_DRING_ELEM(i) ((vd_dring_entry_t *)(void *) \
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* Return the virtual disk client's type as a string (for use in messages) */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo (((vd)->xfer_mode == VIO_DESC_MODE) ? "in-band client" : \
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo (((vd)->xfer_mode == VIO_DRING_MODE) ? "dring client" : \
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo "unsupported client")))
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre/* For IO to raw disk on file */
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre/* Read disk label from a disk on file */
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre vd_file_rw(vd, VD_FILE_SLICE_NONE, VD_OP_BREAD, (caddr_t)labelp, \
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre 0, sizeof (struct dk_label))
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre/* Write disk label to a disk on file */
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre vd_file_rw(vd, VD_FILE_SLICE_NONE, VD_OP_BWRITE, (caddr_t)labelp, \
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre 0, sizeof (struct dk_label))
445b4c2ed2d52ef648ae6b36e4f5e14ff3d234afsb * Specification of an MD node passed to the MDEG to filter any
445b4c2ed2d52ef648ae6b36e4f5e14ff3d234afsb * 'vport' nodes that do not belong to the specified node. This
445b4c2ed2d52ef648ae6b36e4f5e14ff3d234afsb * template is copied for each vds instance and filled in with
445b4c2ed2d52ef648ae6b36e4f5e14ff3d234afsb * the appropriate 'cfg-handle' value before being passed to the MDEG.
445b4c2ed2d52ef648ae6b36e4f5e14ff3d234afsb#define VDS_SET_MDEG_PROP_INST(specp, val) (specp)[1].ps_val = (val);
445b4c2ed2d52ef648ae6b36e4f5e14ff3d234afsb * Matching criteria passed to the MDEG to register interest
445b4c2ed2d52ef648ae6b36e4f5e14ff3d234afsb * in changes to 'virtual-device-port' nodes identified by their
445b4c2ed2d52ef648ae6b36e4f5e14ff3d234afsb * 'id' property.
445b4c2ed2d52ef648ae6b36e4f5e14ff3d234afsbstatic mdeg_node_match_t vd_match = {"virtual-device-port",
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* Debugging macros */
3af08d828975d7e2581b6829e0eecff14d87a483lmstatic int vd_msglevel = 0;
3c96341aef2b4da56c902941f089284b52bd573fnarayan PR0("dst:%x op:%x st:%u nb:%lx addr:%lx ncook:%u\n", \
3af08d828975d7e2581b6829e0eecff14d87a483lm switch (state) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#else /* !DEBUG */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define PR0(...)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define PR1(...)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define PR2(...)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#endif /* DEBUG */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * Soft state structure for a vds instance
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppotypedef struct vds {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo uint_t initialized; /* driver inst initialization flags */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo ldi_ident_t ldi_ident; /* driver's identifier for LDI */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo mod_hash_t *vd_table; /* table of virtual disks served */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * Types of descriptor-processing tasks
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayantypedef enum vd_task_type {
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan VD_NONFINAL_RANGE_TASK, /* task for intermediate descriptor in range */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan VD_FINAL_RANGE_TASK, /* task for last in a range of descriptors */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * Structure describing the task for processing a descriptor
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayantypedef struct vd_task {
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan vd_dring_payload_t *request; /* request task will perform */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * Soft state structure for a virtual disk instance
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppotypedef struct vd {
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan ddi_taskq_t *startq; /* queue for I/O start tasks */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan ddi_taskq_t *completionq; /* queue for completion tasks */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo ldi_handle_t ldi_handle[V_NUMPAR]; /* LDI slice handles */
3c96341aef2b4da56c902941f089284b52bd573fnarayan char device_path[MAXPATHLEN + 1]; /* vdisk device */
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan vd_disk_label_t vdisk_label; /* EFI or VTOC label */
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan struct dk_efi dk_efi; /* synthetic for slice type */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo struct dk_geom dk_geom; /* synthetic for slice type */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo ldc_dring_handle_t dring_handle; /* handle for dring ops */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan vd_task_t inband_task; /* task for inband descriptor */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan boolean_t reset_state; /* reset connection state? */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppotypedef struct vds_operation {
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lmtypedef struct vd_ioctl {
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm /* convert input vd_buf to output ioctl_arg */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm /* convert input ioctl_arg to output vd_buf */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm/* Define trivial copyin/copyout conversion function flag */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppostatic void *vds_state;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppostatic uint64_t vds_operations; /* see vds_operation[] definition below */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * Supported protocol version pairs, from highest (newest) to lowest (oldest)
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * Each supported major version should appear only once, paired with (and only
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * with) its highest supported minor version number (as the protocol requires
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * supporting all lower minor version numbers as well)
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * Function:
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * vd_file_rw
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * Description:
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * Read or write to a disk on file.
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * Parameters:
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * vd - disk on which the operation is performed.
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * slice - slice on which the operation is performed,
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * VD_FILE_SLICE_NONE indicates that the operation
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * is done on the raw disk.
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * operation - operation to execute: read (VD_OP_BREAD) or
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * write (VD_OP_BWRITE).
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * data - buffer where data are read to or written from.
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * blk - starting block for the operation.
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * len - number of bytes to read or write.
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * Return Code:
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * n >= 0 - success, n indicates the number of bytes read
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * or written.
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * -1 - error.
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartrevd_file_rw(vd_t *vd, int slice, int operation, caddr_t data, size_t blk,
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre /* raw disk access */
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre /* address past the end of the slice */
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre return (0);
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre offset = (vd->vtoc.v_part[slice].p_start + blk) * DEV_BSIZE;
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * If the requested size is greater than the size
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * of the partition, truncate the read/write.
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre maxlen = (vd->vtoc.v_part[slice].p_size - blk) * DEV_BSIZE;
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre PR0("I/O size truncated to %lu bytes from %lu bytes",
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * We have to ensure that we are reading/writing into the mmap
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * range. If we have a partial disk image (e.g. an image of
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * s0 instead s2) the system can try to access slices that
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * are not included into the disk image.
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre return (-1);
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre srw = (operation == VD_OP_BREAD)? S_READ : S_WRITE;
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre smflags = (operation == VD_OP_BREAD)? 0 : SM_WRITE;
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * segmap_getmapflt() returns a MAXBSIZE chunk which is
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * MAXBSIZE aligned.
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre maddr = segmap_getmapflt(segkmap, vd->file_vnode, offset,
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * Fault in the pages so we can check for error and ensure
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * that we can safely used the mapped address.
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre return (-1);
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre return (-1);
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre return (-1);
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre } while (n > 0);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (EINVAL); /* no service for trivial requests */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan (request->operation == VD_OP_BREAD) ? "Read" : "Write",
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan mtype = (&vd->inband_task == task) ? LDC_SHADOW_MAP : LDC_DIRECT_MAP;
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan /* Map memory exported by client */
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan status = ldc_mem_map(task->mhdl, request->cookie, request->ncookies,
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan mtype, (request->operation == VD_OP_BREAD) ? LDC_MEM_W : LDC_MEM_R,
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan status = ldc_mem_acquire(task->mhdl, 0, buf->b_bcount);
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan buf->b_flags |= (request->operation == VD_OP_BREAD) ? B_READ : B_WRITE;
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Start the block I/O */
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre rv = vd_file_rw(vd, slice, request->operation, buf->b_un.b_addr,
3c96341aef2b4da56c902941f089284b52bd573fnarayan return (EINPROGRESS); /* will complete on completionq */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Clean up after error */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayansend_msg(ldc_handle_t ldc_handle, void *msg, size_t msglen)
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan return (0);
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * Reset the state of the connection with a client, if needed; reset the LDC
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * transport as well, if needed. This function should only be called from the
3af08d828975d7e2581b6829e0eecff14d87a483lm * "vd_recv_msg", as it waits for tasks - otherwise a deadlock can occur.
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan PR0("Resetting connection state with %s", VD_CLIENT(vd));
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * Let any asynchronous I/O complete before possibly pulling the rug
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * out from under it; defer checking vd->reset_ldc, as one of the
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * asynchronous tasks might set it
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan ((status = ldc_mem_dring_unmap(vd->dring_handle)) != 0))
3af08d828975d7e2581b6829e0eecff14d87a483lm /* Free the staging buffer for msgs */
3af08d828975d7e2581b6829e0eecff14d87a483lm /* Free the inband message buffer */
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm if (vd->reset_ldc && ((status = ldc_down(vd->ldc_handle)) != 0))
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan vd->initialized &= ~(VD_SID | VD_SEQ_NUM | VD_DRING);
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan vd->max_msglen = sizeof (vio_msg_t); /* baseline vio message size */
3af08d828975d7e2581b6829e0eecff14d87a483lm /* Allocate the staging buffer */
3af08d828975d7e2581b6829e0eecff14d87a483lmstatic void
3af08d828975d7e2581b6829e0eecff14d87a483lm status = ddi_taskq_dispatch(vd->startq, vd_recv_msg, vd, DDI_SLEEP);
3c96341aef2b4da56c902941f089284b52bd573fnarayanvd_mark_elem_done(vd_t *vd, int idx, int elem_status, int elem_nbytes)
3af08d828975d7e2581b6829e0eecff14d87a483lm return (0);
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Acquire the element */
3af08d828975d7e2581b6829e0eecff14d87a483lm (status = ldc_mem_dring_acquire(vd->dring_handle, idx, idx)) != 0) {
3af08d828975d7e2581b6829e0eecff14d87a483lm return (0);
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Set the element's status and mark it done */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Perhaps client timed out waiting for I/O... */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Release the element */
3af08d828975d7e2581b6829e0eecff14d87a483lm (status = ldc_mem_dring_release(vd->dring_handle, idx, idx)) != 0) {
3af08d828975d7e2581b6829e0eecff14d87a483lm return (0);
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Wait for the I/O to complete */
3c96341aef2b4da56c902941f089284b52bd573fnarayan /* return back the number of bytes read/written */
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan /* Release the buffer */
3af08d828975d7e2581b6829e0eecff14d87a483lm /* Unmap the memory, even if in reset */
3af08d828975d7e2581b6829e0eecff14d87a483lm PR0("ldc_mem_unmap() returned errno %d copying to client",
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Update the dring element for a dring client */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * If a transport error occurred, arrange to "nack" the message when
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * the final task in the descriptor element range completes
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * Only the final task for a range of elements will respond to and
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * free the message
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * Send the "ack" or "nack" back to the client; if sending the message
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * via LDC fails, arrange to reset both the connection state and LDC
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan (task->msg->tag.vio_subtype == VIO_SUBTYPE_ACK) ? "ACK" : "NACK");
3af08d828975d7e2581b6829e0eecff14d87a483lm status = send_msg(vd->ldc_handle, task->msg, task->msglen);
3af08d828975d7e2581b6829e0eecff14d87a483lm switch (status) {
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lmstatic void
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm VD_GEOM2DK_GEOM((vd_geom_t *)vd_buf, (struct dk_geom *)ioctl_arg);
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lmstatic void
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm VD_VTOC2VTOC((vd_vtoc_t *)vd_buf, (struct vtoc *)ioctl_arg);
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lmstatic void
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm DK_GEOM2VD_GEOM((struct dk_geom *)ioctl_arg, (vd_geom_t *)vd_buf);
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lmstatic void
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm VTOC2VD_VTOC((struct vtoc *)ioctl_arg, (vd_vtoc_t *)vd_buf);
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan dk_efi->dki_data = kmem_zalloc(vd_efi->length, KM_SLEEP);
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan dk_efi->dki_data = kmem_alloc(vd_efi->length, KM_SLEEP);
4bac220845f606f60663ed6f3a2b88caa00ae87enarayanvd_read_vtoc(ldi_handle_t handle, struct vtoc *vtoc, vd_disk_label_t *label)
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan status = ldi_ioctl(handle, DKIOCGVTOC, (intptr_t)vtoc,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0);
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan status = vds_efi_alloc_and_read(handle, &efi, &efi_len);
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan return (0);
3c96341aef2b4da56c902941f089284b52bd573fnarayan count = (sizeof (struct dk_label)) / (sizeof (short)) - 1;
3c96341aef2b4da56c902941f089284b52bd573fnarayan while (count--) {
4bac220845f606f60663ed6f3a2b88caa00ae87enarayanvd_do_slice_ioctl(vd_t *vd, int cmd, void *ioctl_arg)
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan bcopy(&vd->dk_geom, ioctl_arg, sizeof (vd->dk_geom));
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan return (0);
3c96341aef2b4da56c902941f089284b52bd573fnarayan return (0);
3c96341aef2b4da56c902941f089284b52bd573fnarayan /* re-compute checksum */
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre /* write label to file */
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre /* update the cached vdisk VTOC */
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan return (0);
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan return (0);
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lmvd_do_ioctl(vd_t *vd, vd_dring_payload_t *request, void* buf, vd_ioctl_t *ioctl)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo size_t nbytes = request->nbytes; /* modifiable copy */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm /* Get data from client and convert, if necessary */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((status = ldc_mem_copy(vd->ldc_handle, buf, 0, &nbytes,
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm /* Convert client's data, if necessary */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm if (ioctl->copyin == VD_IDENTITY) /* use client buffer */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm else /* convert client vdisk operation data to ioctl data */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Handle single-slice block devices internally; otherwise, have the
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * real driver perform the ioctl()
3c96341aef2b4da56c902941f089284b52bd573fnarayan if (vd->file || (vd->vdisk_type == VD_DISK_TYPE_SLICE && !vd->pseudo)) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo } else if ((status = ldi_ioctl(vd->ldi_handle[request->slice],
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan ioctl->cmd, (intptr_t)ioctl->arg, (vd_open_flags | FKIOCTL),
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo PR0("ldi_ioctl(%s) = errno %d", ioctl->cmd_name, status);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (rval != 0) {
3af08d828975d7e2581b6829e0eecff14d87a483lm PR0("%s set rval = %d, which is not being returned to client",
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#endif /* DEBUG */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm /* Convert data and send to client, if necessary */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm /* Convert ioctl data to vdisk operation data, if necessary */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((status = ldc_mem_copy(vd->ldc_handle, buf, 0, &nbytes,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define RNDSIZE(expr) P2ROUNDUP(sizeof (expr), sizeof (uint64_t))
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Command (no-copy) operations */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* "Get" (copy-out) operations */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm {VD_OP_GET_VTOC, STRINGIZE(VD_OP_GET_VTOC), RNDSIZE(vd_vtoc_t),
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan {VD_OP_GET_EFI, STRINGIZE(VD_OP_GET_EFI), RNDSIZE(vd_efi_t),
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* "Set" (copy-in) operations */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm {VD_OP_SET_VTOC, STRINGIZE(VD_OP_SET_VTOC), RNDSIZE(vd_vtoc_t),
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan {VD_OP_SET_EFI, STRINGIZE(VD_OP_SET_EFI), RNDSIZE(vd_efi_t),
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo size_t nioctls = (sizeof (ioctl))/(sizeof (ioctl[0]));
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Determine ioctl corresponding to caller's "operation" and
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * validate caller's "nbytes"
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo for (i = 0; i < nioctls; i++) {
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm /* LDC memory operations require 8-byte multiples */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo ASSERT(i < nioctls); /* because "operation" already validated */
3c96341aef2b4da56c902941f089284b52bd573fnarayan if (!vd->file && vd->vdisk_type == VD_DISK_TYPE_DISK &&
34683adecebe88ca2c857e28be4749f3a083f9fcsg /* update disk information */
34683adecebe88ca2c857e28be4749f3a083f9fcsg if (rc != 0)
3c96341aef2b4da56c902941f089284b52bd573fnarayan /* no devid for disk on file */
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan /* the most common failure is that no devid is available */
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan bufid_len = request->nbytes - sizeof (vd_devid_t) + 1;
3af08d828975d7e2581b6829e0eecff14d87a483lm * Save the buffer size here for use in deallocation.
3af08d828975d7e2581b6829e0eecff14d87a483lm * The actual number of bytes copied is returned in
3af08d828975d7e2581b6829e0eecff14d87a483lm * the 'nbytes' field of the request structure.
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan len = (devid_len > bufid_len)? bufid_len : devid_len;
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan /* LDC memory operations require 8-byte multiples */
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan if ((status = ldc_mem_copy(vd->ldc_handle, (caddr_t)vd_devid, 0,
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan &request->nbytes, request->cookie, request->ncookies,
3af08d828975d7e2581b6829e0eecff14d87a483lm PR0("ldc_mem_copy() returned errno %d copying to client",
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Define the supported operations once the functions for performing them have
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * been defined
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * Process a task specifying a client I/O request
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Find the requested operation */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo for (i = 0; i < vds_noperations; i++)
7636cb21f250f0485ca6052ffadc80ace93e6358lm /* Handle client using absolute disk offsets */
7636cb21f250f0485ca6052ffadc80ace93e6358lm /* Range-check slice */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Start the operation */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan if ((status = vds_operation[i].start(task)) != EINPROGRESS) {
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan request->status = status; /* op succeeded or failed */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan return (0); /* but request completed */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan ASSERT(vds_operation[i].complete != NULL); /* debug case */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan if (vds_operation[i].complete == NULL) { /* non-debug case */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan "with no I/O completion handler");
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan return (0); /* but request completed */
3af08d828975d7e2581b6829e0eecff14d87a483lm PR1("operation : kick off taskq entry for %s", vds_operation[i].namep);
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Queue a task to complete the operation */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan status = ddi_taskq_dispatch(vd->completionq, vds_operation[i].complete,
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* ddi_taskq_dispatch(9f) guarantees success with DDI_SLEEP */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan return (EINPROGRESS); /* completion handler will finish request */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * Return true if the "type", "subtype", and "env" fields of the "tag" first
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * argument match the corresponding remaining arguments; otherwise, return false
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppovd_msgtype(vio_msg_tag_t *tag, int type, int subtype, int env)
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * Check whether the major/minor version specified in "ver_msg" is supported
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * by this server.
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm for (int i = 0; i < vds_num_versions; i++) {
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm ASSERT((i == 0) ||
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * If the major versions match, adjust the minor version, if
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * necessary, down to the highest value supported by this
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * server and return true so this message will get "ack"ed;
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * the client should also support all minor versions lower
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * than the value it sent
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * If the message contains a higher major version number, set
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * the message's major/minor versions to the current values
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * and return false, so this message will get "nack"ed with
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * these values, and the client will potentially try again
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * with the same or a lower version
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * Otherwise, the message's major version is less than the
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * current major version, so continue the loop to the next
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * (lower) supported version
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * No common version was found; "ground" the version pair in the
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * message to terminate negotiation
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * Process a version message from a client. vds expects to receive version
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * messages from clients seeking service, but never issues version messages
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * itself; therefore, vds can ACK or NACK client version messages, but does
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * not expect to receive version-message ACKs or NACKs (and will treat such
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * messages as invalid).
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lmvd_process_ver_msg(vd_t *vd, vio_msg_t *msg, size_t msglen)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (!vd_msgtype(&msg->tag, VIO_TYPE_CTRL, VIO_SUBTYPE_INFO,
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * We're talking to the expected kind of client; set our device class
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * for "ack/nack" back to the client
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * Check whether the (valid) version message specifies a version
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * supported by this server. If the version is not supported, return
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * EBADMSG so the message will get "nack"ed; vds_supported_version()
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * will have updated the message with a supported version for the
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * client to consider
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * A version has been agreed upon; use the client's SID for
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * communication on this channel now
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * When multiple versions are supported, this function should store
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * the negotiated major and minor version values in the "vd" data
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * structure to govern further communication; in particular, note that
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * the client might have specified a lower minor version for the
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * agreed major version than specifed in the vds_version[] array. The
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * following assertions should help remind future maintainers to make
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * the appropriate changes to support multiple versions.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppovd_process_attr_msg(vd_t *vd, vio_msg_t *msg, size_t msglen)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (!vd_msgtype(&msg->tag, VIO_TYPE_CTRL, VIO_SUBTYPE_INFO,
3c96341aef2b4da56c902941f089284b52bd573fnarayan * check if the underlying disk is ready, if not try accessing
3c96341aef2b4da56c902941f089284b52bd573fnarayan * the device again. Open the vdisk device and extract info
3c96341aef2b4da56c902941f089284b52bd573fnarayan * about it, as this is needed to respond to the attr info msg
3c96341aef2b4da56c902941f089284b52bd573fnarayan /* incremental delay */
3c96341aef2b4da56c902941f089284b52bd573fnarayan /* if vdisk is no longer enabled - return error */
3c96341aef2b4da56c902941f089284b52bd573fnarayan PR0("vdisk_type = %s, pseudo = %s, file = %s, nslices = %u",
3c96341aef2b4da56c902941f089284b52bd573fnarayan ((vd->vdisk_type == VD_DISK_TYPE_DISK) ? "disk" : "slice"),
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Success: valid message and transfer mode */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * The vd_dring_inband_msg_t contains one cookie; need room
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * for up to n-1 more cookies, where "n" is the number of full
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * pages plus possibly one partial page required to cover
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * "max_xfer_sz". Add room for one more cookie if
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * "max_xfer_sz" isn't an integral multiple of the page size.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Must first get the maximum transfer size in bytes.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Set the maximum expected message length to
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * accommodate in-band-descriptor messages with all
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * their cookies
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo vd->max_msglen = MAX(vd->max_msglen, max_inband_msglen);
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * Initialize the data structure for processing in-band I/O
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * request descriptors
3af08d828975d7e2581b6829e0eecff14d87a483lm vd->inband_task.msg = kmem_alloc(vd->max_msglen, KM_SLEEP);
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan vd->inband_task.type = VD_FINAL_RANGE_TASK; /* range == 1 */
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm /* Return the device's block size and max transfer size to the client */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppovd_process_dring_reg_msg(vd_t *vd, vio_msg_t *msg, size_t msglen)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo vio_dring_reg_msg_t *reg_msg = (vio_dring_reg_msg_t *)msg;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (!vd_msgtype(&msg->tag, VIO_TYPE_CTRL, VIO_SUBTYPE_INFO,
3af08d828975d7e2581b6829e0eecff14d87a483lm PR0("Expected at least %lu-byte register-dring message; "
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo (reg_msg->ncookies - 1)*(sizeof (reg_msg->cookie[0]));
3af08d828975d7e2581b6829e0eecff14d87a483lm PR0("A dring was previously registered; only support one");
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan reg_msg->ncookies, INT32_MAX, STRINGIZE(INT32_MAX));
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * In addition to fixing the assertion in the success case
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * below, supporting drings which require more than one
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * "cookie" requires increasing the value of vd->max_msglen
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * somewhere in the code path prior to receiving the message
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * which results in calling this function. Note that without
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * making this change, the larger message size required to
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * accommodate multiple cookies cannot be successfully
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * received, so this function will not even get called.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Gracefully accommodating more dring cookies might
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * reasonably demand exchanging an additional attribute or
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * making a minor protocol adjustment
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo status = ldc_mem_dring_map(vd->ldc_handle, reg_msg->cookie,
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan reg_msg->descriptor_size, LDC_DIRECT_MAP, &vd->dring_handle);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (status != 0) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * To remove the need for this assertion, must call
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * ldc_mem_dring_nextcookie() successfully ncookies-1 times after a
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * successful call to ldc_mem_dring_map()
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo ldc_mem_dring_info(vd->dring_handle, &dring_minfo)) != 0) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((status = ldc_mem_dring_unmap(vd->dring_handle)) != 0)
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Initialize for valid message and mapped dring */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * Allocate and initialize a "shadow" array of data structures for
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * tasks to process I/O requests in dring elements
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan kmem_zalloc((sizeof (*vd->dring_task)) * vd->dring_len, KM_SLEEP);
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan vd->dring_task[i].request = &VD_DRING_ELEM(i)->payload;
3af08d828975d7e2581b6829e0eecff14d87a483lm vd->dring_task[i].msg = kmem_alloc(vd->max_msglen, KM_SLEEP);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppovd_process_dring_unreg_msg(vd_t *vd, vio_msg_t *msg, size_t msglen)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo vio_dring_unreg_msg_t *unreg_msg = (vio_dring_unreg_msg_t *)msg;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (!vd_msgtype(&msg->tag, VIO_TYPE_CTRL, VIO_SUBTYPE_INFO,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0);
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan if (!vd_msgtype(&msg->tag, VIO_TYPE_CTRL, VIO_SUBTYPE_INFO, VIO_RDX)) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((vd->initialized & VD_SEQ_NUM) && (seq_num != vd->seq_num + 1)) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (1);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo vd->initialized |= VD_SEQ_NUM; /* superfluous after first time... */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Return the expected size of an inband-descriptor message with all the
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * cookies it claims to include
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return ((sizeof (*msg)) +
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo (msg->payload.ncookies - 1)*(sizeof (msg->payload.cookie[0])));
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Process an in-band descriptor message: used with clients like OBP, with
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * which vds exchanges descriptors within VIO message payloads, rather than
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * operating on them within a descriptor ring
3af08d828975d7e2581b6829e0eecff14d87a483lmvd_process_desc_msg(vd_t *vd, vio_msg_t *msg, size_t msglen)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo vd_dring_inband_msg_t *desc_msg = (vd_dring_inband_msg_t *)msg;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (!vd_msgtype(&msg->tag, VIO_TYPE_DATA, VIO_SUBTYPE_INFO,
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan PR1("Message is not an in-band-descriptor message");
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (msglen != (expected = expected_inband_size(desc_msg))) {
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan if (vd_check_seq_num(vd, desc_msg->hdr.seq_num) != 0)
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * Valid message: Set up the in-band descriptor task and process the
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * request. Arrange to acknowledge the client's message, unless an
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * error processing the descriptor task results in setting
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * VIO_SUBTYPE_NACK
3af08d828975d7e2581b6829e0eecff14d87a483lm * The task request is now the payload of the message
3af08d828975d7e2581b6829e0eecff14d87a483lm * that was just copied into the body of the task.
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayanvd_process_element(vd_t *vd, vd_task_type_t type, uint32_t idx,
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Accept the updated dring element */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan if ((status = ldc_mem_dring_acquire(vd->dring_handle, idx, idx)) != 0) {
3af08d828975d7e2581b6829e0eecff14d87a483lm PR0("ldc_mem_dring_acquire() returned errno %d", status);
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan if ((status = ldc_mem_dring_release(vd->dring_handle, idx, idx)) != 0) {
3af08d828975d7e2581b6829e0eecff14d87a483lm PR0("ldc_mem_dring_release() returned errno %d", status);
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Initialize a task and process the accepted element */
3af08d828975d7e2581b6829e0eecff14d87a483lm /* duplicate msg buf for cookies etc. */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan if ((status = vd_process_task(&vd->dring_task[idx])) != EINPROGRESS)
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayanvd_process_element_range(vd_t *vd, int start, int end,
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * Arrange to acknowledge the client's message, unless an error
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * processing one of the dring elements results in setting
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * VIO_SUBTYPE_NACK
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * Process the dring elements in the range
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan nelem = ((end < start) ? end + vd->dring_len : end) - start + 1;
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan for (i = start, n = nelem; n > 0; i = (i + 1) % vd->dring_len, n--) {
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan type = (n == 1) ? VD_FINAL_RANGE_TASK : VD_NONFINAL_RANGE_TASK;
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan else if (status != 0)
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * If some, but not all, operations of a multi-element range are in
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * progress, wait for other operations to complete before returning
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * (which will result in "ack" or "nack" of the message). Note that
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * all outstanding operations will need to complete, not just the ones
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * corresponding to the current range of dring elements; howevever, as
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * this situation is an error case, performance is less critical.
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan if ((nelem > 1) && (status != EINPROGRESS) && inprogress)
3af08d828975d7e2581b6829e0eecff14d87a483lmvd_process_dring_msg(vd_t *vd, vio_msg_t *msg, size_t msglen)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (!vd_msgtype(&msg->tag, VIO_TYPE_DATA, VIO_SUBTYPE_INFO,
3af08d828975d7e2581b6829e0eecff14d87a483lm PR0("Expected %lu-byte dring message; received %lu bytes",
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Valid message; process range of updated dring elements */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan PR1("Processing descriptor range, start = %u, end = %u",
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan return (vd_process_element_range(vd, dring_msg->start_idx,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fhepporecv_msg(ldc_handle_t ldc_handle, void *msg, size_t *nbytes)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo } else if (*nbytes == 0) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0);
3af08d828975d7e2581b6829e0eecff14d87a483lmvd_do_process_msg(vd_t *vd, vio_msg_t *msg, size_t msglen)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo PR1("Processing (%x/%x/%x) message", msg->tag.vio_msgtype,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Validate session ID up front, since it applies to all messages
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((msg->tag.vio_sid != vd->sid) && (vd->initialized & VD_SID)) {
3af08d828975d7e2581b6829e0eecff14d87a483lm PR1("\tWhile in state %d (%s)", vd->state, vd_decode_state(vd->state));
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Process the received message based on connection state
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Version negotiated, move to that state */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((status = vd_process_attr_msg(vd, msg, msglen)) != 0)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Attributes exchanged, move to that state */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Ready to receive in-band descriptors */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo case VIO_DRING_MODE: /* expect register-dring message */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* One dring negotiated, move to that state */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo case VD_STATE_DRING: /* expect RDX, register-dring, or unreg-dring */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Ready to receive data */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * If another register-dring message is received, stay in
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * dring state in case the client sends RDX; although the
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * protocol allows multiple drings, this server does not
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * support using more than one
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Acknowledge an unregister-dring message, but reset the
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * connection anyway: Although the protocol allows
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * unregistering drings, this server cannot serve a vdisk
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * without its only dring
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo case VIO_DESC_MODE: /* expect in-band-descriptor message */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo case VIO_DRING_MODE: /* expect dring-data or unreg-dring */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Typically expect dring-data messages, so handle
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * them first
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Acknowledge an unregister-dring message, but reset
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * the connection anyway: Although the protocol
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * allows unregistering drings, this server cannot
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * serve a vdisk without its only dring
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Check that the message is at least big enough for a "tag", so that
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * message processing can proceed based on tag-specified message type
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Can't "nack" short message, so drop the big hammer */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Process the message
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* "ack" valid, successfully-processed messages */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* The completion handler will "ack" or "nack" the message */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* "nack" invalid messages */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* "nack" failed messages */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* An LDC error probably occurred, so try resetting it */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Send the "ack" or "nack" to the client */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo (msg->tag.vio_subtype == VIO_SUBTYPE_ACK) ? "ACK" : "NACK");
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Arrange to reset the connection for nack'ed or failed messages */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * Receive and process a message
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan vd_reset_if_needed(vd); /* can change vd->max_msglen */
3af08d828975d7e2581b6829e0eecff14d87a483lm * check if channel is UP - else break out of loop
3af08d828975d7e2581b6829e0eecff14d87a483lm msgsize = vd->max_msglen; /* stable copy for alloc/free */
3af08d828975d7e2581b6829e0eecff14d87a483lm status = recv_msg(vd->ldc_handle, vd->vio_msgp, &msglen);
3af08d828975d7e2581b6829e0eecff14d87a483lm switch (status) {
3af08d828975d7e2581b6829e0eecff14d87a483lm /* check if max_msglen changed */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Probably an LDC failure; arrange to reset it */
3af08d828975d7e2581b6829e0eecff14d87a483lm PR0("EVT_UP: LDC is up\nResetting client connection state");
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm /* Queue a task to receive the new data */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan status = ddi_taskq_dispatch(vd->startq, vd_recv_msg, vd,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppovds_check_for_vd(mod_hash_key_t key, mod_hash_val_t *val, void *arg)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo switch (cmd) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* the real work happens below */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((vds = ddi_get_soft_state(vds_state, instance)) == NULL) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Do no detach when serving any vdisks */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo mod_hash_walk(vds->vd_table, vds_check_for_vd, &vd_present);
445b4c2ed2d52ef648ae6b36e4f5e14ff3d234afsb kmem_free(vds->ispecp->specp, sizeof (vds_prop_template));
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo for (parent = ddi_get_parent(dip); (parent != NULL) && (parent != root);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (strcmp(ddi_get_name(parent), DEVI_PSEUDO_NEXNAME) == 0)
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm minor_t minor = getminor(vd->dev[0]) - VD_ENTIRE_DISK_SLICE;
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan * At this point, vdisk_size is set to the size of partition 2 but
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan * this does not represent the size of the disk because partition 2
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan * may not cover the entire disk and its size does not include reserved
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan * blocks. So we update vdisk_size to be the size of the entire disk.
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan if ((status = ldi_ioctl(vd->ldi_handle[0], DKIOCGMEDIAINFO,
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre PRN("ldi_ioctl(DKIOCGMEDIAINFO) returned errno %d",
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm /* Set full-disk parameters */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm /* Move dev number and LDI handle to entire-disk-slice array elements */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm vd->ldi_handle[VD_ENTIRE_DISK_SLICE] = vd->ldi_handle[0];
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm /* Initialize device numbers for remaining slices and open them */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * Skip the entire-disk slice, as it's already open and its
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * device known
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * Construct the device number for the current slice
34683adecebe88ca2c857e28be4749f3a083f9fcsg * Open all slices of the disk to serve them to the client.
34683adecebe88ca2c857e28be4749f3a083f9fcsg * Slices are opened exclusively to prevent other threads or
34683adecebe88ca2c857e28be4749f3a083f9fcsg * processes in the service domain from performing I/O to
34683adecebe88ca2c857e28be4749f3a083f9fcsg * slices being accessed by a client. Failure to open a slice
34683adecebe88ca2c857e28be4749f3a083f9fcsg * results in vds not serving this disk, as the client could
34683adecebe88ca2c857e28be4749f3a083f9fcsg * attempt (and should be able) to access any slice immediately.
34683adecebe88ca2c857e28be4749f3a083f9fcsg * Any slices successfully opened before a failure will get
34683adecebe88ca2c857e28be4749f3a083f9fcsg * closed by vds_destroy_vd() as a result of the error returned
34683adecebe88ca2c857e28be4749f3a083f9fcsg * by this function.
34683adecebe88ca2c857e28be4749f3a083f9fcsg * We need to do the open with FNDELAY so that opening an empty
34683adecebe88ca2c857e28be4749f3a083f9fcsg * slice does not fail.
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm /* vds_destroy_vd() will close any open slices */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm return (0);
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan gpt->efi_gpt_HeaderSize = LE_32(sizeof (efi_gpt_t));
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan gpt->efi_gpt_LastUsableLBA = LE_64(vd->vdisk_size - 1);
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan gpt->efi_gpt_SizeOfPartitionEntry = LE_32(sizeof (efi_gpe_t));
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan UUID_LE_CONVERT(gpe->efi_gpe_PartitionTypeGUID, uuid);
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan gpe->efi_gpe_StartingLBA = gpt->efi_gpt_FirstUsableLBA;
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan gpe->efi_gpe_EndingLBA = gpt->efi_gpt_LastUsableLBA;
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan CRC32(crc, gpe, sizeof (efi_gpe_t), -1U, crc32_table);
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan gpt->efi_gpt_PartitionEntryArrayCRC32 = LE_32(~crc);
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan CRC32(crc, gpt, sizeof (efi_gpt_t), -1U, crc32_table);
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan return (0);
3c96341aef2b4da56c902941f089284b52bd573fnarayan /* make sure the file is valid */
3c96341aef2b4da56c902941f089284b52bd573fnarayan if ((status = lookupname(file_path, UIO_SYSSPACE, FOLLOW,
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre PRN("Cannot lookup file(%s) errno %d", file_path, status);
3c96341aef2b4da56c902941f089284b52bd573fnarayan if ((status = vn_open(file_path, UIO_SYSSPACE, vd_open_flags | FOFFMAX,
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * We set vd->file now so that vds_destroy_vd will take care of
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * closing the file and releasing the vnode in case of an error.
3c96341aef2b4da56c902941f089284b52bd573fnarayan if ((status = VOP_GETATTR(vd->file_vnode, &vattr, 0, kcred)) != 0) {
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre PRN("VOP_GETATTR(%s) = errno %d", file_path, status);
3c96341aef2b4da56c902941f089284b52bd573fnarayan /* size should be at least sizeof(dk_label) */
3c96341aef2b4da56c902941f089284b52bd573fnarayan sizeof (struct dk_label));
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre /* read label from file */
3c96341aef2b4da56c902941f089284b52bd573fnarayan /* label checksum */
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre if (label.dkl_magic != DKL_MAGIC || label.dkl_cksum != sum) {
3c96341aef2b4da56c902941f089284b52bd573fnarayan "(magic=%x cksum=%x (expect %x))",
3c96341aef2b4da56c902941f089284b52bd573fnarayan /* default label */
3c96341aef2b4da56c902941f089284b52bd573fnarayan * We must have a resonable number of cylinders and sectors so
3c96341aef2b4da56c902941f089284b52bd573fnarayan * that newfs can run using default values.
3c96341aef2b4da56c902941f089284b52bd573fnarayan * if (disk_size < 2MB)
3c96341aef2b4da56c902941f089284b52bd573fnarayan * phys_cylinders = disk_size / 100K
3c96341aef2b4da56c902941f089284b52bd573fnarayan * phys_cylinders = disk_size / 300K
3c96341aef2b4da56c902941f089284b52bd573fnarayan * phys_cylinders = (phys_cylinders == 0) ? 1 : phys_cylinders
3c96341aef2b4da56c902941f089284b52bd573fnarayan * alt_cylinders = (phys_cylinders > 2) ? 2 : 0;
3c96341aef2b4da56c902941f089284b52bd573fnarayan * data_cylinders = phys_cylinders - alt_cylinders
3c96341aef2b4da56c902941f089284b52bd573fnarayan * sectors = disk_size / (phys_cylinders * blk_size)
3c96341aef2b4da56c902941f089284b52bd573fnarayan PR0("requested disk size: %ld bytes\n", vd->file_size);
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre PR0("setup: ncyl=%d nhead=%d nsec=%d\n", label.dkl_pcyl,
3c96341aef2b4da56c902941f089284b52bd573fnarayan * We must have a correct label name otherwise format(1m) will
3c96341aef2b4da56c902941f089284b52bd573fnarayan * not recognized the disk as labeled.
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre (void) snprintf(label.dkl_asciilabel, LEN_DKL_ASCII,
3c96341aef2b4da56c902941f089284b52bd573fnarayan "SUNVDSK cyl %d alt %d hd %d sec %d",
3c96341aef2b4da56c902941f089284b52bd573fnarayan /* default VTOC */
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre /* write default label to file */
3c96341aef2b4da56c902941f089284b52bd573fnarayan /* sector size = block size = DEV_BSIZE */
3c96341aef2b4da56c902941f089284b52bd573fnarayan vd->max_xfer_sz = maxphys / DEV_BSIZE; /* default transfer size */
3c96341aef2b4da56c902941f089284b52bd573fnarayan /* Get max_xfer_sz from the device where the file is */
3c96341aef2b4da56c902941f089284b52bd573fnarayan if (ddi_dev_pathname(dev, S_IFBLK, dev_path) == DDI_SUCCESS) {
3c96341aef2b4da56c902941f089284b52bd573fnarayan if ((status = ldi_open_by_dev(&dev, OTYP_BLK, FREAD,
3c96341aef2b4da56c902941f089284b52bd573fnarayan PR0("ldi_open_by_dev() returned errno %d for device %s",
3c96341aef2b4da56c902941f089284b52bd573fnarayan (intptr_t)&dk_cinfo, (vd_open_flags | FKIOCTL), kcred,
3c96341aef2b4da56c902941f089284b52bd573fnarayan PR0("ldi_ioctl(DKIOCINFO) returned errno %d for %s",
3c96341aef2b4da56c902941f089284b52bd573fnarayan * Store the device's max transfer size for
3c96341aef2b4da56c902941f089284b52bd573fnarayan * return to the client
3c96341aef2b4da56c902941f089284b52bd573fnarayan PR0("using for file %s, dev %s, max_xfer = %u blks",
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre vd->dk_geom.dkg_write_reinstruct = label.dkl_write_reinstruct;
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre vd->dk_geom.dkg_read_reinstruct = label.dkl_read_reinstruct;
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre vd->vtoc.timestamp[i] = label.dkl_vtoc.v_timestamp[i];
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre vd->vtoc.v_part[i].p_tag = label.dkl_vtoc.v_part[i].p_tag;
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre vd->vtoc.v_part[i].p_flag = label.dkl_vtoc.v_part[i].p_flag;
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre vd->vtoc.v_part[i].p_start = label.dkl_map[i].dkl_cylno *
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre vd->vtoc.v_part[i].p_size = label.dkl_map[i].dkl_nblk;
3c96341aef2b4da56c902941f089284b52bd573fnarayan return (0);
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan * We need to open with FNDELAY so that opening an empty partition
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan * does not fail.
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan if ((status = ldi_open_by_name(device_path, vd_open_flags | FNDELAY,
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan kcred, &vd->ldi_handle[0], vd->vds->ldi_ident)) != 0) {
3c96341aef2b4da56c902941f089284b52bd573fnarayan PR0("ldi_open_by_name(%s) = errno %d", device_path, status);
3c96341aef2b4da56c902941f089284b52bd573fnarayan /* this may not be a device try opening as a file */
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan * nslices must be updated now so that vds_destroy_vd() will close
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan * the slice we have just opened in case of an error.
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm /* Get device number and size of backing device */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm if ((status = ldi_get_dev(vd->ldi_handle[0], &vd->dev[0])) != 0) {
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm if (ldi_get_size(vd->ldi_handle[0], &vd->vdisk_size) != DDI_SUCCESS) {
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm vd->vdisk_size = lbtodb(vd->vdisk_size); /* convert to blocks */
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm /* Verify backing device supports dk_cinfo, dk_geom, and vtoc */
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm &rval)) != 0) {
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan status = vd_read_vtoc(vd->ldi_handle[0], &vd->vtoc, &vd->vdisk_label);
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan PRN("ldi_ioctl(DKIOCGEOM) returned errno %d for %s",
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm /* Store the device's max transfer size for return to the client */
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm /* Determine if backing device is a pseudo device */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((dip = ddi_hold_devi_by_instance(getmajor(vd->dev[0]),
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0); /* ...and we're done */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm /* If slice is entire-disk slice, initialize for full disk */
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm /* Otherwise, we have a non-entire slice of a device */
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm /* Initialize dk_geom structure for single-slice device */
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre PRN("%s geometry claims 0 sectors per track", device_path);
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm vd->vdisk_size/vd->dk_geom.dkg_nsect/vd->dk_geom.dkg_nhead;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo vd->dk_geom.dkg_pcyl = vd->dk_geom.dkg_ncyl + vd->dk_geom.dkg_acyl;
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm /* Initialize vtoc structure for single-slice device */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo MIN(sizeof (VD_VOLUME_NAME), sizeof (vd->vtoc.v_volume)));
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo MIN(sizeof (VD_ASCIILABEL), sizeof (vd->vtoc.v_asciilabel)));
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0);
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lmvds_do_init_vd(vds_t *vds, uint64_t id, char *device_path, uint64_t ldc_id,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((vd = kmem_zalloc(sizeof (*vd), KM_NOSLEEP)) == NULL) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo *vdp = vd; /* assign here so vds_destroy_vd() can cleanup later */
3c96341aef2b4da56c902941f089284b52bd573fnarayan (void) strncpy(vd->device_path, device_path, MAXPATHLEN);
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm /* Open vdisk and initialize parameters */
3c96341aef2b4da56c902941f089284b52bd573fnarayan PR0("vdisk_type = %s, pseudo = %s, file = %s, nslices = %u",
3c96341aef2b4da56c902941f089284b52bd573fnarayan ((vd->vdisk_type == VD_DISK_TYPE_DISK) ? "disk" : "slice"),
3c96341aef2b4da56c902941f089284b52bd573fnarayan (vd->pseudo ? "yes" : "no"), (vd->file ? "yes" : "no"),
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Initialize locking */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (ddi_get_soft_iblock_cookie(vds->dip, DDI_SOFTINT_MED,
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Create start and completion task queues for the vdisk */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan (void) snprintf(tq_name, sizeof (tq_name), "vd_startq%lu", id);
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan if ((vd->startq = ddi_taskq_create(vds->dip, tq_name, 1,
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan (void) snprintf(tq_name, sizeof (tq_name), "vd_completionq%lu", id);
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan if ((vd->completionq = ddi_taskq_create(vds->dip, tq_name, 1,
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan vd->enabled = 1; /* before callback can dispatch to startq */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Bring up LDC */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((status = ldc_init(ldc_id, &ldc_attr, &vd->ldc_handle)) != 0) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((status = ldc_reg_callback(vd->ldc_handle, vd_handle_ldc_events,
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre "reg_callback failed with error %d", ldc_id, status);
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan /* Allocate the inband task memory handle */
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan status = ldc_mem_alloc_handle(vd->ldc_handle, &(vd->inband_task.mhdl));
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre "alloc_handle failed with error %d", ldc_id, status);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Add the successfully-initialized vdisk to the server's table */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (mod_hash_insert(vds->vd_table, (mod_hash_key_t)id, vd) != 0) {
3af08d828975d7e2581b6829e0eecff14d87a483lm /* Allocate the staging buffer */
3af08d828975d7e2581b6829e0eecff14d87a483lm vd->max_msglen = sizeof (vio_msg_t); /* baseline vio message size */
3af08d828975d7e2581b6829e0eecff14d87a483lm /* store initial state */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0);
3af08d828975d7e2581b6829e0eecff14d87a483lmstatic void
3af08d828975d7e2581b6829e0eecff14d87a483lm /* Free all dring_task memory handles */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Destroy the state associated with a virtual disk
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan kmem_free(vd->dk_efi.dki_data, vd->dk_efi.dki_length);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Disable queuing requests for the vdisk */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Drain and destroy start queue (*before* destroying completionq) */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan ddi_taskq_destroy(vd->startq); /* waits for queued tasks */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Drain and destroy completion queue (*before* shutting down LDC) */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan ddi_taskq_destroy(vd->completionq); /* waits for tasks */
34683adecebe88ca2c857e28be4749f3a083f9fcsg /* Free the inband task memory handle */
34683adecebe88ca2c857e28be4749f3a083f9fcsg /* Shut down LDC */
34683adecebe88ca2c857e28be4749f3a083f9fcsg /* unmap the dring */
34683adecebe88ca2c857e28be4749f3a083f9fcsg /* close LDC channel - retry on EAGAIN */
34683adecebe88ca2c857e28be4749f3a083f9fcsg if (rv == 0) {
34683adecebe88ca2c857e28be4749f3a083f9fcsg * Closing the LDC channel has failed. Ideally we should
34683adecebe88ca2c857e28be4749f3a083f9fcsg * fail here but there is no Zeus level infrastructure
34683adecebe88ca2c857e28be4749f3a083f9fcsg * to handle this. The MD has already been changed and
34683adecebe88ca2c857e28be4749f3a083f9fcsg * we have to do the close. So we try to do as much
34683adecebe88ca2c857e28be4749f3a083f9fcsg * clean up as we can.
3af08d828975d7e2581b6829e0eecff14d87a483lm /* Free the staging buffer for msgs */
3af08d828975d7e2581b6829e0eecff14d87a483lm /* Free the inband message buffer */
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre /* Close file */
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre /* Close any open backing-device slices */
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre for (uint_t slice = 0; slice < vd->nslices; slice++) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Free lock */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Finally, free the vdisk structure itself */
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lmvds_init_vd(vds_t *vds, uint64_t id, char *device_path, uint64_t ldc_id)
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm if ((status = vds_do_init_vd(vds, id, device_path, ldc_id, &vd)) != 0)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppovds_do_get_ldc_id(md_t *md, mde_cookie_t vd_node, mde_cookie_t *channel,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Look for channel endpoint child(ren) of the vdisk MD node */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo PRN("No \"%s\" found for virtual disk", VD_CHANNEL_ENDPOINT);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (-1);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Get the "id" value for the first channel endpoint node */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (md_get_prop_val(md, channel[0], VD_ID_PROP, ldc_id) != 0) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (-1);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo PRN("Using ID of first of multiple channels for this vdisk");
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppovds_get_ldc_id(md_t *md, mde_cookie_t vd_node, uint64_t *ldc_id)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo PRN("Invalid node count in Machine Description subtree");
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (-1);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo status = vds_do_get_ldc_id(md, vd_node, channel, ldc_id);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (md_get_prop_val(md, vd_node, VD_ID_PROP, &id) != 0) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (md_get_prop_str(md, vd_node, VD_BLOCK_DEVICE_PROP,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo PRN("Error getting vdisk \"%s\"", VD_BLOCK_DEVICE_PROP);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppovds_remove_vd(vds_t *vds, md_t *md, mde_cookie_t vd_node)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (md_get_prop_val(md, vd_node, VD_ID_PROP, &id) != 0) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo PRN("Unable to get \"%s\" property from vdisk's MD node",
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (mod_hash_destroy(vds->vd_table, (mod_hash_key_t)id) != 0)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppovds_change_vd(vds_t *vds, md_t *prev_md, mde_cookie_t prev_vd_node,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Validate that vdisk ID has not changed */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (md_get_prop_val(prev_md, prev_vd_node, VD_ID_PROP, &prev_id) != 0) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (md_get_prop_val(curr_md, curr_vd_node, VD_ID_PROP, &curr_id) != 0) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo PRN("Error getting current vdisk \"%s\" property", VD_ID_PROP);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Validate that LDC ID has not changed */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (vds_get_ldc_id(prev_md, prev_vd_node, &prev_ldc_id) != 0) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (vds_get_ldc_id(curr_md, curr_vd_node, &curr_ldc_id) != 0) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo "LDC ID changed from %lu to %lu", prev_ldc_id, curr_ldc_id);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Determine whether device path has changed */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (md_get_prop_str(prev_md, prev_vd_node, VD_BLOCK_DEVICE_PROP,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (md_get_prop_str(curr_md, curr_vd_node, VD_BLOCK_DEVICE_PROP,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo PRN("Error getting current vdisk \"%s\"", VD_BLOCK_DEVICE_PROP);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return; /* no relevant (supported) change */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Remove old state, which will close vdisk and reset */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (mod_hash_destroy(vds->vd_table, (mod_hash_key_t)prev_id) != 0)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Re-initialize vdisk with new state */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (vds_init_vd(vds, curr_id, curr_dev, curr_ldc_id) != 0) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo vds_remove_vd(vds, md->removed.mdp, md->removed.mdep[i]);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo vds_change_vd(vds, md->match_prev.mdp, md->match_prev.mdep[i],
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * The "cfg-handle" property of a vds node in an MD contains the MD's
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * notion of "instance", or unique identifier, for that node; OBP
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * stores the value of the "cfg-handle" MD property as the value of
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * the "reg" property on the node in the device tree it builds from
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * the MD and passes to Solaris. Thus, we look up the devinfo node's
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * "reg" property value to uniquely identify this device instance when
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * registering with the MD event-generation framework. If the "reg"
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * property cannot be found, the device tree state is presumably so
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * broken that there is no point in continuing.
445b4c2ed2d52ef648ae6b36e4f5e14ff3d234afsb if (!ddi_prop_exists(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Get the MD instance for later MDEG registration */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo cfg_handle = ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (ddi_soft_state_zalloc(vds_state, instance) != DDI_SUCCESS) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo PRN("Could not allocate state for instance %u", instance);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((vds = ddi_get_soft_state(vds_state, instance)) == NULL) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo vds->vd_table = mod_hash_create_ptrhash("vds_vd_table", VDS_NCHAINS,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo sizeof (void *));
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((status = ldi_ident_from_dip(dip, &vds->ldi_ident)) != 0) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo PRN("ldi_ident_from_dip() returned errno %d", status);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Register for MD updates */
445b4c2ed2d52ef648ae6b36e4f5e14ff3d234afsb /* initialize the complete prop spec structure */
445b4c2ed2d52ef648ae6b36e4f5e14ff3d234afsb ispecp = kmem_zalloc(sizeof (mdeg_node_spec_t), KM_SLEEP);
445b4c2ed2d52ef648ae6b36e4f5e14ff3d234afsb if (mdeg_register(ispecp, &vd_match, vds_process_md, vds,
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm /* Prevent auto-detaching so driver is available whenever MD changes */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm if (ddi_prop_update_int(DDI_DEV_T_NONE, dip, DDI_NO_AUTODETACH, 1) !=
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo switch (cmd) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo 0, /* devo_refcnt */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo "virtual disk server v%I%",
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((status = ddi_soft_state_init(&vds_state, sizeof (vds_t), 1)) != 0)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Fill in the bit-mask of server-supported operations */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo for (i = 0; i < vds_noperations; i++)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo vds_operations |= 1 << (vds_operation[i].operation - 1);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0);