vds.c revision 78fcd0a1c10bb5a069d27365ac663157b8bac58b
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 */
eba0cb4e35a1289aa1f4240a208372b7c8505d40achartre/* Flags for writing to a vdisk which is a file */
87a7269eb068de448caa9e4404e38bebf4449531achartre/* Number of backup labels */
87a7269eb068de448caa9e4404e38bebf4449531achartre/* Timeout for SCSI I/O */
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/* Read disk label from a disk on file */
87a7269eb068de448caa9e4404e38bebf4449531achartre vd_file_rw(vd, VD_SLICE_NONE, VD_OP_BREAD, (caddr_t)labelp, \
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre 0, sizeof (struct dk_label))
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre/* Write disk label to a disk on file */
87a7269eb068de448caa9e4404e38bebf4449531achartre vd_file_rw(vd, VD_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 */
205eeb1ae627fcf67b5705c443a2b56a8263406blm int (*completef)(struct vd_task *task); /* completion func ptr */
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 */
eba0cb4e35a1289aa1f4240a208372b7c8505d40achartrestatic uint_t vd_file_write_flags = VD_FILE_WRITE_FLAGS;
87a7269eb068de448caa9e4404e38bebf4449531achartrestatic short vd_scsi_rdwr_timeout = VD_SCSI_RDWR_TIMEOUT;
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)
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartrestatic ushort_t vd_lbl2cksum(struct dk_label *label);
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,
87a7269eb068de448caa9e4404e38bebf4449531achartre * VD_SLICE_NONE indicates that the operation
87a7269eb068de448caa9e4404e38bebf4449531achartre * is done using an absolute disk offset.
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 */
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre PR0("Unknown disk label, can't do I/O from slice %d",
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre return (-1);
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 * 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);
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * Function:
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * vd_file_build_default_label
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * Description:
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * Return a default label for the given disk. This is used when the disk
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * does not have a valid VTOC so that the user can get a valid default
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * configuration. The default label have all slices size set to 0 (except
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * slice 2 which is the entire disk) to force the user to write a valid
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * label onto the disk image.
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * Parameters:
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * vd - disk on which the operation is performed.
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * label - the returned default label.
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * Return Code:
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartrevd_file_build_default_label(vd_t *vd, struct dk_label *label)
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * We must have a resonable number of cylinders and sectors so
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * that newfs can run using default values.
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * if (disk_size < 2MB)
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * phys_cylinders = disk_size / 100K
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * phys_cylinders = disk_size / 300K
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * phys_cylinders = (phys_cylinders == 0) ? 1 : phys_cylinders
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * alt_cylinders = (phys_cylinders > 2) ? 2 : 0;
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * data_cylinders = phys_cylinders - alt_cylinders
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * sectors = disk_size / (phys_cylinders * blk_size)
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * The file size test is an attempt to not have too few cylinders
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * for a small file, or so many on a big file that you waste space
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * for backup superblocks or cylinder group structures.
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre label->dkl_ncyl = label->dkl_pcyl - label->dkl_acyl;
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre PR0("requested disk size: %ld bytes\n", vd->file_size);
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre PR0("setup: ncyl=%d nhead=%d nsec=%d\n", label->dkl_pcyl,
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * We must have a correct label name otherwise format(1m) will
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * not recognized the disk as labeled.
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre (void) snprintf(label->dkl_asciilabel, LEN_DKL_ASCII,
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre "SUN-DiskImage-%ld%cB cyl %d alt %d hd %d sec %d",
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre label->dkl_ncyl, label->dkl_acyl, label->dkl_nhead,
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre /* default VTOC */
87a7269eb068de448caa9e4404e38bebf4449531achartre * Function:
87a7269eb068de448caa9e4404e38bebf4449531achartre * vd_file_set_vtoc
87a7269eb068de448caa9e4404e38bebf4449531achartre * Description:
87a7269eb068de448caa9e4404e38bebf4449531achartre * Set the vtoc of a disk image by writing the label and backup
87a7269eb068de448caa9e4404e38bebf4449531achartre * labels into the disk image backend.
87a7269eb068de448caa9e4404e38bebf4449531achartre * Parameters:
87a7269eb068de448caa9e4404e38bebf4449531achartre * vd - disk on which the operation is performed.
87a7269eb068de448caa9e4404e38bebf4449531achartre * label - the data to be written.
87a7269eb068de448caa9e4404e38bebf4449531achartre * Return Code:
87a7269eb068de448caa9e4404e38bebf4449531achartre * 0 - success.
87a7269eb068de448caa9e4404e38bebf4449531achartre * n > 0 - error, n indicates the errno code.
87a7269eb068de448caa9e4404e38bebf4449531achartre * Backup labels are on the last alternate cylinder's
87a7269eb068de448caa9e4404e38bebf4449531achartre * first five odd sectors.
87a7269eb068de448caa9e4404e38bebf4449531achartre PR0("no alternate cylinder, can not store backup labels");
87a7269eb068de448caa9e4404e38bebf4449531achartre return (0);
87a7269eb068de448caa9e4404e38bebf4449531achartre blk = (cyl * ((label->dkl_nhead * label->dkl_nsect) - label->dkl_apc)) +
87a7269eb068de448caa9e4404e38bebf4449531achartre * Write the backup labels. Make sure we don't try to write past
87a7269eb068de448caa9e4404e38bebf4449531achartre * the last cylinder.
87a7269eb068de448caa9e4404e38bebf4449531achartre PR0("not enough sector to store all backup labels");
87a7269eb068de448caa9e4404e38bebf4449531achartre return (0);
87a7269eb068de448caa9e4404e38bebf4449531achartre if (vd_file_rw(vd, VD_SLICE_NONE, VD_OP_BWRITE, (caddr_t)label,
87a7269eb068de448caa9e4404e38bebf4449531achartre PR1("wrote backup label at block %d\n", blk + sec);
87a7269eb068de448caa9e4404e38bebf4449531achartre return (0);
87a7269eb068de448caa9e4404e38bebf4449531achartre * Function:
87a7269eb068de448caa9e4404e38bebf4449531achartre * vd_file_get_devid_block
87a7269eb068de448caa9e4404e38bebf4449531achartre * Description:
87a7269eb068de448caa9e4404e38bebf4449531achartre * Return the block number where the device id is stored.
87a7269eb068de448caa9e4404e38bebf4449531achartre * Parameters:
87a7269eb068de448caa9e4404e38bebf4449531achartre * vd - disk on which the operation is performed.
87a7269eb068de448caa9e4404e38bebf4449531achartre * blkp - pointer to the block number
87a7269eb068de448caa9e4404e38bebf4449531achartre * Return Code:
87a7269eb068de448caa9e4404e38bebf4449531achartre * 0 - success
87a7269eb068de448caa9e4404e38bebf4449531achartre * ENOSPC - disk has no space to store a device id
87a7269eb068de448caa9e4404e38bebf4449531achartre /* this geometry doesn't allow us to have a devid */
87a7269eb068de448caa9e4404e38bebf4449531achartre PR0("not enough alternate cylinder available for devid "
87a7269eb068de448caa9e4404e38bebf4449531achartre /* the devid is in on the track next to the last cylinder */
87a7269eb068de448caa9e4404e38bebf4449531achartre cyl = vd->dk_geom.dkg_ncyl + vd->dk_geom.dkg_acyl - 2;
87a7269eb068de448caa9e4404e38bebf4449531achartre spc = vd->dk_geom.dkg_nhead * vd->dk_geom.dkg_nsect;
87a7269eb068de448caa9e4404e38bebf4449531achartre return (0);
87a7269eb068de448caa9e4404e38bebf4449531achartre * Return the checksum of a disk block containing an on-disk devid.
87a7269eb068de448caa9e4404e38bebf4449531achartre for (i = 0; i < ((DEV_BSIZE - sizeof (int)) / sizeof (int)); i++)
87a7269eb068de448caa9e4404e38bebf4449531achartre * Function:
87a7269eb068de448caa9e4404e38bebf4449531achartre * vd_file_read_devid
87a7269eb068de448caa9e4404e38bebf4449531achartre * Description:
87a7269eb068de448caa9e4404e38bebf4449531achartre * Read the device id stored on a disk image.
87a7269eb068de448caa9e4404e38bebf4449531achartre * Parameters:
87a7269eb068de448caa9e4404e38bebf4449531achartre * vd - disk on which the operation is performed.
87a7269eb068de448caa9e4404e38bebf4449531achartre * devid - the return address of the device ID.
87a7269eb068de448caa9e4404e38bebf4449531achartre * Return Code:
87a7269eb068de448caa9e4404e38bebf4449531achartre * 0 - success
87a7269eb068de448caa9e4404e38bebf4449531achartre * EIO - I/O error while trying to access the disk image
87a7269eb068de448caa9e4404e38bebf4449531achartre * EINVAL - no valid device id was found
87a7269eb068de448caa9e4404e38bebf4449531achartre * ENOSPC - disk has no space to store a device id
87a7269eb068de448caa9e4404e38bebf4449531achartre if ((status = vd_file_get_devid_block(vd, &blk)) != 0)
87a7269eb068de448caa9e4404e38bebf4449531achartre /* get the devid */
87a7269eb068de448caa9e4404e38bebf4449531achartre if ((vd_file_rw(vd, VD_SLICE_NONE, VD_OP_BREAD, (caddr_t)dkdevid, blk,
87a7269eb068de448caa9e4404e38bebf4449531achartre /* validate the revision */
87a7269eb068de448caa9e4404e38bebf4449531achartre PR0("invalid devid found at block %lu (bad revision)", blk);
87a7269eb068de448caa9e4404e38bebf4449531achartre /* compute checksum */
87a7269eb068de448caa9e4404e38bebf4449531achartre /* compare the checksums */
87a7269eb068de448caa9e4404e38bebf4449531achartre PR0("invalid devid found at block %lu (bad checksum)", blk);
87a7269eb068de448caa9e4404e38bebf4449531achartre /* validate the device id */
87a7269eb068de448caa9e4404e38bebf4449531achartre if (ddi_devid_valid((ddi_devid_t)&dkdevid->dkd_devid) != DDI_SUCCESS) {
87a7269eb068de448caa9e4404e38bebf4449531achartre sz = ddi_devid_sizeof((ddi_devid_t)&dkdevid->dkd_devid);
87a7269eb068de448caa9e4404e38bebf4449531achartre * Function:
87a7269eb068de448caa9e4404e38bebf4449531achartre * vd_file_write_devid
87a7269eb068de448caa9e4404e38bebf4449531achartre * Description:
87a7269eb068de448caa9e4404e38bebf4449531achartre * Write a device id into disk image.
87a7269eb068de448caa9e4404e38bebf4449531achartre * Parameters:
87a7269eb068de448caa9e4404e38bebf4449531achartre * vd - disk on which the operation is performed.
87a7269eb068de448caa9e4404e38bebf4449531achartre * devid - the device ID to store.
87a7269eb068de448caa9e4404e38bebf4449531achartre * Return Code:
87a7269eb068de448caa9e4404e38bebf4449531achartre * 0 - success
87a7269eb068de448caa9e4404e38bebf4449531achartre * EIO - I/O error while trying to access the disk image
87a7269eb068de448caa9e4404e38bebf4449531achartre * ENOSPC - disk has no space to store a device id
87a7269eb068de448caa9e4404e38bebf4449531achartre if ((status = vd_file_get_devid_block(vd, &blk)) != 0)
87a7269eb068de448caa9e4404e38bebf4449531achartre /* set revision */
87a7269eb068de448caa9e4404e38bebf4449531achartre /* copy devid */
87a7269eb068de448caa9e4404e38bebf4449531achartre bcopy(devid, &dkdevid->dkd_devid, ddi_devid_sizeof(devid));
87a7269eb068de448caa9e4404e38bebf4449531achartre /* compute checksum */
87a7269eb068de448caa9e4404e38bebf4449531achartre /* set checksum */
87a7269eb068de448caa9e4404e38bebf4449531achartre /* store the devid */
87a7269eb068de448caa9e4404e38bebf4449531achartre if ((status = vd_file_rw(vd, VD_SLICE_NONE, VD_OP_BWRITE,
87a7269eb068de448caa9e4404e38bebf4449531achartre * Function:
87a7269eb068de448caa9e4404e38bebf4449531achartre * vd_scsi_rdwr
87a7269eb068de448caa9e4404e38bebf4449531achartre * Description:
87a7269eb068de448caa9e4404e38bebf4449531achartre * Read or write to a SCSI disk using an absolute disk offset.
87a7269eb068de448caa9e4404e38bebf4449531achartre * Parameters:
87a7269eb068de448caa9e4404e38bebf4449531achartre * vd - disk on which the operation is performed.
87a7269eb068de448caa9e4404e38bebf4449531achartre * operation - operation to execute: read (VD_OP_BREAD) or
87a7269eb068de448caa9e4404e38bebf4449531achartre * write (VD_OP_BWRITE).
87a7269eb068de448caa9e4404e38bebf4449531achartre * data - buffer where data are read to or written from.
87a7269eb068de448caa9e4404e38bebf4449531achartre * blk - starting block for the operation.
87a7269eb068de448caa9e4404e38bebf4449531achartre * len - number of bytes to read or write.
87a7269eb068de448caa9e4404e38bebf4449531achartre * Return Code:
87a7269eb068de448caa9e4404e38bebf4449531achartre * 0 - success
87a7269eb068de448caa9e4404e38bebf4449531achartre * n != 0 - error.
87a7269eb068de448caa9e4404e38bebf4449531achartrevd_scsi_rdwr(vd_t *vd, int operation, caddr_t data, size_t blk, size_t len)
87a7269eb068de448caa9e4404e38bebf4449531achartre * Build and execute the uscsi ioctl. We build a group0, group1
87a7269eb068de448caa9e4404e38bebf4449531achartre * or group4 command as necessary, since some targets
87a7269eb068de448caa9e4404e38bebf4449531achartre * do not support group1 commands.
87a7269eb068de448caa9e4404e38bebf4449531achartre nsectors = (max_sectors < nblk) ? max_sectors : nblk;
87a7269eb068de448caa9e4404e38bebf4449531achartre * Set flags so that the command is isolated from normal
87a7269eb068de448caa9e4404e38bebf4449531achartre * commands and no error message is printed.
87a7269eb068de448caa9e4404e38bebf4449531achartre status = ldi_ioctl(vd->ldi_handle[VD_ENTIRE_DISK_SLICE],
87a7269eb068de448caa9e4404e38bebf4449531achartre USCSICMD, (intptr_t)&ucmd, (vd_open_flags | FKIOCTL),
87a7269eb068de448caa9e4404e38bebf4449531achartre * Check if partial DMA breakup is required. If so, reduce
87a7269eb068de448caa9e4404e38bebf4449531achartre * the request size by half and retry the last request.
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Return Values
205eeb1ae627fcf67b5705c443a2b56a8263406blm * EINPROGRESS - operation was successfully started
205eeb1ae627fcf67b5705c443a2b56a8263406blm * EIO - encountered LDC (aka. task error)
205eeb1ae627fcf67b5705c443a2b56a8263406blm * 0 - operation completed successfully
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Side Effect
205eeb1ae627fcf67b5705c443a2b56a8263406blm * sets request->status = <disk operation status>
87a7269eb068de448caa9e4404e38bebf4449531achartre ASSERT(slice == VD_SLICE_NONE || slice < vd->nslices);
205eeb1ae627fcf67b5705c443a2b56a8263406blm /* no service for trivial requests */
205eeb1ae627fcf67b5705c443a2b56a8263406blm return (0);
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan (request->operation == VD_OP_BREAD) ? "Read" : "Write",
87a7269eb068de448caa9e4404e38bebf4449531achartre buf->b_edev = (slice == VD_SLICE_NONE)? NODEV : vd->dev[slice];
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,
87a7269eb068de448caa9e4404e38bebf4449531achartre * This is not a disk image so it is a real disk. We
87a7269eb068de448caa9e4404e38bebf4449531achartre * assume that the underlying device driver supports
87a7269eb068de448caa9e4404e38bebf4449531achartre * USCSICMD ioctls. This is the case of all SCSI devices
87a7269eb068de448caa9e4404e38bebf4449531achartre * (sd, ssd...).
87a7269eb068de448caa9e4404e38bebf4449531achartre * In the future if we have non-SCSI disks we would need
87a7269eb068de448caa9e4404e38bebf4449531achartre * to invoke the appropriate function to do I/O using an
87a7269eb068de448caa9e4404e38bebf4449531achartre * absolute disk offset (for example using DKIOCTL_RWCMD
87a7269eb068de448caa9e4404e38bebf4449531achartre * for IDE disks).
87a7269eb068de448caa9e4404e38bebf4449531achartre if (rv != 0) {
205eeb1ae627fcf67b5705c443a2b56a8263406blm * This is to indicate to the caller that the request
205eeb1ae627fcf67b5705c443a2b56a8263406blm * needs to be finished by vd_complete_bio() by calling
205eeb1ae627fcf67b5705c443a2b56a8263406blm * biowait() there and waiting for that to return before
205eeb1ae627fcf67b5705c443a2b56a8263406blm * triggering the notification of the vDisk client.
205eeb1ae627fcf67b5705c443a2b56a8263406blm * This is necessary when writing to real disks as
205eeb1ae627fcf67b5705c443a2b56a8263406blm * otherwise calls to ldi_strategy() would be serialized
205eeb1ae627fcf67b5705c443a2b56a8263406blm * behind the calls to biowait() and performance would
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Clean up after error */
205eeb1ae627fcf67b5705c443a2b56a8263406blm * This function should only be called from vd_notify to ensure that requests
205eeb1ae627fcf67b5705c443a2b56a8263406blm * are responded to in the order that they are received.
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);
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Return Values
205eeb1ae627fcf67b5705c443a2b56a8263406blm * 0 - operation completed successfully
205eeb1ae627fcf67b5705c443a2b56a8263406blm * EIO - encountered LDC / task error
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Side Effect
205eeb1ae627fcf67b5705c443a2b56a8263406blm * sets request->status = <disk operation status>
205eeb1ae627fcf67b5705c443a2b56a8263406blm /* Wait for the I/O to complete [ call to ldi_strategy(9f) ] */
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",
205eeb1ae627fcf67b5705c443a2b56a8263406blm return (rv);
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Description:
205eeb1ae627fcf67b5705c443a2b56a8263406blm * This function is called by the two functions called by a taskq
205eeb1ae627fcf67b5705c443a2b56a8263406blm * [ vd_complete_notify() and vd_serial_notify()) ] to send the
205eeb1ae627fcf67b5705c443a2b56a8263406blm * message to the client.
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Parameters:
205eeb1ae627fcf67b5705c443a2b56a8263406blm * arg - opaque pointer to structure containing task to be completed
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Return Values
205eeb1ae627fcf67b5705c443a2b56a8263406blmstatic void
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Send the "ack" or "nack" back to the client; if sending the message
205eeb1ae627fcf67b5705c443a2b56a8263406blm * via LDC fails, arrange to reset both the connection state and LDC
205eeb1ae627fcf67b5705c443a2b56a8263406blm (task->msg->tag.vio_subtype == VIO_SUBTYPE_ACK) ? "ACK" : "NACK");
205eeb1ae627fcf67b5705c443a2b56a8263406blm status = send_msg(task->vd->ldc_handle, task->msg, task->msglen);
205eeb1ae627fcf67b5705c443a2b56a8263406blm switch (status) {
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Description:
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Mark the Dring entry as Done and (if necessary) send an ACK/NACK to
205eeb1ae627fcf67b5705c443a2b56a8263406blm * the vDisk client
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Parameters:
205eeb1ae627fcf67b5705c443a2b56a8263406blm * task - structure containing the request sent from client
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Return Values
205eeb1ae627fcf67b5705c443a2b56a8263406blmstatic void
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Update the dring element for a dring client */
205eeb1ae627fcf67b5705c443a2b56a8263406blm if (!vd->reset_state && (vd->xfer_mode == VIO_DRING_MODE)) {
205eeb1ae627fcf67b5705c443a2b56a8263406blm * If a transport error occurred while marking the element done or
205eeb1ae627fcf67b5705c443a2b56a8263406blm * previously while executing the task, arrange to "nack" the message
205eeb1ae627fcf67b5705c443a2b56a8263406blm * when 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
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Description:
205eeb1ae627fcf67b5705c443a2b56a8263406blm * This is the basic completion function called to handle inband data
205eeb1ae627fcf67b5705c443a2b56a8263406blm * requests and handshake messages. All it needs to do is trigger a
205eeb1ae627fcf67b5705c443a2b56a8263406blm * message to the client that the request is completed.
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Parameters:
205eeb1ae627fcf67b5705c443a2b56a8263406blm * arg - opaque pointer to structure containing task to be completed
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Return Values
205eeb1ae627fcf67b5705c443a2b56a8263406blmstatic void
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);
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartrevd_read_vtoc(ldi_handle_t handle, struct vtoc *vtoc)
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan status = ldi_ioctl(handle, DKIOCGVTOC, (intptr_t)vtoc,
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan status = vds_efi_alloc_and_read(handle, &efi, &efi_len);
3c96341aef2b4da56c902941f089284b52bd573fnarayan count = (sizeof (struct dk_label)) / (sizeof (short)) - 1;
3c96341aef2b4da56c902941f089284b52bd573fnarayan while (count--) {
87a7269eb068de448caa9e4404e38bebf4449531achartre * Handle ioctls to a disk slice.
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Return Values
205eeb1ae627fcf67b5705c443a2b56a8263406blm * 0 - Indicates that there are no errors in disk operations
205eeb1ae627fcf67b5705c443a2b56a8263406blm * ENOTSUP - Unknown disk label type or unsupported DKIO ioctl
205eeb1ae627fcf67b5705c443a2b56a8263406blm * EINVAL - Not enough room to copy the EFI label
4bac220845f606f60663ed6f3a2b88caa00ae87enarayanvd_do_slice_ioctl(vd_t *vd, int cmd, void *ioctl_arg)
87a7269eb068de448caa9e4404e38bebf4449531achartre /* ioctls for a slice from a disk with a VTOC label */
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan bcopy(&vd->dk_geom, ioctl_arg, sizeof (vd->dk_geom));
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan return (0);
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan return (0);
87a7269eb068de448caa9e4404e38bebf4449531achartre /* ioctls for a slice from a disk with an EFI label */
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan return (0);
205eeb1ae627fcf67b5705c443a2b56a8263406blm /* Unknown disk label type */
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * Function:
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * vd_file_validate_geometry
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * Description:
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * Read the label and validate the geometry of a disk image. The driver
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * label, vtoc and geometry information are updated according to the
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * label read from the disk image.
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * If no valid label is found, the label is set to unknown and the
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * function returns EINVAL, but a default vtoc and geometry are provided
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * to the driver.
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * Parameters:
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * vd - disk on which the operation is performed.
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * Return Code:
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * 0 - success.
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * EIO - error reading the label from the disk image.
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * EINVAL - unknown disk label.
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre /* Update the driver geometry */
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre geom->dkg_write_reinstruct = label.dkl_write_reinstruct;
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre geom->dkg_read_reinstruct = label.dkl_read_reinstruct;
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre /* Update the driver vtoc */
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre vtoc->v_part[i].p_size = label.dkl_map[i].dkl_nblk;
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * The bootinfo array can not be copied with bcopy() because
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * elements are of type long in vtoc (so 64-bit) and of type
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * int in dk_vtoc (so 32-bit).
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre vtoc->v_bootinfo[0] = label.dkl_vtoc.v_bootinfo[0];
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre vtoc->v_bootinfo[1] = label.dkl_vtoc.v_bootinfo[1];
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre vtoc->v_bootinfo[2] = label.dkl_vtoc.v_bootinfo[2];
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Handle ioctls to a disk image (file-based).
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Return Values
205eeb1ae627fcf67b5705c443a2b56a8263406blm * 0 - Indicates that there are no errors
205eeb1ae627fcf67b5705c443a2b56a8263406blm * != 0 - Disk operation returned an error
87a7269eb068de448caa9e4404e38bebf4449531achartrevd_do_file_ioctl(vd_t *vd, int cmd, void *ioctl_arg)
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre bcopy(&vd->dk_geom, geom, sizeof (struct dk_geom));
87a7269eb068de448caa9e4404e38bebf4449531achartre return (0);
87a7269eb068de448caa9e4404e38bebf4449531achartre return (0);
87a7269eb068de448caa9e4404e38bebf4449531achartre * The current device geometry is not updated, just the driver
87a7269eb068de448caa9e4404e38bebf4449531achartre * "notion" of it. The device geometry will be effectively
87a7269eb068de448caa9e4404e38bebf4449531achartre * updated when a label is written to the device during a next
87a7269eb068de448caa9e4404e38bebf4449531achartre * DKIOCSVTOC.
87a7269eb068de448caa9e4404e38bebf4449531achartre bcopy(ioctl_arg, &vd->dk_geom, sizeof (vd->dk_geom));
87a7269eb068de448caa9e4404e38bebf4449531achartre return (0);
87a7269eb068de448caa9e4404e38bebf4449531achartre label.dkl_write_reinstruct = vd->dk_geom.dkg_write_reinstruct;
87a7269eb068de448caa9e4404e38bebf4449531achartre label.dkl_read_reinstruct = vd->dk_geom.dkg_read_reinstruct;
87a7269eb068de448caa9e4404e38bebf4449531achartre for (i = 0; i < V_NUMPAR; i++) {
87a7269eb068de448caa9e4404e38bebf4449531achartre * The bootinfo array can not be copied with bcopy() because
87a7269eb068de448caa9e4404e38bebf4449531achartre * elements are of type long in vtoc (so 64-bit) and of type
87a7269eb068de448caa9e4404e38bebf4449531achartre * int in dk_vtoc (so 32-bit).
87a7269eb068de448caa9e4404e38bebf4449531achartre label.dkl_vtoc.v_bootinfo[0] = vtoc->v_bootinfo[0];
87a7269eb068de448caa9e4404e38bebf4449531achartre label.dkl_vtoc.v_bootinfo[1] = vtoc->v_bootinfo[1];
87a7269eb068de448caa9e4404e38bebf4449531achartre label.dkl_vtoc.v_bootinfo[2] = vtoc->v_bootinfo[2];
87a7269eb068de448caa9e4404e38bebf4449531achartre /* re-compute checksum */
87a7269eb068de448caa9e4404e38bebf4449531achartre /* write label to the disk image */
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre /* check the geometry and update the driver info */
87a7269eb068de448caa9e4404e38bebf4449531achartre * The disk geometry may have changed, so we need to write
87a7269eb068de448caa9e4404e38bebf4449531achartre * the devid (if there is one) so that it is stored at the
87a7269eb068de448caa9e4404e38bebf4449531achartre * right location.
87a7269eb068de448caa9e4404e38bebf4449531achartre return (0);
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Description:
205eeb1ae627fcf67b5705c443a2b56a8263406blm * This is the function that processes the ioctl requests (farming it
205eeb1ae627fcf67b5705c443a2b56a8263406blm * out to functions that handle slices, files or whole disks)
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Return Values
205eeb1ae627fcf67b5705c443a2b56a8263406blm * 0 - ioctl operation completed successfully
205eeb1ae627fcf67b5705c443a2b56a8263406blm * != 0 - The LDC error value encountered
205eeb1ae627fcf67b5705c443a2b56a8263406blm * (propagated back up the call stack as a task error)
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Side Effect
205eeb1ae627fcf67b5705c443a2b56a8263406blm * sets request->status to the return value of the ioctl function.
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()
87a7269eb068de448caa9e4404e38bebf4449531achartre } else if (vd->vdisk_type == VD_DISK_TYPE_SLICE && !vd->pseudo) {
205eeb1ae627fcf67b5705c443a2b56a8263406blm request->status = ldi_ioctl(vd->ldi_handle[request->slice],
205eeb1ae627fcf67b5705c443a2b56a8263406blm ioctl->cmd, (intptr_t)ioctl->arg, (vd_open_flags | FKIOCTL),
205eeb1ae627fcf67b5705c443a2b56a8263406blm if (rval != 0) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#endif /* DEBUG */
205eeb1ae627fcf67b5705c443a2b56a8263406blm PR0("ioctl(%s) = errno %d", ioctl->cmd_name, request->status);
205eeb1ae627fcf67b5705c443a2b56a8263406blm return (0);
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))
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Description:
205eeb1ae627fcf67b5705c443a2b56a8263406blm * This generic function is called by the task queue to complete
205eeb1ae627fcf67b5705c443a2b56a8263406blm * the processing of the tasks. The specific completion function
205eeb1ae627fcf67b5705c443a2b56a8263406blm * is passed in as a field in the task pointer.
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Parameters:
205eeb1ae627fcf67b5705c443a2b56a8263406blm * arg - opaque pointer to structure containing task to be completed
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Return Values
205eeb1ae627fcf67b5705c443a2b56a8263406blmstatic void
205eeb1ae627fcf67b5705c443a2b56a8263406blm PR0("%s: Error %d completing task", __func__, task->status);
205eeb1ae627fcf67b5705c443a2b56a8263406blm /* Now notify the vDisk client */
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 */
205eeb1ae627fcf67b5705c443a2b56a8263406blm return (0);
205eeb1ae627fcf67b5705c443a2b56a8263406blm return (0);
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
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Parameters:
205eeb1ae627fcf67b5705c443a2b56a8263406blm * task - structure containing the request sent from client
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Return Value
205eeb1ae627fcf67b5705c443a2b56a8263406blm * 0 - success
205eeb1ae627fcf67b5705c443a2b56a8263406blm * ENOTSUP - Unknown/Unsupported VD_OP_XXX operation
205eeb1ae627fcf67b5705c443a2b56a8263406blm * EINVAL - Invalid disk slice
205eeb1ae627fcf67b5705c443a2b56a8263406blm * != 0 - some other non-zero return value from start function
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Find the requested operation */
205eeb1ae627fcf67b5705c443a2b56a8263406blm for (i = 0; i < vds_noperations; i++) {
205eeb1ae627fcf67b5705c443a2b56a8263406blm /* all operations should have a start func */
7636cb21f250f0485ca6052ffadc80ace93e6358lm /* Range-check slice */
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Call the function pointer that starts the operation.
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Description:
205eeb1ae627fcf67b5705c443a2b56a8263406blm * This function is called by both the in-band and descriptor ring
205eeb1ae627fcf67b5705c443a2b56a8263406blm * message processing functions paths to actually execute the task
205eeb1ae627fcf67b5705c443a2b56a8263406blm * requested by the vDisk client. It in turn calls its worker
205eeb1ae627fcf67b5705c443a2b56a8263406blm * function, vd_do_process_task(), to carry our the request.
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Any transport errors (e.g. LDC errors, vDisk protocol errors) are
205eeb1ae627fcf67b5705c443a2b56a8263406blm * saved in the 'status' field of the task and are propagated back
205eeb1ae627fcf67b5705c443a2b56a8263406blm * up the call stack to trigger a NACK
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Any request errors (e.g. ENOTTY from an ioctl) are saved in
205eeb1ae627fcf67b5705c443a2b56a8263406blm * the 'status' field of the request and result in an ACK being sent
205eeb1ae627fcf67b5705c443a2b56a8263406blm * by the completion handler.
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Parameters:
205eeb1ae627fcf67b5705c443a2b56a8263406blm * task - structure containing the request sent from client
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Return Value
205eeb1ae627fcf67b5705c443a2b56a8263406blm * 0 - successful synchronous request.
205eeb1ae627fcf67b5705c443a2b56a8263406blm * != 0 - transport error (e.g. LDC errors, vDisk protocol)
205eeb1ae627fcf67b5705c443a2b56a8263406blm * EINPROGRESS - task will be finished in a completion handler
205eeb1ae627fcf67b5705c443a2b56a8263406blm * If the task processing function returned EINPROGRESS indicating
205eeb1ae627fcf67b5705c443a2b56a8263406blm * that the task needs completing then schedule a taskq entry to
205eeb1ae627fcf67b5705c443a2b56a8263406blm * finish it now.
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Otherwise the task processing function returned either zero
205eeb1ae627fcf67b5705c443a2b56a8263406blm * indicating that the task was finished in the start function (and we
205eeb1ae627fcf67b5705c443a2b56a8263406blm * don't need to wait in a completion function) or the start function
205eeb1ae627fcf67b5705c443a2b56a8263406blm * returned an error - in both cases all that needs to happen is the
205eeb1ae627fcf67b5705c443a2b56a8263406blm * notification to the vDisk client higher up the call stack.
205eeb1ae627fcf67b5705c443a2b56a8263406blm * If the task was using a Descriptor Ring, we need to mark it as done
205eeb1ae627fcf67b5705c443a2b56a8263406blm * at this stage.
205eeb1ae627fcf67b5705c443a2b56a8263406blm /* Queue a task to complete the operation */
205eeb1ae627fcf67b5705c443a2b56a8263406blm } else if (!vd->reset_state && (vd->xfer_mode == VIO_DRING_MODE)) {
205eeb1ae627fcf67b5705c443a2b56a8263406blm /* Update the dring element if it's a dring client */
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()
87a7269eb068de448caa9e4404e38bebf4449531achartre 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. */
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
87a7269eb068de448caa9e4404e38bebf4449531achartre vd_process_dring_reg_msg(vd, msg, msglen)) != ENOMSG)
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 */
205eeb1ae627fcf67b5705c443a2b56a8263406blm /* "transport" error will cause NACK of invalid messages */
205eeb1ae627fcf67b5705c443a2b56a8263406blm /* "transport" error will cause NACK of invalid messages */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* An LDC error probably occurred, so try resetting it */
205eeb1ae627fcf67b5705c443a2b56a8263406blm /* populate the task so we can dispatch it on the taskq */
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Queue a task to send the notification that the operation completed.
205eeb1ae627fcf67b5705c443a2b56a8263406blm * We need to ensure that requests are responded to in the correct
205eeb1ae627fcf67b5705c443a2b56a8263406blm * order and since the taskq is processed serially this ordering
205eeb1ae627fcf67b5705c443a2b56a8263406blm * is maintained.
205eeb1ae627fcf67b5705c443a2b56a8263406blm (void) ddi_taskq_dispatch(vd->completionq, vd_serial_notify,
205eeb1ae627fcf67b5705c443a2b56a8263406blm * To ensure handshake negotiations do not happen out of order, such
205eeb1ae627fcf67b5705c443a2b56a8263406blm * requests that come through this path should not be done in parallel
205eeb1ae627fcf67b5705c443a2b56a8263406blm * so we need to wait here until the response is sent to the client.
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);
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre (intptr_t)&vd->dk_geom, (vd_open_flags | FKIOCTL), kcred, &rval);
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre PRN("ldi_ioctl(DKIOCGEOM) returned errno %d for %s",
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre /* Initialize dk_geom structure for single-slice device */
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre PRN("%s geometry claims 0 sectors per track", device_path);
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre vd->dk_geom.dkg_ncyl = vd->vdisk_size / vd->dk_geom.dkg_nsect /
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre vd->dk_geom.dkg_pcyl = vd->dk_geom.dkg_ncyl + vd->dk_geom.dkg_acyl;
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre /* Initialize vtoc structure for single-slice device */
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre MIN(sizeof (VD_VOLUME_NAME), sizeof (vd->vtoc.v_volume)));
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre MIN(sizeof (VD_ASCIILABEL), sizeof (vd->vtoc.v_asciilabel)));
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre 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));
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre /* find and validate the geometry of the disk image */
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
87a7269eb068de448caa9e4404e38bebf4449531achartre /* Setup devid for the disk image */
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre /* a valid devid was found */
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre return (0);
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * There was an error while trying to read the devid.
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * So this disk image may have a devid but we are
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * unable to read it.
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre return (0);
87a7269eb068de448caa9e4404e38bebf4449531achartre * No valid device id was found so we create one. Note that a failure
87a7269eb068de448caa9e4404e38bebf4449531achartre * to create a device id is not fatal and does not prevent the disk
87a7269eb068de448caa9e4404e38bebf4449531achartre * image from being attached.
87a7269eb068de448caa9e4404e38bebf4449531achartre if (ddi_devid_init(vd->vds->dip, DEVID_FAB, NULL, 0,
87a7269eb068de448caa9e4404e38bebf4449531achartre return (0);
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * Write devid to the disk image. The devid is stored into the disk
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * image if we have a valid label; otherwise the devid will be stored
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * when the user writes a valid label.
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre if (vd_file_write_devid(vd, vd->file_devid) != 0) {
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 */
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre /* Verify backing device supports dk_cinfo */
87a7269eb068de448caa9e4404e38bebf4449531achartre (intptr_t)&dk_cinfo, (vd_open_flags | FKIOCTL), kcred,
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre vd->vdisk_label = vd_read_vtoc(vd->ldi_handle[0], &vd->vtoc);
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]),
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * Currently we only support exporting pseudo devices which
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * provide a valid disk label.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0); /* ...and we're done */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm /* If slice is entire-disk slice, initialize for full disk */
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre /* We can only export a slice if the disk has a valid label */
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre PRN("%s is a slice from a disk with an unknown disk label\n",
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm /* Otherwise, we have a non-entire slice of a device */
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre /* Slice from a disk with an EFI label */
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre /* Slice from a disk with a VTOC label */
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,
87a7269eb068de448caa9e4404e38bebf4449531achartre vds_destroy_vd, 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 */
205eeb1ae627fcf67b5705c443a2b56a8263406blm "virtual disk server",
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);