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
a2b1d4fbb85525bff34187316a8ac58745dc963dZach Kissel * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
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. */
047ba61eb972395c8952e47676eefbb616aceec3achartre#define VD_BLOCK_DEVICE_OPTS "vds-block-device-opts"
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* Virtual disk initialization flags */
87a7269eb068de448caa9e4404e38bebf4449531achartre/* Number of backup labels */
87a7269eb068de448caa9e4404e38bebf4449531achartre/* Timeout for SCSI I/O */
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * Default number of threads for the I/O queue. In many cases, we will not
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * receive more than 8 I/O requests at the same time. However there are
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * cases (for example during the OS installation) where we can have a lot
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * more (up to the limit of the DRing size).
edcc07547a39d6570197493a9836083bd6b2a197achartre/* Maximum number of logical partitions */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * By Solaris convention, slice/partition 2 represents the entire disk;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * unfortunately, this convention does not appear to be codified.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre/* Logical block address for EFI */
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China#define VD_EFI_DEV_SET(dev, vdsk, ioctl) \
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China VDSK_EFI_DEV_SET(dev, vdsk, ioctl, \
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China (vdsk)->vdisk_bsize, (vdsk)->vdisk_size)
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * Flags defining the behavior for flushing asynchronous writes used to
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * performed some write I/O requests.
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * The VD_AWFLUSH_IMMEDIATE enables immediate flushing of asynchronous
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * writes. This ensures that data are committed to the backend when the I/O
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * request reply is sent to the guest domain so this prevents any data to
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * be lost in case a service domain unexpectedly crashes.
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * The flag VD_AWFLUSH_DEFER indicates that flushing is deferred to another
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * thread while the request is immediatly marked as completed. In that case,
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * a guest domain can a receive a reply that its write request is completed
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * while data haven't been flushed to disk yet.
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * Flags VD_AWFLUSH_IMMEDIATE and VD_AWFLUSH_DEFER are mutually exclusive.
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre#define VD_AWFLUSH_IMMEDIATE 0x01 /* immediate flushing */
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre#define VD_AWFLUSH_DEFER 0x02 /* defer flushing */
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre#define VD_AWFLUSH_GROUP 0x04 /* group requests before flushing */
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre/* Driver types */
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre#define VDS_NUM_DRIVERS (sizeof (vds_driver_types) / sizeof (vd_driver_type_t))
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre vd_driver_t type; /* driver type (disk or volume) */
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * There is no reliable way to determine if a device is representing a disk
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * or a volume, especially with pseudo devices. So we maintain a list of well
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * known drivers and the type of device they represent (either a disk or a
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * The list can be extended by adding a "driver-type-list" entry in vds.conf
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * with the following syntax:
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * driver-type-list="<driver>:<type>", ... ,"<driver>:<type>";
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * <driver> is the name of a driver (limited to 64 characters)
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * <type> is either the string "disk" or "volume"
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * Invalid entries in "driver-type-list" will be ignored.
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * For example, the following line in vds.conf:
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * driver-type-list="foo:disk","bar:volume";
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * defines that "foo" is a disk driver, and driver "bar" is a volume driver.
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * When a list is defined in vds.conf, it is checked before the built-in list
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * (vds_driver_types[]) so that any definition from this list can be overriden
11f54b6e45feb2d8f72622727a377aa52baad4f9Alexandre Chartre { "dlmfdrv", VD_DRIVER_DISK }, /* Hitachi HDLM */
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" : \
f0ca1d9a12d54d304791bc74525e2010ca924726sb (((vd)->xfer_mode == VIO_DRING_MODE_V1_0) ? "dring client" : \
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo "unsupported client")))
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre/* Read disk label from a disk image */
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre vd_dskimg_rw(vd, VD_SLICE_NONE, VD_OP_BREAD, (caddr_t)labelp, \
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre 0, sizeof (struct dk_label))
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre/* Write disk label to a disk image */
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre#define VD_DSKIMG_LABEL_WRITE(vd, labelp) \
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre vd_dskimg_rw(vd, VD_SLICE_NONE, VD_OP_BWRITE, (caddr_t)labelp, \
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre 0, sizeof (struct dk_label))
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre/* Identify if a backend is a disk image */
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre#define VD_DSKIMG(vd) ((vd)->vdisk_type == VD_DISK_TYPE_DISK && \
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre/* Next index in a write queue */
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre ((((id) + 1) >= vd->dring_len)? 0 : (id) + 1)
2f5224ae5d04383463098ad866ccee0464ee6429achartre/* Message for disk access rights reset failure */
2f5224ae5d04383463098ad866ccee0464ee6429achartre "Fail to reset disk access rights for disk %s"
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",
047ba61eb972395c8952e47676eefbb616aceec3achartre * Options for the VD_BLOCK_DEVICE_OPTS property.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* Debugging macros */
3c96341aef2b4da56c902941f089284b52bd573fnarayan PR0("dst:%x op:%x st:%u nb:%lx addr:%lx ncook:%u\n", \
3af08d828975d7e2581b6829e0eecff14d87a483lm switch (state) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#else /* !DEBUG */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#endif /* DEBUG */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * Soft state structure for a vds instance
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 */
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre vd_driver_type_t *driver_types; /* extra driver types (from vds.conf) */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * Types of descriptor-processing tasks
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
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan vd_dring_payload_t *request; /* request task will perform */
205eeb1ae627fcf67b5705c443a2b56a8263406blm int (*completef)(struct vd_task *task); /* completion func ptr */
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre uint32_t write_index; /* index in the write_queue */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * Soft state structure for a virtual disk instance
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan ddi_taskq_t *startq; /* queue for I/O start tasks */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan ddi_taskq_t *completionq; /* queue for completion tasks */
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre uint32_t write_index; /* next write index */
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre buf_t **write_queue; /* queue for async writes */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo ldi_handle_t ldi_handle[V_NUMPAR]; /* LDI slice handles */
3c96341aef2b4da56c902941f089284b52bd573fnarayan char device_path[MAXPATHLEN + 1]; /* vdisk device */
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China size_t vdisk_bsize; /* blk size of the vdisk */
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan vd_disk_label_t vdisk_label; /* EFI or VTOC label */
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China size_t backend_bsize; /* blk size of backend device */
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China int vio_bshift; /* shift for blk convertion */
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre boolean_t zvol; /* is vDisk backed by a zvol */
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre size_t dskimg_size; /* size of disk image */
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre ddi_devid_t dskimg_devid; /* devid for disk image */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo struct dk_geom dk_geom; /* synthetic for slice type */
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty struct extvtoc vtoc; /* synthetic for slice type */
edcc07547a39d6570197493a9836083bd6b2a197achartre vd_slice_t slices[VD_MAXPART]; /* logical partitions */
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? */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Macros to manipulate the fake label (flabel) for single slice disks.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * If we fake a VTOC label then the fake label consists of only one block
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * containing the VTOC label (struct dk_label).
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * If we fake an EFI label then the fake label consists of a blank block
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * followed by a GPT (efi_gpt_t) and a GPE (efi_gpe_t).
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China#define VD_LABEL_VTOC_SIZE(lba) \
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China P2ROUNDUP(sizeof (struct dk_label), (lba))
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China#define VD_LABEL_EFI_SIZE(lba) \
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China P2ROUNDUP(2 * (lba) + sizeof (efi_gpe_t) * VD_MAXPART, \
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty ((struct dk_label *)(void *)((vd)->flabel))
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China#define VD_LABEL_EFI_GPT(vd, lba) \
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China ((efi_gpt_t *)(void *)((vd)->flabel + (lba)))
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China#define VD_LABEL_EFI_GPE(vd, lba) \
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China ((efi_gpe_t *)(void *)((vd)->flabel + 2 * (lba)))
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm /* convert input vd_buf to output ioctl_arg */
2f5224ae5d04383463098ad866ccee0464ee6429achartre int (*copyin)(void *vd_buf, size_t, void *ioctl_arg);
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm /* convert input ioctl_arg to output vd_buf */
047ba61eb972395c8952e47676eefbb616aceec3achartre /* write is true if the operation writes any data to the backend */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm/* Define trivial copyin/copyout conversion function flag */
2f5224ae5d04383463098ad866ccee0464ee6429achartre#define VD_IDENTITY_IN ((int (*)(void *, size_t, void *))-1)
2f5224ae5d04383463098ad866ccee0464ee6429achartre#define VD_IDENTITY_OUT ((void (*)(void *, void *))-1)
87a7269eb068de448caa9e4404e38bebf4449531achartrestatic short vd_scsi_rdwr_timeout = VD_SCSI_RDWR_TIMEOUT;
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * Number of threads in the taskq handling vdisk I/O. This can be set up to
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * the size of the DRing which is the maximum number of I/O we can receive
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * in parallel. Note that using a high number of threads can improve performance
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * but this is going to consume a lot of resources if there are many vdisks.
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartrestatic int vd_ioq_nthreads = VD_IOQ_NTHREADS;
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * Tunable to define the behavior for flushing asynchronous writes used to
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * performed some write I/O requests. The default behavior is to group as
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * much asynchronous writes as possible and to flush them immediatly.
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * If the tunable is set to 0 then explicit flushing is disabled. In that
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * case, data will be flushed by traditional mechanism (like fsflush) but
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * this might not happen immediatly.
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartrestatic int vd_awflush = VD_AWFLUSH_IMMEDIATE | VD_AWFLUSH_GROUP;
2f5224ae5d04383463098ad866ccee0464ee6429achartre * Tunable to define the behavior of the service domain if the vdisk server
2f5224ae5d04383463098ad866ccee0464ee6429achartre * fails to reset disk exclusive access when a LDC channel is reset. When a
2f5224ae5d04383463098ad866ccee0464ee6429achartre * LDC channel is reset the vdisk server will try to reset disk exclusive
2f5224ae5d04383463098ad866ccee0464ee6429achartre * access by releasing any SCSI-2 reservation or resetting the disk. If these
2f5224ae5d04383463098ad866ccee0464ee6429achartre * actions fail then the default behavior (vd_reset_access_failure = 0) is to
2f5224ae5d04383463098ad866ccee0464ee6429achartre * print a warning message. This default behavior can be changed by setting
2f5224ae5d04383463098ad866ccee0464ee6429achartre * the vd_reset_access_failure variable to A_REBOOT (= 0x1) and that will
2f5224ae5d04383463098ad866ccee0464ee6429achartre * cause the service domain to reboot, or A_DUMP (= 0x5) and that will cause
2f5224ae5d04383463098ad866ccee0464ee6429achartre * the service domain to panic. In both cases, the reset of the service domain
2f5224ae5d04383463098ad866ccee0464ee6429achartre * should trigger a reset SCSI buses and hopefully clear any SCSI-2 reservation.
2f5224ae5d04383463098ad866ccee0464ee6429achartre * Tunable for backward compatibility. When this variable is set to B_TRUE,
2f5224ae5d04383463098ad866ccee0464ee6429achartre * all disk volumes (ZFS, SVM, VxvM volumes) will be exported as single
2f5224ae5d04383463098ad866ccee0464ee6429achartre * slice disks whether or not they have the "slice" option set. This is
2f5224ae5d04383463098ad866ccee0464ee6429achartre * to provide a simple backward compatibility mechanism when upgrading
2f5224ae5d04383463098ad866ccee0464ee6429achartre * the vds driver and using a domain configuration created before the
2f5224ae5d04383463098ad866ccee0464ee6429achartre * "slice" option was available.
66cfcfbe1d432c3106a5faa9b07357f6ed2d4651achartre * The label of disk images created with some earlier versions of the virtual
66cfcfbe1d432c3106a5faa9b07357f6ed2d4651achartre * disk software is not entirely correct and have an incorrect v_sanity field
66cfcfbe1d432c3106a5faa9b07357f6ed2d4651achartre * (usually 0) instead of VTOC_SANE. This creates a compatibility problem with
66cfcfbe1d432c3106a5faa9b07357f6ed2d4651achartre * these images because we are now validating that the disk label (and the
66cfcfbe1d432c3106a5faa9b07357f6ed2d4651achartre * sanity) is correct when a disk image is opened.
66cfcfbe1d432c3106a5faa9b07357f6ed2d4651achartre * This tunable is set to false to not validate the sanity field and ensure
66cfcfbe1d432c3106a5faa9b07357f6ed2d4651achartre * compatibility. If the tunable is set to true, we will do a strict checking
66cfcfbe1d432c3106a5faa9b07357f6ed2d4651achartre * of the sanity but this can create compatibility problems with old disk
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartrestatic boolean_t vd_dskimg_validate_sanity = B_FALSE;
bbfa0259e68b6b625e9e085053d41d620f185eeeha * Enables the use of LDC_DIRECT_MAP when mapping in imported descriptor rings.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * When a backend is exported as a single-slice disk then we entirely fake
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * its disk label. So it can be exported either with a VTOC label or with
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * an EFI label. If vd_slice_label is set to VD_DISK_LABEL_VTOC then all
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * single-slice disks will be exported with a VTOC label; and if it is set
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * to VD_DISK_LABEL_EFI then all single-slice disks will be exported with
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * an EFI label.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * If vd_slice_label is set to VD_DISK_LABEL_UNK and the backend is a disk
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * or volume device then it will be exported with the same type of label as
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * defined on the device. Otherwise if the backend is a file then it will
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * exported with the disk label type set in the vd_file_slice_label variable.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Note that if the backend size is greater than 1TB then it will always be
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * exported with an EFI label no matter what the setting is.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartrestatic vd_disk_label_t vd_slice_label = VD_DISK_LABEL_UNK;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartrestatic vd_disk_label_t vd_file_slice_label = VD_DISK_LABEL_VTOC;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Tunable for backward compatibility. If this variable is set to B_TRUE then
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * single-slice disks are exported as disks with only one slice instead of
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * faking a complete disk partitioning.
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);
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartrestatic int vd_dskimg_validate_geometry(vd_t *vd);
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartrestatic boolean_t vd_dskimg_is_iso_image(vd_t *vd);
edcc07547a39d6570197493a9836083bd6b2a197achartrestatic int vd_backend_ioctl(vd_t *vd, int cmd, caddr_t arg);
edcc07547a39d6570197493a9836083bd6b2a197achartrestatic int vds_efi_alloc_and_read(vd_t *, efi_gpt_t **, efi_gpe_t **);
edcc07547a39d6570197493a9836083bd6b2a197achartrestatic void vds_efi_free(vd_t *, efi_gpt_t *, efi_gpe_t *);
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsettystatic void vd_vtocgeom_to_label(struct extvtoc *vtoc, struct dk_geom *geom,
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsettystatic void vd_label_to_vtocgeom(struct dk_label *label, struct extvtoc *vtoc,
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartrestatic boolean_t vd_slice_geom_isvalid(vd_t *vd, struct dk_geom *geom);
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsettystatic boolean_t vd_slice_vtoc_isvalid(vd_t *vd, struct extvtoc *vtoc);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Function:
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * vd_get_readable_size
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Description:
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Convert a given size in bytes to a human readable format in
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * kilobytes, megabytes, gigabytes or terabytes.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Parameters:
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * full_size - the size to convert in bytes.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * size - the converted size.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * unit - the unit of the converted size: 'K' (kilobyte),
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * 'M' (Megabyte), 'G' (Gigabyte), 'T' (Terabyte).
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Return Code:
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartrevd_get_readable_size(size_t full_size, size_t *size, char *unit)
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * Function:
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * vd_dskimg_io_params
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * Description:
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * Convert virtual disk I/O parameters (slice, block, length) to
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * (offset, length) relative to the disk image and according to
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * the virtual disk partitioning.
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * Parameters:
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * vd - disk on which the operation is performed.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * slice - slice to which is the I/O parameters apply.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * VD_SLICE_NONE indicates that parameters are
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * are relative to the entire virtual disk.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * blkp - pointer to the starting block relative to the
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * slice; return the starting block relative to
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * the disk image.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * lenp - pointer to the number of bytes requested; return
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * the number of bytes that can effectively be used.
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre * Return Code:
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * 0 - I/O parameters have been successfully converted;
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * blkp and lenp point to the converted values.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * ENODATA - no data are available for the given I/O parameters;
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * This occurs if the starting block is past the limit
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * of the slice.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * EINVAL - I/O parameters are invalid.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartrevd_dskimg_io_params(vd_t *vd, int slice, size_t *blkp, size_t *lenp)
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China ASSERT(vd->vdisk_bsize == DEV_BSIZE);
047ba61eb972395c8952e47676eefbb616aceec3achartre * If a file is exported as a slice then we don't care about the vtoc.
047ba61eb972395c8952e47676eefbb616aceec3achartre * In that case, the vtoc is a fake mainly to make newfs happy and we
047ba61eb972395c8952e47676eefbb616aceec3achartre * handle any I/O as a raw disk access so that we can have access to the
047ba61eb972395c8952e47676eefbb616aceec3achartre * entire backend.
047ba61eb972395c8952e47676eefbb616aceec3achartre if (vd->vdisk_type == VD_DISK_TYPE_SLICE || slice == VD_SLICE_NONE) {
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre /* raw disk access */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* offset past the end of the disk */
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * v1.0 vDisk clients depended on the server not verifying
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * the label of a unformatted disk. This "feature" is
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * maintained for backward compatibility but all versions
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * from v1.1 onwards must do the right thing.
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre /* address past the end of the slice */
edcc07547a39d6570197493a9836083bd6b2a197achartre offset = (vd->slices[slice].start + blk) * DEV_BSIZE;
edcc07547a39d6570197493a9836083bd6b2a197achartre maxlen = (vd->slices[slice].nblocks - blk) * DEV_BSIZE;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * If the requested size is greater than the size
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * of the partition, truncate the read/write.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre 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.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre "dskimg_size (0x%lx)", offset, len, vd->dskimg_size);
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * vd_dskimg_rw
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * Description:
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * Read or write to a disk image. It handles the case where the disk
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * image is a file or a volume exported as a full disk or a file
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * exported as single-slice disk. Read or write to volumes exported as
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * single slice disks are done by directly using the ldi interface.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * vd - disk on which the operation is performed.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * slice - slice on which the operation is performed,
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * VD_SLICE_NONE indicates that the operation
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * is done using an absolute disk offset.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * operation - operation to execute: read (VD_OP_BREAD) or
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * write (VD_OP_BWRITE).
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * data - buffer where data are read to or written from.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * blk - starting block for the operation.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * len - number of bytes to read or write.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * Return Code:
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * n >= 0 - success, n indicates the number of bytes read
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartrevd_dskimg_rw(vd_t *vd, int slice, int operation, caddr_t data, size_t offset,
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China ASSERT(vd->vdisk_bsize == DEV_BSIZE);
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre if ((status = vd_dskimg_io_params(vd, slice, &offset, &len)) != 0)
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre ((operation == VD_OP_BREAD)? B_READ : B_WRITE);
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * We use ldi_strategy() and not ldi_read()/ldi_write() because
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * the read/write functions of the underlying driver may try to
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * lock pages of the data buffer, and this requires the data
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * buffer to be kmem_alloc'ed (and not allocated on the stack).
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * Also using ldi_strategy() ensures that writes are immediatly
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * commited and not cached as this may be the case with
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * ldi_write() (for example with a ZFS volume).
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre if (ldi_strategy(vd->ldi_handle[0], &buf) != 0) {
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre status = vn_rdwr((operation == VD_OP_BREAD)? UIO_READ : UIO_WRITE,
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre vd->file_vnode, data, len, offset * DEV_BSIZE, UIO_SYSSPACE, FSYNC,
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * Function:
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * vd_build_default_label
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * Description:
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Return a default label for a given disk size. This is used when the disk
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * does not have a valid VTOC so that the user can get a valid default
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * configuration. The default label has all slice sizes 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:
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * disk_size - the disk size in bytes
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * bsize - the disk block size in bytes
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * label - the returned default label.
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * Return Code:
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing Chinavd_build_default_label(size_t disk_size, size_t bsize, struct dk_label *label)
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * Ideally we would like the cylinder size (nsect * nhead) to be the
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * same whatever the disk size is. That way the VTOC label could be
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * easily updated in case the disk size is increased (keeping the
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * same cylinder size allows to preserve the existing partitioning
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * when updating the VTOC label). But it is not possible to have
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * a fixed cylinder size and to cover all disk size.
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * So we define different cylinder sizes depending on the disk size.
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * The cylinder size is chosen so that we don't have too few cylinders
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * for a small disk image, or so many on a big disk image that you
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * waste space for backup superblocks or cylinder group structures.
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * Also we must have a resonable number of cylinders and sectors so
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * that newfs can run using default values.
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * +-----------+--------+---------+--------+
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * | disk_size | < 2MB | 2MB-4GB | >= 8GB |
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * +-----------+--------+---------+--------+
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * | nhead | 1 | 1 | 96 |
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * | nsect | 200 | 600 | 768 |
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * +-----------+--------+---------+--------+
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * Other parameters are computed from these values:
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * pcyl = disk_size / (nhead * nsect * 512)
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * acyl = (pcyl > 2)? 2 : 0
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * ncyl = pcyl - acyl
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * The maximum number of cylinder is 65535 so this allows to define a
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * geometry for a disk size up to 65535 * 96 * 768 * 512 = 2.24 TB
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * which is more than enough to cover the maximum size allowed by the
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * extended VTOC format (2TB).
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty } else if (disk_size >= 2 * ONE_MEGABYTE) {
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China (label->dkl_nsect * label->dkl_nhead * bsize);
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre label->dkl_ncyl = label->dkl_pcyl - label->dkl_acyl;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre PR0("requested disk size: %ld bytes\n", disk_size);
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre PR0("setup: ncyl=%d nhead=%d nsec=%d\n", label->dkl_pcyl,
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China label->dkl_nsect * bsize));
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 */
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty label->dkl_vtoc.v_version = V_EXTVERSION;
edcc07547a39d6570197493a9836083bd6b2a197achartre label->dkl_vtoc.v_part[VD_ENTIRE_DISK_SLICE].p_tag = V_BACKUP;
edcc07547a39d6570197493a9836083bd6b2a197achartre label->dkl_map[VD_ENTIRE_DISK_SLICE].dkl_cylno = 0;
edcc07547a39d6570197493a9836083bd6b2a197achartre label->dkl_map[VD_ENTIRE_DISK_SLICE].dkl_nblk = label->dkl_ncyl *
87a7269eb068de448caa9e4404e38bebf4449531achartre * Function:
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * vd_dskimg_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.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartrevd_dskimg_set_vtoc(vd_t *vd, struct dk_label *label)
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre if (VD_DSKIMG_LABEL_WRITE(vd, label) < 0) {
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.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre for (cnt = 0; cnt < VD_DSKIMG_NUM_BACKUP; cnt++) {
87a7269eb068de448caa9e4404e38bebf4449531achartre PR0("not enough sector to store all backup labels");
87a7269eb068de448caa9e4404e38bebf4449531achartre return (0);
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre if (vd_dskimg_rw(vd, VD_SLICE_NONE, VD_OP_BWRITE,
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre (caddr_t)label, blk + sec, sizeof (struct dk_label)) < 0) {
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty PR0("error writing backup label at block %lu\n",
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty PR1("wrote backup label at block %lu\n", blk + sec);
87a7269eb068de448caa9e4404e38bebf4449531achartre return (0);
87a7269eb068de448caa9e4404e38bebf4449531achartre * Function:
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * vd_dskimg_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
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartrevd_dskimg_get_devid_block(vd_t *vd, size_t *blkp)
edcc07547a39d6570197493a9836083bd6b2a197achartre * If no label is defined we don't know where to find
edcc07547a39d6570197493a9836083bd6b2a197achartre * a device id.
edcc07547a39d6570197493a9836083bd6b2a197achartre * For an EFI disk, the devid is at the beginning of
edcc07547a39d6570197493a9836083bd6b2a197achartre * the reserved slice
edcc07547a39d6570197493a9836083bd6b2a197achartre return (0);
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:
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * vd_dskimg_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
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartrevd_dskimg_read_devid(vd_t *vd, ddi_devid_t *devid)
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China ASSERT(vd->vdisk_bsize == DEV_BSIZE);
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre if ((status = vd_dskimg_get_devid_block(vd, &blk)) != 0)
87a7269eb068de448caa9e4404e38bebf4449531achartre /* get the devid */
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre if ((vd_dskimg_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:
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * vd_dskimg_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
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartrevd_dskimg_write_devid(vd_t *vd, ddi_devid_t devid)
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China ASSERT(vd->vdisk_bsize == DEV_BSIZE);
edcc07547a39d6570197493a9836083bd6b2a197achartre /* nothing to write */
edcc07547a39d6570197493a9836083bd6b2a197achartre return (0);
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre if ((status = vd_dskimg_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 */
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre if ((status = vd_dskimg_rw(vd, VD_SLICE_NONE, VD_OP_BWRITE,
87a7269eb068de448caa9e4404e38bebf4449531achartre * Function:
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * vd_do_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.
17cadca83cc82e37ff517ea2783eb4bfcc07b950lmvd_do_scsi_rdwr(vd_t *vd, int operation, caddr_t data, size_t blk, size_t len)
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China ASSERT(vd->vdisk_bsize > 0);
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China nblk = (len / vd->vdisk_bsize);
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China if (len % vd->vdisk_bsize != 0)
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;
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * Some of the optical drives on sun4v machines are ATAPI
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * devices which use Group 1 Read/Write commands so we need
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * to explicitly check a flag which is set when a domain
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * is bound.
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm if (blk < (2 << 20) && nsectors <= 0xff && !vd->is_atapi_dev) {
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China ucmd.uscsi_buflen = nsectors * vd->backend_bsize;
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],
047ba61eb972395c8952e47676eefbb616aceec3achartre 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.
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China data += nsectors * vd->vdisk_bsize;
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * Function:
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * vd_scsi_rdwr
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * Description:
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * Wrapper function to read or write to a SCSI disk using an absolute
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * disk offset. It checks the blocksize of the underlying device and,
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * if necessary, adjusts the buffers accordingly before calling
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * vd_do_scsi_rdwr() to do the actual read or write.
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * Parameters:
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * vd - disk on which the operation is performed.
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * operation - operation to execute: read (VD_OP_BREAD) or
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * write (VD_OP_BWRITE).
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * data - buffer where data are read to or written from.
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * blk - starting block for the operation.
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * len - number of bytes to read or write.
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * Return Code:
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * 0 - success
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * n != 0 - error.
17cadca83cc82e37ff517ea2783eb4bfcc07b950lmvd_scsi_rdwr(vd_t *vd, int operation, caddr_t data, size_t vblk, size_t vlen)
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm size_t pblk; /* physical device block number of data on device */
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm size_t delta; /* relative offset between pblk and vblk */
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm size_t pnblk; /* number of physical blocks to be read from device */
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm size_t plen; /* length of data to be read from physical device */
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm char *buf; /* buffer area to fit physical device's block size */
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China if (vd->backend_bsize == 0) {
2f5224ae5d04383463098ad866ccee0464ee6429achartre * The block size was not available during the attach,
2f5224ae5d04383463098ad866ccee0464ee6429achartre * try to update it now.
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * If the vdisk block size and the block size of the underlying device
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * match we can skip straight to vd_do_scsi_rdwr(), otherwise we need
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * to create a buffer large enough to handle the device's block size
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * and adjust the block to be read from and the amount of data to
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * read to correspond with the device's block size.
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China if (vd->vdisk_bsize == vd->backend_bsize)
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm return (vd_do_scsi_rdwr(vd, operation, data, vblk, vlen));
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China if (vd->vdisk_bsize > vd->backend_bsize)
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * Writing of physical block sizes larger than the virtual block size
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * is not supported. This would be added if/when support for guests
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * writing to DVDs is implemented.
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm /* BEGIN CSTYLED */
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * Below is a diagram showing the relationship between the physical
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * and virtual blocks. If the virtual blocks marked by 'X' below are
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * requested, then the physical blocks denoted by 'Y' are read.
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * |<--------------->|
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * --+--+--+--+--+--+--+--+--+--+--+--+--+--+--+- virtual disk:
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * | | | |XX|XX|XX|XX|XX|XX| | | | | | } block size is
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * --+--+--+--+--+--+--+--+--+--+--+--+--+--+--+- vd->vdisk_bsize
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * >:==:< delta : :
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * --+-----+-----+-----+-----+-----+-----+-----+-- physical disk:
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * | |YY:YY|YYYYY|YYYYY|YY:YY| | | } block size is
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * --+-----+-----+-----+-----+-----+-----+-----+-- vd->backend_bsize
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * |<--------------------->|
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm /* END CSTYLED */
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China pblk = (vblk * vd->vdisk_bsize) / vd->backend_bsize;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China delta = (vblk * vd->vdisk_bsize) - (pblk * vd->backend_bsize);
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China pnblk = ((delta + vlen - 1) / vd->backend_bsize) + 1;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China plen = pnblk * vd->backend_bsize;
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm PR2("vblk %lx:pblk %lx: vlen %ld:plen %ld", vblk, pblk, vlen, plen);
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm rv = vd_do_scsi_rdwr(vd, operation, (caddr_t)buf, pblk, plen);
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm return (rv);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Function:
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * vd_slice_flabel_read
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Description:
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * This function simulates a read operation from the fake label of
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * a single-slice disk.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Parameters:
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * vd - single-slice disk to read from
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * data - buffer where data should be read to
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * offset - offset in byte where the read should start
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * length - number of bytes to read
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Return Code:
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * n >= 0 - success, n indicates the number of bytes read
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * -1 - error
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartrevd_slice_flabel_read(vd_t *vd, caddr_t data, size_t offset, size_t length)
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China uint_t limit = vd->flabel_limit * vd->vdisk_bsize;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* if offset is past the fake label limit there's nothing to read */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre return (0);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* data with offset 0 to flabel_size are read from flabel */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* data with offset from flabel_size to flabel_limit are all zeros */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Function:
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * vd_slice_flabel_write
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Description:
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * This function simulates a write operation to the fake label of
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * a single-slice disk. Write operations are actually faked and return
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * success although the label is never changed. This is mostly to
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * simulate a successful label update.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Parameters:
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * vd - single-slice disk to write to
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * data - buffer where data should be written from
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * offset - offset in byte where the write should start
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * length - number of bytes to written
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Return Code:
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * n >= 0 - success, n indicates the number of bytes written
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * -1 - error
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartrevd_slice_flabel_write(vd_t *vd, caddr_t data, size_t offset, size_t length)
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China uint_t limit = vd->flabel_limit * vd->vdisk_bsize;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre return (0);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * If this is a request to overwrite the VTOC disk label, check that
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * the new label is similar to the previous one and return that the
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * write was successful, but note that nothing is actually overwritten.
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China offset == 0 && length == vd->vdisk_bsize) {
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* check that this is a valid label */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre return (-1);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* check the vtoc and geometry */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* fail any other write */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre return (-1);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Function:
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * vd_slice_fake_rdwr
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Description:
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * This function simulates a raw read or write operation to a single-slice
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * disk. It only handles the faked part of the operation i.e. I/Os to
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * blocks which have no mapping with the vdisk backend (I/Os to the
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * beginning and to the end of the vdisk).
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * The function returns 0 is the operation is completed and it has been
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * entirely handled as a fake read or write. In that case, lengthp points
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * to the number of bytes not read or written. Values returned by datap
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * and blkp are undefined.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * If the fake operation has succeeded but the read or write is not
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * complete (i.e. the read/write operation extends beyond the blocks
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * we fake) then the function returns EAGAIN and datap, blkp and lengthp
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * pointers points to the parameters for completing the operation.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * In case of an error, for example if the slice is empty or parameters
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * are invalid, then the function returns a non-zero value different
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * from EAGAIN. In that case, the returned values of datap, blkp and
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * lengthp are undefined.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Parameters:
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * vd - single-slice disk on which the operation is performed
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * slice - slice on which the operation is performed,
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * VD_SLICE_NONE indicates that the operation
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * is done using an absolute disk offset.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * operation - operation to execute: read (VD_OP_BREAD) or
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * write (VD_OP_BWRITE).
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * datap - pointer to the buffer where data are read to
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * or written from. Return the pointer where remaining
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * data have to be read to or written from.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * blkp - pointer to the starting block for the operation.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Return the starting block relative to the vdisk
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * backend for the remaining operation.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * lengthp - pointer to the number of bytes to read or write.
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * This should be a multiple of vdisk_bsize. Return the
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * remaining number of bytes to read or write.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Return Code:
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * 0 - read/write operation is completed
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * EAGAIN - read/write operation is not completed
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * other values - error
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartrevd_slice_fake_rdwr(vd_t *vd, int slice, int operation, caddr_t *datap,
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China size_t bsize = vd->vdisk_bsize;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * If this is not a raw I/O or an I/O from a full disk slice then
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * this is an I/O to/from an empty slice.
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China if (length % bsize != 0)
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* handle any I/O with the fake label */
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China n = vd_slice_flabel_write(vd, data, blk * bsize, length);
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China n = vd_slice_flabel_read(vd, data, blk * bsize, length);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre if (n == -1)
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China ASSERT(n % bsize == 0);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* adjust I/O arguments */
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China blk += n / bsize;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* check if there's something else to process */
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China asize = EFI_MIN_RESV_SIZE + (EFI_MIN_ARRAY_SIZE / bsize) + 1;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre csize = vd->dk_geom.dkg_nhead * vd->dk_geom.dkg_nsect;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China alen = length / bsize;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* if we have reached the last block then the I/O is completed */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* if we are past the last block then return an error */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* check if there is any I/O to end of the disk */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* we don't allow any write to the end of the disk */
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China alen *= bsize;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China bzero(data + (aoff - blk) * bsize, alen);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* check if we read backup labels */
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China ablk + sec < blk + (length / bsize)) {
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China (ablk + sec - blk) * bsize,
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre sizeof (struct dk_label));
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Return the parameters for the remaining I/O. The starting block is
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * adjusted so that it is relative to the vdisk backend.
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre status = VOP_FSYNC(vd->file_vnode, FSYNC, kcred, NULL);
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre status = ldi_ioctl(vd->ldi_handle[0], DKIOCFLUSHWRITECACHE,
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre NULL, vd->open_flags | FKIOCTL, kcred, &rval);
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre vd_task_t *task = (vd_task_t *)buf->b_private;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China ASSERT(vd->vdisk_bsize == DEV_BSIZE);
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre status = ldi_strategy(vd->ldi_handle[0], buf);
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre status = vn_rdwr((buf->b_flags & B_READ)? UIO_READ : UIO_WRITE,
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre vd->file_vnode, buf->b_un.b_addr, buf->b_bcount,
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre buf->b_lblkno * DEV_BSIZE, UIO_SYSSPACE, 0,
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * We define our own biodone function so that buffers used for
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * asynchronous writes are not released when biodone() is called.
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",
047ba61eb972395c8952e47676eefbb616aceec3achartre * We have to check the open flags because the functions processing
047ba61eb972395c8952e47676eefbb616aceec3achartre * the read/write request will not do it.
047ba61eb972395c8952e47676eefbb616aceec3achartre if (request->operation == VD_OP_BWRITE && !(vd->open_flags & FWRITE)) {
047ba61eb972395c8952e47676eefbb616aceec3achartre PR0("write fails because backend is opened read-only");
047ba61eb972395c8952e47676eefbb616aceec3achartre return (0);
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,
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * The buffer size has to be 8-byte aligned, so the client should have
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * sent a buffer which size is roundup to the next 8-byte aligned value.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* default number of byte returned by the I/O */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* handle any fake I/O */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre rv = vd_slice_fake_rdwr(vd, slice, request->operation,
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* record the number of bytes from the fake I/O */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre if (rv == 0) {
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * If we return with EAGAIN then this means that there
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * are still data to read or write.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * We need to continue the I/O from the slice backend to
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * complete the request. The variables bufaddr, offset
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * and length have been adjusted to have the right
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * information to do the remaining I/O from the backend.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * The backend is entirely mapped to slice 0 so we just
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * have to complete the I/O from that slice.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre rv = vd_dskimg_io_params(vd, slice, &offset, &length);
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre request->status = (rv == ENODATA)? 0: EIO;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * This is not a disk image so it is a real disk. We
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * assume that the underlying device driver supports
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * USCSICMD ioctls. This is the case of all SCSI devices
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * (sd, ssd...).
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * In the future if we have non-SCSI disks we would need
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * to invoke the appropriate function to do I/O using an
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * absolute disk offset (for example using DIOCTL_RWCMD
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * for IDE disks).
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre rv = vd_scsi_rdwr(vd, request->operation, bufaddr, offset,
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre if (rv != 0) {
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan /* Start the block I/O */
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * I/O to a file are dispatched to an I/O queue, so that several
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * I/Os can be processed in parallel. We also do that for ZFS
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * volumes because the ZFS volume strategy() function will only
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * return after the I/O is completed (instead of just starting
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * For ZFS volumes and files, we do an asynchronous
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * write and we will wait for the completion of the
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * write in vd_complete_bio() by flushing the volume
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * This done for performance reasons, so that we can
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * group together several write requests into a single
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * flush operation.
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * We keep track of the write so that we can group
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * requests when flushing. The write queue has the
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * same number of slots as the dring so this prevents
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * the write queue from wrapping and overwriting
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * existing entries: if the write queue gets full
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * then that means that the dring is full so we stop
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * receiving new requests until an existing request
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * is processed, removed from the write queue and
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * then from the dring.
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre (void) ddi_taskq_dispatch(task->vd->ioq, vd_bio_task, buf,
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China /* convert VIO block number to buf block number */
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China buf->b_lblkno = offset << vd->vio_bshift;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre request->status = ldi_strategy(vd->ldi_handle[slice], buf);
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * This is to indicate to the caller that the request
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * needs to be finished by vd_complete_bio() by calling
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * biowait() there and waiting for that to return before
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * triggering the notification of the vDisk client.
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * This is necessary when writing to real disks as
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * otherwise calls to ldi_strategy() would be serialized
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * behind the calls to biowait() and performance would
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* Clean up after error or completion */
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
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre PR0("flushwrite returned error %d", status);
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))
2f5224ae5d04383463098ad866ccee0464ee6429achartre /* Reset exclusive access rights */
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 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 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>
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * If the I/O is already done then we don't call biowait()
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * because biowait() might already have been called when
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * flushing a previous asynchronous write. So we just
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * retrieve the status of the request.
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * Wait for the I/O. For synchronous I/O, biowait() will return
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * when the I/O has completed. For asynchronous write, it will
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * return the write has been submitted to the backend, but it
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * may not have been committed.
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * Asynchronous writes are used when writing to a file or a
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * ZFS volume. In that case the bio notification indicates
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * that the write has started. We have to flush the backend
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * to ensure that the write has been committed before marking
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * the request as completed.
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre ASSERT(task->request->operation == VD_OP_BWRITE);
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre /* check if write has been already flushed */
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * Because flushing is time consuming, it is worth
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * waiting for any other writes so that they can be
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * included in this single flush request.
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre DTRACE_PROBE2(flushgrp, vd_task_t *, task,
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre } else if (vd_awflush & VD_AWFLUSH_DEFER) {
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* Update the number of bytes read/written */
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan /* Release the buffer */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre status = ldc_mem_release(task->mhdl, 0, buf->b_bufsize);
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 */
f0ca1d9a12d54d304791bc74525e2010ca924726sb if (!vd->reset_state && (vd->xfer_mode == VIO_DRING_MODE_V1_0)) {
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
27ac699d6a5b15c676e0106195cecf7d3c1eea0czk * We should only send an ACK/NACK here if we are not currently in
27ac699d6a5b15c676e0106195cecf7d3c1eea0czk * reset as, depending on how we reset, the dring may have been
27ac699d6a5b15c676e0106195cecf7d3c1eea0czk * blown away and we don't want to ACK/NACK a message that isn't
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
2f5224ae5d04383463098ad866ccee0464ee6429achartre/* ARGSUSED */
2f5224ae5d04383463098ad866ccee0464ee6429achartrevd_geom2dk_geom(void *vd_buf, size_t vd_buf_len, void *ioctl_arg)
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm VD_GEOM2DK_GEOM((vd_geom_t *)vd_buf, (struct dk_geom *)ioctl_arg);
2f5224ae5d04383463098ad866ccee0464ee6429achartre return (0);
2f5224ae5d04383463098ad866ccee0464ee6429achartre/* ARGSUSED */
2f5224ae5d04383463098ad866ccee0464ee6429achartrevd_vtoc2vtoc(void *vd_buf, size_t vd_buf_len, void *ioctl_arg)
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty VD_VTOC2VTOC((vd_vtoc_t *)vd_buf, (struct extvtoc *)ioctl_arg);
2f5224ae5d04383463098ad866ccee0464ee6429achartre return (0);
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lmstatic void
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm DK_GEOM2VD_GEOM((struct dk_geom *)ioctl_arg, (vd_geom_t *)vd_buf);
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lmstatic void
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty VTOC2VD_VTOC((struct extvtoc *)ioctl_arg, (vd_vtoc_t *)vd_buf);
2f5224ae5d04383463098ad866ccee0464ee6429achartrevd_get_efi_in(void *vd_buf, size_t vd_buf_len, void *ioctl_arg)
2f5224ae5d04383463098ad866ccee0464ee6429achartre data_len = vd_buf_len - (sizeof (vd_efi_t) - sizeof (uint64_t));
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan dk_efi->dki_data = kmem_zalloc(vd_efi->length, KM_SLEEP);
2f5224ae5d04383463098ad866ccee0464ee6429achartre return (0);
2f5224ae5d04383463098ad866ccee0464ee6429achartrevd_set_efi_in(void *vd_buf, size_t vd_buf_len, void *ioctl_arg)
2f5224ae5d04383463098ad866ccee0464ee6429achartre data_len = vd_buf_len - (sizeof (vd_efi_t) - sizeof (uint64_t));
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan dk_efi->dki_data = kmem_alloc(vd_efi->length, KM_SLEEP);
2f5224ae5d04383463098ad866ccee0464ee6429achartre return (0);
2f5224ae5d04383463098ad866ccee0464ee6429achartrevd_scsicmd_in(void *vd_buf, size_t vd_buf_len, void *ioctl_arg)
2f5224ae5d04383463098ad866ccee0464ee6429achartre struct uscsi_cmd *uscsi = (struct uscsi_cmd *)ioctl_arg;
2f5224ae5d04383463098ad866ccee0464ee6429achartre /* check buffer size */
2f5224ae5d04383463098ad866ccee0464ee6429achartre vd_scsi_len += P2ROUNDUP(vd_scsi->cdb_len, sizeof (uint64_t));
2f5224ae5d04383463098ad866ccee0464ee6429achartre vd_scsi_len += P2ROUNDUP(vd_scsi->sense_len, sizeof (uint64_t));
2f5224ae5d04383463098ad866ccee0464ee6429achartre vd_scsi_len += P2ROUNDUP(vd_scsi->datain_len, sizeof (uint64_t));
2f5224ae5d04383463098ad866ccee0464ee6429achartre vd_scsi_len += P2ROUNDUP(vd_scsi->dataout_len, sizeof (uint64_t));
2f5224ae5d04383463098ad866ccee0464ee6429achartre /* set flags */
2f5224ae5d04383463098ad866ccee0464ee6429achartre /* task attribute */
2f5224ae5d04383463098ad866ccee0464ee6429achartre /* timeout */
2f5224ae5d04383463098ad866ccee0464ee6429achartre /* cdb data */
2f5224ae5d04383463098ad866ccee0464ee6429achartre uscsi->uscsi_cdb = (caddr_t)VD_SCSI_DATA_CDB(vd_scsi);
2f5224ae5d04383463098ad866ccee0464ee6429achartre /* sense buffer */
2f5224ae5d04383463098ad866ccee0464ee6429achartre uscsi->uscsi_rqbuf = (caddr_t)VD_SCSI_DATA_SENSE(vd_scsi);
2f5224ae5d04383463098ad866ccee0464ee6429achartre if (vd_scsi->datain_len != 0 && vd_scsi->dataout_len != 0) {
2f5224ae5d04383463098ad866ccee0464ee6429achartre /* uscsi does not support read/write request */
2f5224ae5d04383463098ad866ccee0464ee6429achartre /* request data-in */
2f5224ae5d04383463098ad866ccee0464ee6429achartre uscsi->uscsi_bufaddr = (char *)VD_SCSI_DATA_IN(vd_scsi);
2f5224ae5d04383463098ad866ccee0464ee6429achartre /* request data-out */
2f5224ae5d04383463098ad866ccee0464ee6429achartre uscsi->uscsi_bufaddr = (char *)VD_SCSI_DATA_OUT(vd_scsi);
2f5224ae5d04383463098ad866ccee0464ee6429achartre return (0);
2f5224ae5d04383463098ad866ccee0464ee6429achartre struct uscsi_cmd *uscsi = (struct uscsi_cmd *)ioctl_arg;
2f5224ae5d04383463098ad866ccee0464ee6429achartre /* output fields */
2f5224ae5d04383463098ad866ccee0464ee6429achartre /* sense data */
2f5224ae5d04383463098ad866ccee0464ee6429achartre /* request data (read) */
2f5224ae5d04383463098ad866ccee0464ee6429achartre /* request data (write) */
3c96341aef2b4da56c902941f089284b52bd573fnarayan count = (sizeof (struct dk_label)) / (sizeof (short)) - 1;
3c96341aef2b4da56c902941f089284b52bd573fnarayan while (count--) {
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Copy information from a vtoc and dk_geom structures to a dk_label structure.
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsettyvd_vtocgeom_to_label(struct extvtoc *vtoc, struct dk_geom *geom,
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre label->dkl_write_reinstruct = geom->dkg_write_reinstruct;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre label->dkl_read_reinstruct = geom->dkg_read_reinstruct;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre for (i = 0; i < V_NUMPAR; i++) {
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre label->dkl_vtoc.v_timestamp[i] = vtoc->timestamp[i];
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre label->dkl_vtoc.v_part[i].p_tag = vtoc->v_part[i].p_tag;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre label->dkl_vtoc.v_part[i].p_flag = vtoc->v_part[i].p_flag;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre label->dkl_map[i].dkl_cylno = vtoc->v_part[i].p_start /
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre label->dkl_map[i].dkl_nblk = vtoc->v_part[i].p_size;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * The bootinfo array can not be copied with bcopy() because
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * elements are of type long in vtoc (so 64-bit) and of type
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * int in dk_vtoc (so 32-bit).
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre label->dkl_vtoc.v_bootinfo[0] = vtoc->v_bootinfo[0];
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre label->dkl_vtoc.v_bootinfo[1] = vtoc->v_bootinfo[1];
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre label->dkl_vtoc.v_bootinfo[2] = vtoc->v_bootinfo[2];
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre bcopy(vtoc->v_asciilabel, label->dkl_asciilabel, LEN_DKL_ASCII);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre bcopy(vtoc->v_volume, label->dkl_vtoc.v_volume, LEN_DKL_VVOL);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* re-compute checksum */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Copy information from a dk_label structure to a vtoc and dk_geom structures.
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsettyvd_label_to_vtocgeom(struct dk_label *label, struct extvtoc *vtoc,
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre geom->dkg_write_reinstruct = label->dkl_write_reinstruct;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre geom->dkg_read_reinstruct = label->dkl_read_reinstruct;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre vtoc->v_part[i].p_tag = label->dkl_vtoc.v_part[i].p_tag;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre vtoc->v_part[i].p_flag = label->dkl_vtoc.v_part[i].p_flag;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre vtoc->v_part[i].p_start = label->dkl_map[i].dkl_cylno *
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre vtoc->v_part[i].p_size = label->dkl_map[i].dkl_nblk;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre vtoc->timestamp[i] = label->dkl_vtoc.v_timestamp[i];
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * The bootinfo array can not be copied with bcopy() because
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * elements are of type long in vtoc (so 64-bit) and of type
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * int in dk_vtoc (so 32-bit).
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre vtoc->v_bootinfo[0] = label->dkl_vtoc.v_bootinfo[0];
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre vtoc->v_bootinfo[1] = label->dkl_vtoc.v_bootinfo[1];
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre vtoc->v_bootinfo[2] = label->dkl_vtoc.v_bootinfo[2];
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre bcopy(label->dkl_asciilabel, vtoc->v_asciilabel, LEN_DKL_ASCII);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre bcopy(label->dkl_vtoc.v_volume, vtoc->v_volume, LEN_DKL_VVOL);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Check if a geometry is valid for a single-slice disk. A geometry is
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * considered valid if the main attributes of the geometry match with the
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * attributes of the fake geometry we have created.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartrevd_slice_geom_isvalid(vd_t *vd, struct dk_geom *geom)
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Check if a vtoc is valid for a single-slice disk. A vtoc is considered
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * valid if the main attributes of the vtoc match with the attributes of the
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * fake vtoc we have created.
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsettyvd_slice_vtoc_isvalid(vd_t *vd, struct extvtoc *vtoc)
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre strcmp(vtoc->v_asciilabel, vd->vtoc.v_asciilabel) != 0)
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* slice 2 should be unchanged */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Slice 0 should be mostly unchanged and cover most of the disk.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * However we allow some flexibility wrt to the start and the size
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * of this slice mainly because we can't exactly know how it will
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * be defined by the OS installer.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * We allow slice 0 to be defined as starting on any of the first
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * 4 cylinders.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre csize = vd->dk_geom.dkg_nhead * vd->dk_geom.dkg_nsect;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre vtoc->v_part[0].p_size > vtoc->v_part[VD_ENTIRE_DISK_SLICE].p_size)
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre vtoc->v_part[0].p_size < vd->vtoc.v_part[0].p_size - 4 *csize)
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* any other slice should have a size of 0 */
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)
edcc07547a39d6570197493a9836083bd6b2a197achartre /* ioctls for a single slice disk with a VTOC label */
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan bcopy(&vd->dk_geom, ioctl_arg, sizeof (vd->dk_geom));
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan return (0);
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan return (0);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* fake success only if new geometry is valid */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre return (0);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* fake sucess only if the new vtoc is valid */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre return (0);
edcc07547a39d6570197493a9836083bd6b2a197achartre /* ioctls for a single slice disk with an EFI label */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre if ((lba != VD_EFI_LBA_GPT && lba != VD_EFI_LBA_GPE) ||
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre (lba == VD_EFI_LBA_GPT && len < sizeof (efi_gpt_t)) ||
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre (lba == VD_EFI_LBA_GPE && len < sizeof (efi_gpe_t)))
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China (caddr_t)dk_ioc->dki_data,
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China lba * vd->vdisk_bsize, len);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre return (0);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* we currently don't support writing EFI */
205eeb1ae627fcf67b5705c443a2b56a8263406blm /* Unknown disk label type */
edcc07547a39d6570197493a9836083bd6b2a197achartrevds_efi_alloc_and_read(vd_t *vd, efi_gpt_t **gpt, efi_gpe_t **gpe)
edcc07547a39d6570197493a9836083bd6b2a197achartre VD_EFI_DEV_SET(edev, vd, (vd_efi_ioctl_func)vd_backend_ioctl);
edcc07547a39d6570197493a9836083bd6b2a197achartrevds_efi_free(vd_t *vd, efi_gpt_t *gpt, efi_gpe_t *gpe)
edcc07547a39d6570197493a9836083bd6b2a197achartre VD_EFI_DEV_SET(edev, vd, (vd_efi_ioctl_func)vd_backend_ioctl);
edcc07547a39d6570197493a9836083bd6b2a197achartre if ((status = vds_efi_alloc_and_read(vd, &gpt, &gpe)) != 0)
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty bzero(&vd->vtoc, sizeof (struct extvtoc));
edcc07547a39d6570197493a9836083bd6b2a197achartre bzero(vd->slices, sizeof (vd_slice_t) * VD_MAXPART);
edcc07547a39d6570197493a9836083bd6b2a197achartre if (bcmp(&gpe[i].efi_gpe_PartitionTypeGUID, &efi_reserved,
edcc07547a39d6570197493a9836083bd6b2a197achartre sizeof (struct uuid)) == 0)
edcc07547a39d6570197493a9836083bd6b2a197achartre vd->slices[VD_EFI_WD_SLICE].nblocks = vd->vdisk_size;
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre * Function:
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * vd_dskimg_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
edcc07547a39d6570197493a9836083bd6b2a197achartre * to the driver. If an EFI label is found, ENOTSUP is returned.
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.
edcc07547a39d6570197493a9836083bd6b2a197achartre * ENOTSUP - geometry not applicable (EFI label).
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vd_build_default_label(vd->dskimg_size, vd->vdisk_bsize,
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* Update the driver geometry and vtoc */
edcc07547a39d6570197493a9836083bd6b2a197achartre /* Update logical partitions */
edcc07547a39d6570197493a9836083bd6b2a197achartre bzero(vd->slices, sizeof (vd_slice_t) * VD_MAXPART);
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * Handle ioctls to a disk image.
205eeb1ae627fcf67b5705c443a2b56a8263406blm * Return Values
205eeb1ae627fcf67b5705c443a2b56a8263406blm * 0 - Indicates that there are no errors
205eeb1ae627fcf67b5705c443a2b56a8263406blm * != 0 - Disk operation returned an error
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartrevd_do_dskimg_ioctl(vd_t *vd, int cmd, void *ioctl_arg)
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre bcopy(&vd->dk_geom, geom, sizeof (struct dk_geom));
87a7269eb068de448caa9e4404e38bebf4449531achartre return (0);
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty bcopy(&vd->vtoc, vtoc, sizeof (struct extvtoc));
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
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * DKIOCSEXTVTOC.
87a7269eb068de448caa9e4404e38bebf4449531achartre bcopy(ioctl_arg, &vd->dk_geom, sizeof (vd->dk_geom));
87a7269eb068de448caa9e4404e38bebf4449531achartre return (0);
87a7269eb068de448caa9e4404e38bebf4449531achartre /* write label to the disk image */
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre if ((rc = vd_dskimg_set_vtoc(vd, &label)) != 0)
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre if (vd_dskimg_rw(vd, VD_SLICE_NONE, VD_OP_BREAD,
edcc07547a39d6570197493a9836083bd6b2a197achartre (caddr_t)efi->dki_data, efi->dki_lba, efi->dki_length) < 0)
87a7269eb068de448caa9e4404e38bebf4449531achartre return (0);
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre if (vd_dskimg_rw(vd, VD_SLICE_NONE, VD_OP_BWRITE,
edcc07547a39d6570197493a9836083bd6b2a197achartre (caddr_t)efi->dki_data, efi->dki_lba, efi->dki_length) < 0)
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty ASSERT(cmd == DKIOCSEXTVTOC || cmd == DKIOCSETEFI);
edcc07547a39d6570197493a9836083bd6b2a197achartre /* label has changed, revalidate the geometry */
edcc07547a39d6570197493a9836083bd6b2a197achartre * The disk geometry may have changed, so we need to write
edcc07547a39d6570197493a9836083bd6b2a197achartre * the devid (if there is one) so that it is stored at the
edcc07547a39d6570197493a9836083bd6b2a197achartre * right location.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre if (vd_dskimg_write_devid(vd, vd->dskimg_devid) != 0) {
edcc07547a39d6570197493a9836083bd6b2a197achartre return (0);
edcc07547a39d6570197493a9836083bd6b2a197achartre * Call the appropriate function to execute the ioctl depending
edcc07547a39d6570197493a9836083bd6b2a197achartre * on the type of vdisk.
edcc07547a39d6570197493a9836083bd6b2a197achartre /* slice, file or volume exported as a single slice disk */
edcc07547a39d6570197493a9836083bd6b2a197achartre /* file or volume exported as a full disk */
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre status = vd_do_dskimg_ioctl(vd, cmd, arg);
edcc07547a39d6570197493a9836083bd6b2a197achartre /* disk device exported as a full disk */
edcc07547a39d6570197493a9836083bd6b2a197achartre status = ldi_ioctl(vd->ldi_handle[0], cmd, (intptr_t)arg,
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * By default VTOC ioctls are done using ioctls for the
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * extended VTOC. Some drivers (in particular non-Sun drivers)
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * may not support these ioctls. In that case, we fallback to
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty * the regular VTOC ioctls.
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty status = ldi_ioctl(vd->ldi_handle[0], cmd,
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty (intptr_t)&vtoc, vd->open_flags | FKIOCTL,
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty extvtoctovtoc((*(struct extvtoc *)(void *)arg),
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty status = ldi_ioctl(vd->ldi_handle[0], cmd,
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty (intptr_t)&vtoc, vd->open_flags | FKIOCTL,
edcc07547a39d6570197493a9836083bd6b2a197achartre if (rval != 0) {
edcc07547a39d6570197493a9836083bd6b2a197achartre PR0("ioctl %x set rval = %d, which is not being returned"
edcc07547a39d6570197493a9836083bd6b2a197achartre#endif /* DEBUG */
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 */
2f5224ae5d04383463098ad866ccee0464ee6429achartre /* use client buffer */
2f5224ae5d04383463098ad866ccee0464ee6429achartre /* convert client vdisk operation data to ioctl data */
2f5224ae5d04383463098ad866ccee0464ee6429achartre return (0);
2f5224ae5d04383463098ad866ccee0464ee6429achartre struct uscsi_cmd *uscsi = (struct uscsi_cmd *)ioctl->arg;
2f5224ae5d04383463098ad866ccee0464ee6429achartre /* check write permission */
2f5224ae5d04383463098ad866ccee0464ee6429achartre PR0("uscsi fails because backend is opened read-only");
2f5224ae5d04383463098ad866ccee0464ee6429achartre return (0);
edcc07547a39d6570197493a9836083bd6b2a197achartre * Send the ioctl to the disk backend.
edcc07547a39d6570197493a9836083bd6b2a197achartre request->status = vd_backend_ioctl(vd, ioctl->cmd, ioctl->arg);
205eeb1ae627fcf67b5705c443a2b56a8263406blm PR0("ioctl(%s) = errno %d", ioctl->cmd_name, request->status);
2f5224ae5d04383463098ad866ccee0464ee6429achartre ((struct uscsi_cmd *)ioctl->arg)->uscsi_status != 0)
2f5224ae5d04383463098ad866ccee0464ee6429achartre * USCSICMD has reported an error and the uscsi_status
2f5224ae5d04383463098ad866ccee0464ee6429achartre * field is not zero. This means that the SCSI command
2f5224ae5d04383463098ad866ccee0464ee6429achartre * has completed but it has an error. So we should
2f5224ae5d04383463098ad866ccee0464ee6429achartre * mark the VD operation has succesfully completed
2f5224ae5d04383463098ad866ccee0464ee6429achartre * and clients can check the SCSI status field for
2f5224ae5d04383463098ad866ccee0464ee6429achartre * SCSI errors.
2f5224ae5d04383463098ad866ccee0464ee6429achartre 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),
2f5224ae5d04383463098ad866ccee0464ee6429achartre {VD_OP_SCSICMD, STRINGIZE(VD_OP_SCSICMD), RNDSIZE(vd_scsi_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 */
047ba61eb972395c8952e47676eefbb616aceec3achartre if (!(vd->open_flags & FWRITE) && ioctl[i].write) {
047ba61eb972395c8952e47676eefbb616aceec3achartre PR0("%s fails because backend is opened read-only",
047ba61eb972395c8952e47676eefbb616aceec3achartre return (0);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * We don't support devid for single-slice disks because we
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * have no space to store a fabricated devid and for physical
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * disk slices, we can't use the devid of the disk otherwise
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * exporting multiple slices from the same disk will produce
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * the same devids.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre return (0);
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",
2f5224ae5d04383463098ad866ccee0464ee6429achartre status = ldi_ioctl(vd->ldi_handle[0], USCSICMD, (intptr_t)&uscsi,
2f5224ae5d04383463098ad866ccee0464ee6429achartre return (0);
2f5224ae5d04383463098ad866ccee0464ee6429achartre PR0("VD_OP_GET_CAPACITY: Expected nbytes = %lu, got %lu",
de3a53312897a4ba0d450636226db584e8b09648Ramesh Chitrothu * Check the backend size in case it has changed. If the check fails
de3a53312897a4ba0d450636226db584e8b09648Ramesh Chitrothu * then we will return the last known size.
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vd_cap.vdisk_block_size = vd->vdisk_bsize;
2f5224ae5d04383463098ad866ccee0464ee6429achartre if ((rv = ldc_mem_copy(vd->ldc_handle, (char *)&vd_cap, 0, &nbytes,
2f5224ae5d04383463098ad866ccee0464ee6429achartre request->cookie, request->ncookies, LDC_COPY_OUT)) != 0) {
2f5224ae5d04383463098ad866ccee0464ee6429achartre PR0("ldc_mem_copy() returned errno %d copying to client", rv);
2f5224ae5d04383463098ad866ccee0464ee6429achartre return (0);
2f5224ae5d04383463098ad866ccee0464ee6429achartre PR0("VD_OP_GET_ACCESS: Expected nbytes = %lu, got %lu",
2f5224ae5d04383463098ad866ccee0464ee6429achartre request->status = ldi_ioctl(vd->ldi_handle[request->slice], MHIOCSTATUS,
2f5224ae5d04383463098ad866ccee0464ee6429achartre return (0);
2f5224ae5d04383463098ad866ccee0464ee6429achartre access = (rval == 0)? VD_ACCESS_ALLOWED : VD_ACCESS_DENIED;
2f5224ae5d04383463098ad866ccee0464ee6429achartre if ((rv = ldc_mem_copy(vd->ldc_handle, (char *)&access, 0, &nbytes,
2f5224ae5d04383463098ad866ccee0464ee6429achartre request->cookie, request->ncookies, LDC_COPY_OUT)) != 0) {
2f5224ae5d04383463098ad866ccee0464ee6429achartre PR0("ldc_mem_copy() returned errno %d copying to client", rv);
2f5224ae5d04383463098ad866ccee0464ee6429achartre return (0);
2f5224ae5d04383463098ad866ccee0464ee6429achartre PR0("VD_OP_SET_ACCESS: Expected nbytes = %lu, got %lu",
2f5224ae5d04383463098ad866ccee0464ee6429achartre if ((rv = ldc_mem_copy(vd->ldc_handle, (char *)&flags, 0, &nbytes,
2f5224ae5d04383463098ad866ccee0464ee6429achartre request->cookie, request->ncookies, LDC_COPY_IN)) != 0) {
2f5224ae5d04383463098ad866ccee0464ee6429achartre PR0("ldc_mem_copy() returned errno %d copying from client", rv);
2f5224ae5d04383463098ad866ccee0464ee6429achartre request->status = ldi_ioctl(vd->ldi_handle[request->slice],
2f5224ae5d04383463098ad866ccee0464ee6429achartre MHIOCRELEASE, NULL, (vd->open_flags | FKIOCTL), kcred,
2f5224ae5d04383463098ad866ccee0464ee6429achartre return (0);
2f5224ae5d04383463098ad866ccee0464ee6429achartre * As per the VIO spec, the PREEMPT and PRESERVE flags are only valid
2f5224ae5d04383463098ad866ccee0464ee6429achartre * when the EXCLUSIVE flag is set.
2f5224ae5d04383463098ad866ccee0464ee6429achartre PR0("Invalid VD_OP_SET_ACCESS flags: 0x%lx", flags);
2f5224ae5d04383463098ad866ccee0464ee6429achartre return (0);
2f5224ae5d04383463098ad866ccee0464ee6429achartre switch (flags & (VD_ACCESS_SET_PREEMPT | VD_ACCESS_SET_PRESERVE)) {
2f5224ae5d04383463098ad866ccee0464ee6429achartre case VD_ACCESS_SET_PREEMPT | VD_ACCESS_SET_PRESERVE:
2f5224ae5d04383463098ad866ccee0464ee6429achartre * Flags EXCLUSIVE and PREEMPT and PRESERVE. We have to
2f5224ae5d04383463098ad866ccee0464ee6429achartre * acquire exclusive access rights, preserve them and we
2f5224ae5d04383463098ad866ccee0464ee6429achartre * can use preemption. So we can use the MHIOCTKNOWN ioctl.
2f5224ae5d04383463098ad866ccee0464ee6429achartre PR0("Performing VD_OP_SET_ACCESS (EXCLUSIVE|PREEMPT|PRESERVE)");
2f5224ae5d04383463098ad866ccee0464ee6429achartre request->status = ldi_ioctl(vd->ldi_handle[request->slice],
2f5224ae5d04383463098ad866ccee0464ee6429achartre MHIOCTKOWN, NULL, (vd->open_flags | FKIOCTL), kcred, &rval);
2f5224ae5d04383463098ad866ccee0464ee6429achartre * Flags EXCLUSIVE and PRESERVE. We have to acquire exclusive
2f5224ae5d04383463098ad866ccee0464ee6429achartre * access rights and preserve them, but not preempt any other
2f5224ae5d04383463098ad866ccee0464ee6429achartre * host. So we need to use the MHIOCTKOWN ioctl to enable the
2f5224ae5d04383463098ad866ccee0464ee6429achartre * "preserve" feature but we can not called it directly
2f5224ae5d04383463098ad866ccee0464ee6429achartre * because it uses preemption. So before that, we use the
2f5224ae5d04383463098ad866ccee0464ee6429achartre * MHIOCQRESERVE ioctl to ensure we can get exclusive rights
2f5224ae5d04383463098ad866ccee0464ee6429achartre * without preempting anyone.
2f5224ae5d04383463098ad866ccee0464ee6429achartre PR0("Performing VD_OP_SET_ACCESS (EXCLUSIVE|PRESERVE)");
2f5224ae5d04383463098ad866ccee0464ee6429achartre request->status = ldi_ioctl(vd->ldi_handle[request->slice],
2f5224ae5d04383463098ad866ccee0464ee6429achartre MHIOCQRESERVE, NULL, (vd->open_flags | FKIOCTL), kcred,
2f5224ae5d04383463098ad866ccee0464ee6429achartre request->status = ldi_ioctl(vd->ldi_handle[request->slice],
2f5224ae5d04383463098ad866ccee0464ee6429achartre MHIOCTKOWN, NULL, (vd->open_flags | FKIOCTL), kcred, &rval);
2f5224ae5d04383463098ad866ccee0464ee6429achartre * Flags EXCLUSIVE and PREEMPT. We have to acquire exclusive
2f5224ae5d04383463098ad866ccee0464ee6429achartre * access rights and we can use preemption. So we try to do
2f5224ae5d04383463098ad866ccee0464ee6429achartre * a SCSI reservation, if it fails we reset the disk to clear
2f5224ae5d04383463098ad866ccee0464ee6429achartre * any reservation and we try to reserve again.
2f5224ae5d04383463098ad866ccee0464ee6429achartre PR0("Performing VD_OP_SET_ACCESS (EXCLUSIVE|PREEMPT)");
2f5224ae5d04383463098ad866ccee0464ee6429achartre request->status = ldi_ioctl(vd->ldi_handle[request->slice],
2f5224ae5d04383463098ad866ccee0464ee6429achartre MHIOCQRESERVE, NULL, (vd->open_flags | FKIOCTL), kcred,
2f5224ae5d04383463098ad866ccee0464ee6429achartre /* reset the disk */
2f5224ae5d04383463098ad866ccee0464ee6429achartre /* try again even if the reset has failed */
2f5224ae5d04383463098ad866ccee0464ee6429achartre request->status = ldi_ioctl(vd->ldi_handle[request->slice],
2f5224ae5d04383463098ad866ccee0464ee6429achartre MHIOCQRESERVE, NULL, (vd->open_flags | FKIOCTL), kcred,
2f5224ae5d04383463098ad866ccee0464ee6429achartre /* Flag EXCLUSIVE only. Just issue a SCSI reservation */
2f5224ae5d04383463098ad866ccee0464ee6429achartre request->status = ldi_ioctl(vd->ldi_handle[request->slice],
2f5224ae5d04383463098ad866ccee0464ee6429achartre MHIOCQRESERVE, NULL, (vd->open_flags | FKIOCTL), kcred,
2f5224ae5d04383463098ad866ccee0464ee6429achartre PR0("VD_OP_SET_ACCESS: error %d", request->status);
2f5224ae5d04383463098ad866ccee0464ee6429achartre return (0);
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre if (vd->file || vd->volume || !vd->ownership)
2f5224ae5d04383463098ad866ccee0464ee6429achartre status = ldi_ioctl(vd->ldi_handle[0], MHIOCRELEASE, NULL,
2f5224ae5d04383463098ad866ccee0464ee6429achartre * An EACCES failure means that there is a reservation conflict,
2f5224ae5d04383463098ad866ccee0464ee6429achartre * so we are not the owner of the disk anymore.
2f5224ae5d04383463098ad866ccee0464ee6429achartre PR0("Fail to release ownership, error %d", status);
2f5224ae5d04383463098ad866ccee0464ee6429achartre * We have failed to release the ownership, try to reset the disk
2f5224ae5d04383463098ad866ccee0464ee6429achartre * to release reservations.
2f5224ae5d04383463098ad866ccee0464ee6429achartre /* whatever the result of the reset is, we try the release again */
2f5224ae5d04383463098ad866ccee0464ee6429achartre status = ldi_ioctl(vd->ldi_handle[0], MHIOCRELEASE, NULL,
2f5224ae5d04383463098ad866ccee0464ee6429achartre PR0("Fail to release ownership, error %d", status);
2f5224ae5d04383463098ad866ccee0464ee6429achartre * At this point we have done our best to try to reset the
2f5224ae5d04383463098ad866ccee0464ee6429achartre * access rights to the disk and we don't know if we still
2f5224ae5d04383463098ad866ccee0464ee6429achartre * own a reservation and if any mechanism to preserve the
2f5224ae5d04383463098ad866ccee0464ee6429achartre * ownership is still in place. The ultimate solution would
2f5224ae5d04383463098ad866ccee0464ee6429achartre * be to reset the system but this is usually not what we
2f5224ae5d04383463098ad866ccee0464ee6429achartre * want to happen.
2f5224ae5d04383463098ad866ccee0464ee6429achartre panic(VD_RESET_ACCESS_FAILURE_MSG, vd->device_path);
2f5224ae5d04383463098ad866ccee0464ee6429achartre cmn_err(CE_WARN, VD_RESET_ACCESS_FAILURE_MSG, vd->device_path);
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 */
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * We need to check that the requested operation is permitted
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * for the particular client that sent it or that the loop above
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * did not complete without finding the operation type (indicating
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * that the requested operation is unknown/unimplemented)
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm if ((VD_OP_SUPPORTED(vd->operations, request->operation) == B_FALSE) ||
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm return (0);
7636cb21f250f0485ca6052ffadc80ace93e6358lm /* Range-check slice */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre ((vd->vdisk_type != VD_DISK_TYPE_DISK && vd_slice_single_slice) ||
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre return (0);
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 */
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre if (!vd->reset_state && (vd->xfer_mode == VIO_DRING_MODE_V1_0)) {
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
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * Store the negotiated major and minor version values in the "vd" data
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * structure so that we can check if certain operations are supported
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * by the client.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0);
17cadca83cc82e37ff517ea2783eb4bfcc07b950lmstatic void
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * We need to check from the highest version supported to the
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * lowest because versions with a higher minor number implicitly
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * support versions with a lower minor number.
de3a53312897a4ba0d450636226db584e8b09648Ramesh Chitrothu vd->operations |= VD_OP_MASK_READ | (1 << VD_OP_GET_CAPACITY);
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre if (VD_DSKIMG(vd) && vd_dskimg_is_iso_image(vd)) {
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * can't write to ISO images, make sure that write
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * support is not set in case administrator did not
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * use "options=ro" when doing an ldm add-vdsdev
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm /* we should have already agreed on a version */
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 */
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre PR0("vdisk_type = %s, volume = %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.
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China attr_msg->vdisk_block_size * attr_msg->max_xfer_sz :
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 */
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China attr_msg->vdisk_block_size = vd->vdisk_bsize;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre attr_msg->vdisk_type = (vd_slice_single_slice)? vd->vdisk_type :
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm /* Discover and save the list of supported VD_OP_XXX operations */
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,
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);
5b7cb889d5dcadfe96f6a0188f0648131d49d3b3ha * The descriptor payload varies in length. Calculate its
5b7cb889d5dcadfe96f6a0188f0648131d49d3b3ha * size by subtracting the header size from the total
5b7cb889d5dcadfe96f6a0188f0648131d49d3b3ha * descriptor size.
5b7cb889d5dcadfe96f6a0188f0648131d49d3b3ha vd->dring_task[i].request = kmem_zalloc((vd->descriptor_size -
3af08d828975d7e2581b6829e0eecff14d87a483lm vd->dring_task[i].msg = kmem_alloc(vd->max_msglen, KM_SLEEP);
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre kmem_zalloc(sizeof (buf_t *) * vd->dring_len, 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 /* 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.
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre 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);
f0ca1d9a12d54d304791bc74525e2010ca924726sb case VIO_DRING_MODE_V1_0: /* 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 */
f0ca1d9a12d54d304791bc74525e2010ca924726sb case VIO_DRING_MODE_V1_0: /* 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) {
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty rv = vd_process_msg(vd, (void *)vd->vio_msgp, msglen);
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));
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * Description:
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * This function checks to see if the disk image being used as a
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * virtual disk is an ISO image. An ISO image is a special case
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * which can be booted/installed from like a CD/DVD.
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * Parameters:
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * vd - disk on which the operation is performed.
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * Return Code:
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * B_TRUE - The disk image is an ISO 9660 compliant image
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * B_FALSE - just a regular disk image
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * If we have already discovered and saved this info we can
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * short-circuit the check and avoid reading the disk image.
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm if (vd->vdisk_media == VD_MEDIA_DVD || vd->vdisk_media == VD_MEDIA_CD)
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * We wish to read the sector that should contain the 2nd ISO volume
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * descriptor. The second field in this descriptor is called the
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * Standard Identifier and is set to CD001 for a CD-ROM compliant
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * to the ISO 9660 standard.
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China sec = (ISO_VOLDESC_SEC * ISO_SECTOR_SIZE) / vd->vdisk_bsize;
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre rv = vd_dskimg_rw(vd, VD_SLICE_NONE, VD_OP_BREAD, (caddr_t)iso_buf,
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm for (i = 0; i < ISO_ID_STRLEN; i++) {
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * Description:
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * This function checks to see if the virtual device is an ATAPI
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * device. ATAPI devices use Group 1 Read/Write commands, so
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * any USCSI calls vds makes need to take this into account.
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * Parameters:
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * vd - disk on which the operation is performed.
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * Return Code:
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * B_TRUE - The virtual disk is backed by an ATAPI device
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * B_FALSE - not an ATAPI device (presumably SCSI)
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm (LDI_DEV_T_ANY | DDI_PROP_DONTPASS), "variant", &variantp);
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm PR0("'variant' property exists for %s", vd->device_path);
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm rv = ldi_prop_exists(vd->ldi_handle[0], LDI_DEV_T_ANY, "atapi");
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm minor_t minor = getminor(vd->dev[0]) - VD_ENTIRE_DISK_SLICE;
de3a53312897a4ba0d450636226db584e8b09648Ramesh Chitrothu /* set the disk size, block size and the media type of the disk */
2f5224ae5d04383463098ad866ccee0464ee6429achartre /* unexpected failure */
cc446bab4d3331e782fa29c34006ed7694138452Alexandre Chartre PRN("Check size failed for %s (errno %d)",
2f5224ae5d04383463098ad866ccee0464ee6429achartre * The function can fail for SCSI disks which are present but
2f5224ae5d04383463098ad866ccee0464ee6429achartre * reserved by another system. In that case, we don't know the
2f5224ae5d04383463098ad866ccee0464ee6429achartre * size of the disk and the block size.
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vd->vdisk_bsize = 0;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vd->backend_bsize = 0;
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.
047ba61eb972395c8952e47676eefbb616aceec3achartre * Try to open the device. This can fail for example if we are
047ba61eb972395c8952e47676eefbb616aceec3achartre * opening an empty slice. So in case of a failure, we try the
047ba61eb972395c8952e47676eefbb616aceec3achartre * open again but this time with the FNDELAY flag.
047ba61eb972395c8952e47676eefbb616aceec3achartre status = ldi_open_by_dev(&vd->dev[slice], OTYP_BLK,
047ba61eb972395c8952e47676eefbb616aceec3achartre status = ldi_open_by_dev(&vd->dev[slice], OTYP_BLK,
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm /* vds_destroy_vd() will close any open slices */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm return (0);
edcc07547a39d6570197493a9836083bd6b2a197achartre * When a slice or a volume is exported as a single-slice disk, we want
edcc07547a39d6570197493a9836083bd6b2a197achartre * the disk backend (i.e. the slice or volume) to be entirely mapped as
edcc07547a39d6570197493a9836083bd6b2a197achartre * a slice without the addition of any metadata.
edcc07547a39d6570197493a9836083bd6b2a197achartre * So when exporting the disk as a VTOC disk, we fake a disk with the following
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * flabel +--- flabel_limit
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * 0 1 C D E
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * +-+---+--------------------------+--+
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * virtual disk: |L|XXX| slice 0 |AA|
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * +-+---+--------------------------+--+
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * VTOC LABEL--+ : :
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * +--------------------------+
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * disk backend: | slice/volume/file |
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * +--------------------------+
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * N is the number of blocks in the slice/volume/file.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * We simulate a disk with N+M blocks, where M is the number of blocks
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * simluated at the beginning and at the end of the disk (blocks 0-C
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * and D-E).
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * The first blocks (0 to C-1) are emulated and can not be changed. Blocks C
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * to D defines slice 0 and are mapped to the backend. Finally we emulate 2
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * alternate cylinders at the end of the disk (blocks D-E). In summary we have:
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * - block 0 (L) returns a fake VTOC label
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * - blocks 1 to C-1 (X) are unused and return 0
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * - blocks C to D-1 are mapped to the exported slice or volume
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * - blocks D and E (A) are blocks defining alternate cylinders (2 cylinders)
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Note: because we define a fake disk geometry, it is possible that the length
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * of the backend is not a multiple of the size of cylinder, in that case the
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * very end of the backend will not map to any block of the virtual disk.
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre /* Initialize dk_geom structure for single-slice device */
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre PRN("%s geometry claims 0 sectors per track", device_path);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* size of a cylinder in block */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre csize = vd->dk_geom.dkg_nhead * vd->dk_geom.dkg_nsect;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Add extra cylinders: we emulate the first cylinder (which contains
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * the disk label).
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* we emulate 2 alternate cylinders */
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre vd->dk_geom.dkg_pcyl = vd->dk_geom.dkg_ncyl + vd->dk_geom.dkg_acyl;
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre /* Initialize vtoc structure for single-slice device */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Partition 0 starts on cylinder 1 and its size has to be
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * a multiple of a number of cylinder.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre vd->vtoc.v_part[0].p_start = csize; /* start on cylinder 1 */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre vd->vtoc.v_part[0].p_size = (vd->vdisk_size / csize) * csize;
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre MIN(sizeof (VD_VOLUME_NAME), sizeof (vd->vtoc.v_volume)));
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* adjust the number of slices */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* define slice 2 representing the entire disk */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre vd->vtoc.v_part[VD_ENTIRE_DISK_SLICE].p_tag = V_BACKUP;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vd_get_readable_size(vd->vdisk_size * vd->vdisk_bsize,
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * Set some attributes of the geometry to what format(1m) uses
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * so that writing a default label using format(1m) does not
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * produce any error.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * We must have a correct label name otherwise format(1m) will
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * not recognized the disk as labeled.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre (void) snprintf(vd->vtoc.v_asciilabel, LEN_DKL_ASCII,
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre "SUN-DiskSlice-%ld%cB cyl %d alt %d hd %d sec %d",
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre bzero(vd->vtoc.v_volume, sizeof (vd->vtoc.v_volume));
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* create a fake label from the vtoc and geometry */
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vd->flabel_size = VD_LABEL_VTOC_SIZE(vd->vdisk_bsize);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre vd->flabel = kmem_zalloc(vd->flabel_size, KM_SLEEP);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* adjust the vdisk_size, we emulate 3 cylinders */
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre return (0);
edcc07547a39d6570197493a9836083bd6b2a197achartre * When a slice, volume or file is exported as a single-slice disk, we want
edcc07547a39d6570197493a9836083bd6b2a197achartre * the disk backend (i.e. the slice, volume or file) to be entirely mapped
edcc07547a39d6570197493a9836083bd6b2a197achartre * as a slice without the addition of any metadata.
edcc07547a39d6570197493a9836083bd6b2a197achartre * So when exporting the disk as an EFI disk, we fake a disk with the following
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * layout: (assuming the block size is 512 bytes)
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * flabel +--- flabel_limit
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * <------> v
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * 0 1 2 L 34 34+N P
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * +-+-+--+-------+--------------------------+-------+
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * virtual disk: |X|T|EE|XXXXXXX| slice 0 |RRRRRRR|
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * +-+-+--+-------+--------------------------+-------+
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * GPT-+ +-GPE : :
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * +--------------------------+
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * disk backend: | slice/volume/file |
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * +--------------------------+
edcc07547a39d6570197493a9836083bd6b2a197achartre * N is the number of blocks in the slice/volume/file.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * We simulate a disk with N+M blocks, where M is the number of blocks
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * simluated at the beginning and at the end of the disk (blocks 0-34
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * and 34+N-P).
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * The first 34 blocks (0 to 33) are emulated and can not be changed. Blocks 34
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * to 34+N defines slice 0 and are mapped to the exported backend, and we
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * emulate some blocks at the end of the disk (blocks 34+N to P) as a the EFI
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * reserved partition.
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * - block 0 (X) is unused and return 0
edcc07547a39d6570197493a9836083bd6b2a197achartre * - block 1 (T) returns a fake EFI GPT (via DKIOCGETEFI)
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * - blocks 2 to L-1 (E) defines a fake EFI GPE (via DKIOCGETEFI)
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * - blocks L to 33 (X) are unused and return 0
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * - blocks 34 to 34+N are mapped to the exported slice, volume or file
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * - blocks 34+N+1 to P define a fake reserved partition and backup label, it
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * returns 0
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * Note: if the backend size is not a multiple of the vdisk block size then
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * the very end of the backend will not map to any block of the virtual disk.
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China uint64_t s0_start, s0_end, first_u_lba;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China size_t bsize;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China ASSERT(vd->vdisk_bsize > 0);
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China bsize = vd->vdisk_bsize;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * The minimum size for the label is 16K (EFI_MIN_ARRAY_SIZE)
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * for GPEs plus one block for the GPT and one for PMBR.
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China first_u_lba = (EFI_MIN_ARRAY_SIZE / bsize) + 2;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vd->flabel_limit = (uint_t)first_u_lba;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vd->flabel_size = VD_LABEL_EFI_SIZE(bsize);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre vd->flabel = kmem_zalloc(vd->flabel_size, KM_SLEEP);
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China gpt = VD_LABEL_EFI_GPT(vd, bsize);
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China gpe = VD_LABEL_EFI_GPE(vd, bsize);
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * Adjust the vdisk_size, we emulate the first few blocks
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * for the disk label.
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vd->vdisk_size += first_u_lba;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China s0_start = first_u_lba;
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan gpt->efi_gpt_HeaderSize = LE_32(sizeof (efi_gpt_t));
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China gpt->efi_gpt_FirstUsableLBA = LE_64(first_u_lba);
4bac220845f606f60663ed6f3a2b88caa00ae87enarayan gpt->efi_gpt_SizeOfPartitionEntry = LE_32(sizeof (efi_gpe_t));
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre UUID_LE_CONVERT(gpe[0].efi_gpe_PartitionTypeGUID, uuid);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* adjust the number of slices */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre gpt->efi_gpt_NumberOfPartitionEntries = LE_32(VD_MAXPART);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* define a fake reserved partition */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre UUID_LE_CONVERT(gpe[VD_MAXPART - 1].efi_gpe_PartitionTypeGUID,
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* adjust the vdisk_size to include the reserved slice */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre gpt->efi_gpt_LastUsableLBA = LE_64(vd->vdisk_size - 1);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* adjust the vdisk size for the backup GPT and GPE */
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vd->vdisk_size += (EFI_MIN_ARRAY_SIZE / bsize) + 1;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China gpt->efi_gpt_AlternateLBA = LE_64(vd->vdisk_size - 1);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre CRC32(crc, gpe, sizeof (efi_gpe_t) * VD_MAXPART, -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);
047ba61eb972395c8952e47676eefbb616aceec3achartre * Setup for a virtual disk whose backend is a file (exported as a single slice
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * or as a full disk). In that case, the backend is accessed using the vnode
047ba61eb972395c8952e47676eefbb616aceec3achartre if ((status = vn_open(file_path, UIO_SYSSPACE, vd->open_flags | FOFFMAX,
a2b1d4fbb85525bff34187316a8ac58745dc963dZach Kissel if ((status == ENXIO || status == ENODEV || status == ENOENT ||
a2b1d4fbb85525bff34187316a8ac58745dc963dZach Kissel status == EROFS) && (!(vd->initialized & VD_SETUP_ERROR) &&
a2b1d4fbb85525bff34187316a8ac58745dc963dZach Kissel PRN("vn_open(%s) = errno %d", file_path, status);
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 vd->max_xfer_sz = maxphys / DEV_BSIZE; /* default transfer size */
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * Get max_xfer_sz from the device where the file is.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre PR0("underlying device of %s = (%d, %d)\n", file_path,
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre status = ldi_open_by_dev(&dev, OTYP_BLK, FREAD, kcred, &lhandle,
f745d6a3fc99e7af9f6bb7cfc14055a3ff91e566achartre PR0("ldi_open() returned errno %d for underlying device",
047ba61eb972395c8952e47676eefbb616aceec3achartre (intptr_t)&dk_cinfo, (vd->open_flags | FKIOCTL), kcred,
3c96341aef2b4da56c902941f089284b52bd573fnarayan * Store the device's max transfer size for
3c96341aef2b4da56c902941f089284b52bd573fnarayan * return to the client
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre PR0("using file %s on device (%d, %d), max_xfer = %u blks",
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre file_path, getmajor(dev), getminor(dev), vd->max_xfer_sz);
cc446bab4d3331e782fa29c34006ed7694138452Alexandre Chartre if ((status = vd_backend_check_size(vd)) != 0) {
cc446bab4d3331e782fa29c34006ed7694138452Alexandre Chartre PRN("Check size failed for %s (errno %d)",
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre vd->vdisk_label = (vd_slice_label == VD_DISK_LABEL_UNK)?
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre if (vd->vdisk_label == VD_DISK_LABEL_EFI ||
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * We build a default label to get a geometry for
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * the vdisk. Then the partition setup function will
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * adjust the vtoc so that it defines a single-slice
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vd_build_default_label(vd->dskimg_size, vd->vdisk_bsize,
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre vd_label_to_vtocgeom(&label, &vd->vtoc, &vd->dk_geom);
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China if ((status = vd_backend_check_size(vd)) != 0) {
cc446bab4d3331e782fa29c34006ed7694138452Alexandre Chartre PRN("Check size failed for %s (errno %d)",
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China backend_path, status);
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China return (EIO);
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre /* size should be at least sizeof(dk_label) */
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre if (vd->dskimg_size < sizeof (struct dk_label)) {
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre PRN("Size of file has to be at least %ld bytes",
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre sizeof (struct dk_label));
edcc07547a39d6570197493a9836083bd6b2a197achartre * Find and validate the geometry of a disk image.
edcc07547a39d6570197493a9836083bd6b2a197achartre if (status != 0 && status != EINVAL && status != ENOTSUP) {
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre PRN("Failed to read label from %s", backend_path);
edcc07547a39d6570197493a9836083bd6b2a197achartre * Indicate whether to call this a CD or DVD from the size
edcc07547a39d6570197493a9836083bd6b2a197achartre * of the ISO image (images for both drive types are stored
edcc07547a39d6570197493a9836083bd6b2a197achartre * in the ISO-9600 format). CDs can store up to just under 1Gb
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China if ((vd->vdisk_size * vd->vdisk_bsize) > ONE_GIGABYTE)
edcc07547a39d6570197493a9836083bd6b2a197achartre /* Setup devid for the disk image */
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre status = vd_dskimg_read_devid(vd, &vd->dskimg_devid);
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.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre PR0("can not read devid for %s", backend_path);
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.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre PR1("creating devid for %s", backend_path);
87a7269eb068de448caa9e4404e38bebf4449531achartre if (ddi_devid_init(vd->vds->dip, DEVID_FAB, NULL, 0,
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre PR0("fail to create devid for %s", backend_path);
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.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre if (vd_dskimg_write_devid(vd, vd->dskimg_devid) != 0) {
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre PR0("fail to write devid for %s", backend_path);
3c96341aef2b4da56c902941f089284b52bd573fnarayan return (0);
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * Description:
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * Open a device using its device path (supplied by ldm(1m))
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * Parameters:
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * vd - pointer to structure containing the vDisk info
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * flags - open flags
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * Return Value
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * 0 - success
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * != 0 - some other non-zero return value from ldi(9F) functions
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre /* Attempt to open device */
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre status = ldi_open_by_name(device_path, flags, kcred,
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * The open can fail for example if we are opening an empty slice.
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * In case of a failure, we try the open again but this time with
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * the FNDELAY flag.
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre status = ldi_open_by_name(device_path, flags | FNDELAY,
3c96341aef2b4da56c902941f089284b52bd573fnarayan PR0("ldi_open_by_name(%s) = errno %d", device_path, status);
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm return (0);
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * Setup for a virtual disk which backend is a device (a physical disk,
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * slice or volume device) exported as a full disk or as a slice. In these
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * cases, the backend is accessed using the LDI interface.
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre /* device has been opened by vd_identify_dev() */
78fcd0a1c10bb5a069d27365ac663157b8bac58bachartre /* Verify backing device supports dk_cinfo */
047ba61eb972395c8952e47676eefbb616aceec3achartre (intptr_t)&dk_cinfo, (vd->open_flags | FKIOCTL), kcred,
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * The device has been opened read-only by vd_identify_dev(), re-open
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * it read-write if the write flag is set and we don't have an optical
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * device such as a CD-ROM, which, for now, we do not permit writes to
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * and thus should not export write operations to the client.
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * Future: if/when we implement support for guest domains writing to
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * optical devices we will need to do further checking of the media type
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * to distinguish between read-only and writable discs.
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre (void) ldi_close(vd->ldi_handle[0], vd->open_flags & ~FWRITE,
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre status = vd_open_using_ldi_by_name(vd, vd->open_flags);
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm /* Store the device's max transfer size for return to the client */
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * We need to work out if it's an ATAPI (IDE CD-ROM) or SCSI device so
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * that we can use the correct CDB group when sending USCSI commands.
047ba61eb972395c8952e47676eefbb616aceec3achartre * Export a full disk.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * The exported device can be either a volume, a disk or a CD/DVD
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * device. We export a device as a full disk if we have an entire
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * disk slice (slice 2) and if this slice is exported as a full disk
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * and not as a single slice disk. A CD or DVD device is exported
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * as a full disk (even if it isn't s2). A volume is exported as a
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * full disk as long as the "slice" option is not specified.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre if (vd->vdisk_type == VD_DISK_TYPE_DISK) {
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre /* setup disk image */
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre if (dk_cinfo.dki_partition == VD_ENTIRE_DISK_SLICE ||
047ba61eb972395c8952e47676eefbb616aceec3achartre * Export a single slice disk.
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * The exported device can be either a volume device or a disk slice. If
047ba61eb972395c8952e47676eefbb616aceec3achartre * it is a disk slice different from slice 2 then it is always exported
047ba61eb972395c8952e47676eefbb616aceec3achartre * as a single slice disk even if the "slice" option is not specified.
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * If it is disk slice 2 or a volume device then it is exported as a
047ba61eb972395c8952e47676eefbb616aceec3achartre * single slice disk only if the "slice" option is specified.
047ba61eb972395c8952e47676eefbb616aceec3achartre * We export the slice as a single slice disk even if the "slice"
047ba61eb972395c8952e47676eefbb616aceec3achartre * option was not specified.
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China /* Get size of backing device */
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China if ((status = vd_backend_check_size(vd)) != 0) {
cc446bab4d3331e782fa29c34006ed7694138452Alexandre Chartre PRN("Check size failed for %s (errno %d)", device_path, status);
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China return (EIO);
edcc07547a39d6570197493a9836083bd6b2a197achartre * When exporting a slice or a device as a single slice disk, we don't
edcc07547a39d6570197493a9836083bd6b2a197achartre * care about any partitioning exposed by the backend. The goal is just
edcc07547a39d6570197493a9836083bd6b2a197achartre * to export the backend as a flat storage. We provide a fake partition
edcc07547a39d6570197493a9836083bd6b2a197achartre * table (either a VTOC or EFI), which presents only one slice, to
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * accommodate tools expecting a disk label. The selection of the label
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * type (VTOC or EFI) depends on the value of the vd_slice_label
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre * variable.
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vd->vdisk_size >= ONE_TERABYTE / vd->vdisk_bsize) {
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty status = ldi_ioctl(vd->ldi_handle[0], DKIOCGEXTVTOC,
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty /* try with the non-extended vtoc ioctl */
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty status = ldi_ioctl(vd->ldi_handle[0], DKIOCGVTOC,
342440ec94087b8c751c580ab9ed6c693d31d418Prasad Singamsetty (intptr_t)&vtoc, (vd->open_flags | FKIOCTL),
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre (intptr_t)&vd->dk_geom, (vd->open_flags | FKIOCTL),
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vd_build_default_label(vd->vdisk_size * vd->vdisk_bsize,
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vd->vdisk_bsize, &label);
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre vd_label_to_vtocgeom(&label, &vd->vtoc, &vd->dk_geom);
edcc07547a39d6570197493a9836083bd6b2a197achartre /* export with a fake VTOC label */
edcc07547a39d6570197493a9836083bd6b2a197achartre /* export with a fake EFI label */
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * This function is invoked when setting up the vdisk backend and to process
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * the VD_OP_GET_CAPACITY operation. It checks the backend size and set the
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * following attributes of the vd structure:
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * - vdisk_bsize: block size for the virtual disk used by the VIO protocol. Its
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * value is 512 bytes (DEV_BSIZE) when the backend is a file, a volume or a
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * CD/DVD. When the backend is a disk or a disk slice then it has the value
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * of the logical block size of that disk (as returned by the DKIOCGMEDIAINFO
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * ioctl). This block size is expected to be a power of 2 and a multiple of
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * - vdisk_size: size of the virtual disk expressed as a number of vdisk_bsize
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * vdisk_size and vdisk_bsize are sent to the vdisk client during the connection
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * handshake and in the result of a VD_OP_GET_CAPACITY operation.
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * - backend_bsize: block size of the backend device. backend_bsize has the same
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * value as vdisk_bsize except when the backend is a CD/DVD. In that case,
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * vdisk_bsize is set to 512 (DEV_BSIZE) while backend_bsize is set to the
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * effective logical block size of the CD/DVD (usually 2048).
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * - dskimg_size: size of the backend when the backend is a disk image. This
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * attribute is set only when the backend is a file or a volume, otherwise it
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * is unused.
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * - vio_bshift: number of bit to shift to convert a VIO block number (which
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * uses a block size of vdisk_bsize) to a buf(9s) block number (which uses a
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * block size of 512 bytes) i.e. we have vdisk_bsize = 512 x 2 ^ vio_bshift
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * - vdisk_media: media of the virtual disk. This function only sets this
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * attribute for physical disk and CD/DVD. For other backend types, this
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * attribute is set in the setup function of the backend.
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China size_t backend_size, backend_bsize, vdisk_bsize;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China size_t old_size, new_size;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China int rval, rv, media, nshift = 0;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China uint32_t n;
de3a53312897a4ba0d450636226db584e8b09648Ramesh Chitrothu /* file (slice or full disk) */
de3a53312897a4ba0d450636226db584e8b09648Ramesh Chitrothu rv = VOP_GETATTR(vd->file_vnode, &vattr, 0, kcred, NULL);
de3a53312897a4ba0d450636226db584e8b09648Ramesh Chitrothu PR0("VOP_GETATTR(%s) = errno %d", vd->device_path, rv);
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China backend_bsize = DEV_BSIZE;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vdisk_bsize = DEV_BSIZE;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China } else if (vd->volume) {
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China /* volume (slice or full disk) */
de3a53312897a4ba0d450636226db584e8b09648Ramesh Chitrothu rv = ldi_get_size(vd->ldi_handle[0], &backend_size);
de3a53312897a4ba0d450636226db584e8b09648Ramesh Chitrothu PR0("ldi_get_size() failed for %s", vd->device_path);
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China backend_bsize = DEV_BSIZE;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vdisk_bsize = DEV_BSIZE;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China /* physical disk or slice */
de3a53312897a4ba0d450636226db584e8b09648Ramesh Chitrothu rv = ldi_ioctl(vd->ldi_handle[0], DKIOCGMEDIAINFO,
de3a53312897a4ba0d450636226db584e8b09648Ramesh Chitrothu (intptr_t)&minfo, (vd->open_flags | FKIOCTL),
de3a53312897a4ba0d450636226db584e8b09648Ramesh Chitrothu PR0("DKIOCGMEDIAINFO failed for %s (err=%d)",
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China if (vd->vdisk_type == VD_DISK_TYPE_SLICE) {
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China rv = ldi_get_size(vd->ldi_handle[0], &backend_size);
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China if (rv != DDI_SUCCESS) {
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China PR0("ldi_get_size() failed for %s",
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vd->device_path);
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China return (EIO);
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China ASSERT(vd->vdisk_type == VD_DISK_TYPE_DISK);
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China backend_size = minfo.dki_capacity * minfo.dki_lbsize;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China backend_bsize = minfo.dki_lbsize;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China media = DK_MEDIATYPE2VD_MEDIATYPE(minfo.dki_media_type);
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * If the device is a CD or a DVD then we force the vdisk block
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * size to 512 bytes (DEV_BSIZE). In that case, vdisk_bsize can
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China * be different from backend_size.
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China if (media == VD_MEDIA_CD || media == VD_MEDIA_DVD)
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vdisk_bsize = DEV_BSIZE;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vdisk_bsize = backend_bsize;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China /* check vdisk block size */
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China if (vdisk_bsize == 0 || vdisk_bsize % DEV_BSIZE != 0)
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China return (EINVAL);
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China new_size = backend_size / vdisk_bsize;
de3a53312897a4ba0d450636226db584e8b09648Ramesh Chitrothu /* check if size has changed */
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China if (old_size != VD_SIZE_UNKNOWN && old_size == new_size &&
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vd->vdisk_bsize == vdisk_bsize)
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China /* cache info for blk conversion */
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China for (n = vdisk_bsize / DEV_BSIZE; n > 1; n >>= 1) {
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China if ((n & 0x1) != 0) {
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China /* blk_size is not a power of 2 */
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China return (EINVAL);
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vd->vio_bshift = nshift;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vd->vdisk_bsize = vdisk_bsize;
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vd->backend_bsize = backend_bsize;
de3a53312897a4ba0d450636226db584e8b09648Ramesh Chitrothu * If we are exporting a single-slice disk and the size of the backend
de3a53312897a4ba0d450636226db584e8b09648Ramesh Chitrothu * has changed then we regenerate the partition setup so that the
de3a53312897a4ba0d450636226db584e8b09648Ramesh Chitrothu * partitioning matches with the new disk backend size.
de3a53312897a4ba0d450636226db584e8b09648Ramesh Chitrothu if (vd->vdisk_type == VD_DISK_TYPE_SLICE) {
de3a53312897a4ba0d450636226db584e8b09648Ramesh Chitrothu /* slice or file or device exported as a slice */
de3a53312897a4ba0d450636226db584e8b09648Ramesh Chitrothu if (vd->vdisk_label == VD_DISK_LABEL_VTOC) {
de3a53312897a4ba0d450636226db584e8b09648Ramesh Chitrothu PR0("vd_setup_partition_vtoc() failed for %s "
de3a53312897a4ba0d450636226db584e8b09648Ramesh Chitrothu PR0("vd_setup_partition_efi() failed for %s "
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre /* physical disk */
de3a53312897a4ba0d450636226db584e8b09648Ramesh Chitrothu ASSERT(vd->vdisk_type == VD_DISK_TYPE_DISK);
65908c77dfc02644236ba18bffe67b5ed6f23135yu, larry liu - Sun Microsystems - Beijing China vd->vdisk_media = media;
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * Description:
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * Open a device using its device path and identify if this is
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * a disk device or a volume device.
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * Parameters:
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * vd - pointer to structure containing the vDisk info
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * dtype - return the driver type of the device
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * Return Value
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * 0 - success
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * != 0 - some other non-zero return value from ldi(9F) functions
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre status = vd_open_using_ldi_by_name(vd, vd->open_flags & ~FWRITE);
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre PR0("Failed to open (%s) = errno %d", device_path, status);
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre /* Get device number of backing device */
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre if ((status = ldi_get_dev(vd->ldi_handle[0], &vd->dev[0])) != 0) {
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * We start by looking if the driver is in the list from vds.conf
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * so that we can override the built-in list using vds.conf.
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre drv_name = ddi_major_to_name(getmajor(vd->dev[0]));
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre /* check vds.conf list */
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre if (vds->driver_types[i].type == VD_DRIVER_UNKNOWN) {
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre /* ignore invalid entries */
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre if (strcmp(drv_name, vds->driver_types[i].name) == 0) {
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre /* check built-in list */
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre for (i = 0; i < VDS_NUM_DRIVERS; i++) {
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre if (strcmp(drv_name, vds_driver_types[i].name) == 0) {
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre (drv_type == VD_DRIVER_VOLUME)? "VOLUME" : "UNKNOWN");
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre return (0);
047ba61eb972395c8952e47676eefbb616aceec3achartre /* make sure the vdisk backend is valid */
047ba61eb972395c8952e47676eefbb616aceec3achartre * Backend is a file so it is exported as a full disk or as a
047ba61eb972395c8952e47676eefbb616aceec3achartre * single slice disk using the vnode interface.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * Backend is a device. In that case, it is exported using the
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * LDI interface, and it is exported either as a single-slice
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * disk or as a full disk depending on the "slice" option and
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * on the type of device.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * - A volume device is exported as a single-slice disk if the
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * "slice" is specified, otherwise it is exported as a full
047ba61eb972395c8952e47676eefbb616aceec3achartre * - A disk slice (different from slice 2) is always exported
047ba61eb972395c8952e47676eefbb616aceec3achartre * as a single slice disk using the LDI interface.
047ba61eb972395c8952e47676eefbb616aceec3achartre * - The slice 2 of a disk is exported as a single slice disk
047ba61eb972395c8952e47676eefbb616aceec3achartre * if the "slice" option is specified, otherwise the entire
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * disk will be exported.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * - The slice of a CD or DVD is exported as single slice disk
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * if the "slice" option is specified, otherwise the entire
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre * disk will be exported.
047ba61eb972395c8952e47676eefbb616aceec3achartre /* check if this is a pseudo device */
047ba61eb972395c8952e47676eefbb616aceec3achartre if ((dip = ddi_hold_devi_by_instance(getmajor(vnp->v_rdev),
d753835af57c7904d74f55a1251a643a5ddc47d1Zach Kissel if ((status = vd_identify_dev(vd, &drv_type)) != 0) {
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * If the driver hasn't been identified then we consider that
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * pseudo devices are volumes and other devices are disks.
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * If this is a volume device then its usage depends if the
047ba61eb972395c8952e47676eefbb616aceec3achartre * "slice" option is set or not. If the "slice" option is set
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * then the volume device will be exported as a single slice,
047ba61eb972395c8952e47676eefbb616aceec3achartre * otherwise it will be exported as a full disk.
2f5224ae5d04383463098ad866ccee0464ee6429achartre * For backward compatibility, if vd_volume_force_slice is set
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * then we always export volume devices as slices.
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre if (vd->volume && vd_volume_force_slice) {
047ba61eb972395c8952e47676eefbb616aceec3achartre * If the error is retryable print an error message only
047ba61eb972395c8952e47676eefbb616aceec3achartre * during the first try.
047ba61eb972395c8952e47676eefbb616aceec3achartre /* print a message only if we previously had an error */
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * For file or ZFS volume we also need an I/O queue.
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * The I/O task queue is initialized here and not in vds_do_init_vd()
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * (as the start and completion queues) because vd_setup_vd() will be
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * call again if the backend is not available, and we need to know if
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre * the backend is a ZFS volume or a file.
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre if ((vd->file || vd->zvol) && vd->ioq == NULL) {
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre (void) snprintf(tq_name, sizeof (tq_name), "vd_ioq%lu", vd->id);
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre if ((vd->ioq = ddi_taskq_create(vd->vds->dip, tq_name,
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre vd_ioq_nthreads, TASKQ_DEFAULTPRI, 0)) == NULL) {
047ba61eb972395c8952e47676eefbb616aceec3achartrevds_do_init_vd(vds_t *vds, uint64_t id, char *device_path, uint64_t options,
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);
047ba61eb972395c8952e47676eefbb616aceec3achartre /* Setup open flags */
047ba61eb972395c8952e47676eefbb616aceec3achartre /* Setup disk type */
047ba61eb972395c8952e47676eefbb616aceec3achartre /* default disk label */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm /* Open vdisk and initialize parameters */
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre PR0("vdisk_type = %s, volume = %s, file = %s, nslices = %u",
3c96341aef2b4da56c902941f089284b52bd573fnarayan ((vd->vdisk_type == VD_DISK_TYPE_DISK) ? "disk" : "slice"),
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre (vd->volume ? "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,
5b98b50905ca1ba7dd1e3c1d6e0a4f8460cc1b9fachartre /* Allocate the staging buffer */
5b98b50905ca1ba7dd1e3c1d6e0a4f8460cc1b9fachartre vd->max_msglen = sizeof (vio_msg_t); /* baseline vio message size */
5b98b50905ca1ba7dd1e3c1d6e0a4f8460cc1b9fachartre vd->vio_msgp = kmem_alloc(vd->max_msglen, KM_SLEEP);
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 /* store initial state */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0);
3af08d828975d7e2581b6829e0eecff14d87a483lmstatic void
3af08d828975d7e2581b6829e0eecff14d87a483lm /* Free all dring_task memory handles */
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre kmem_free(vdp->write_queue, sizeof (buf_t *) * vdp->dring_len);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Destroy the state associated with a virtual disk
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Disable queuing requests for the vdisk */
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre /* Drain and destroy start queue (*before* destroying ioq) */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan ddi_taskq_destroy(vd->startq); /* waits for queued tasks */
83990c4a302edc9e3a11572b2cc7cce78f2c8f89Alexandre Chartre /* Drain and destroy the I/O queue (*before* destroying completionq) */
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 */
047ba61eb972395c8952e47676eefbb616aceec3achartre (void) VOP_CLOSE(vd->file_vnode, vd->open_flags, 1,
690555a1dfb3e9c3b00be26ece1988ed10a6fbe5achartre /* Close any open backing-device slices */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre for (uint_t slice = 0; slice < V_NUMPAR; slice++) {
1aff8f07c7bb7f79d8c2363db21c57e53d5df2daAlexandre Chartre /* Free disk image devid */
bae9e67e8dfdee5278f9707cf885b7c8ebeba79fachartre /* Free any fake label */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Free lock */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Finally, free the vdisk structure itself */
047ba61eb972395c8952e47676eefbb616aceec3achartrevds_init_vd(vds_t *vds, uint64_t id, char *device_path, uint64_t options,
047ba61eb972395c8952e47676eefbb616aceec3achartre if ((status = vds_do_init_vd(vds, id, device_path, options,
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);
047ba61eb972395c8952e47676eefbb616aceec3achartre * Function:
047ba61eb972395c8952e47676eefbb616aceec3achartre * vds_get_options
047ba61eb972395c8952e47676eefbb616aceec3achartre * Description:
047ba61eb972395c8952e47676eefbb616aceec3achartre * Parse the options of a vds node. Options are defined as an array
047ba61eb972395c8952e47676eefbb616aceec3achartre * of strings in the vds-block-device-opts property of the vds node
047ba61eb972395c8952e47676eefbb616aceec3achartre * in the machine description. Options are returned as a bitmask. The
047ba61eb972395c8952e47676eefbb616aceec3achartre * mapping between the bitmask options and the options strings from the
047ba61eb972395c8952e47676eefbb616aceec3achartre * machine description is defined in the vd_bdev_options[] array.
047ba61eb972395c8952e47676eefbb616aceec3achartre * The vds-block-device-opts property is optional. If a vds has no such
047ba61eb972395c8952e47676eefbb616aceec3achartre * property then no option is defined.
047ba61eb972395c8952e47676eefbb616aceec3achartre * Parameters:
047ba61eb972395c8952e47676eefbb616aceec3achartre * md - machine description.
047ba61eb972395c8952e47676eefbb616aceec3achartre * vd_node - vds node in the machine description for which
047ba61eb972395c8952e47676eefbb616aceec3achartre * options have to be parsed.
047ba61eb972395c8952e47676eefbb616aceec3achartre * options - the returned options.
047ba61eb972395c8952e47676eefbb616aceec3achartre * Return Code:
047ba61eb972395c8952e47676eefbb616aceec3achartrevds_get_options(md_t *md, mde_cookie_t vd_node, uint64_t *options)
047ba61eb972395c8952e47676eefbb616aceec3achartre if (md_get_prop_data(md, vd_node, VD_BLOCK_DEVICE_OPTS,
047ba61eb972395c8952e47676eefbb616aceec3achartre /* parse options */
047ba61eb972395c8952e47676eefbb616aceec3achartre n = sizeof (vd_bdev_options) / sizeof (vd_option_t);
047ba61eb972395c8952e47676eefbb616aceec3achartre for (i = 0; i < n; i++) {
047ba61eb972395c8952e47676eefbb616aceec3achartre if (i < n) {
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre kmem_free(vds->driver_types, sizeof (vd_driver_type_t) *
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * Update the driver type list with information from vds.conf.
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, vds->dip,
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre DDI_PROP_DONTPASS, "driver-type-list", &list, &num) !=
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * We create a driver_types list with as many as entries as there
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * is in the driver-type-list from vds.conf. However only valid
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * entries will be populated (i.e. entries from driver-type-list
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * with a valid syntax). Invalid entries will be left blank so
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * they will have no driver name and the driver type will be
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre * VD_DRIVER_UNKNOWN (= 0).
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre vds->driver_types = kmem_zalloc(sizeof (vd_driver_type_t) * num,
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre for (i = 0; i < num; i++) {
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre if (s == NULL) {
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre "a colon is expected in the entry",
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre if (len == 0) {
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre "the driver name is empty",
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre "the driver name is too long",
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre "the driver type is invalid",
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre (void) strncpy(vds->driver_types[i].name, list[i], len);
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre /* nothing was added, clean up */
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);
047ba61eb972395c8952e47676eefbb616aceec3achartre if (vds_init_vd(vds, id, device_path, options, ldc_id) != 0) {
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm if (mod_hash_destroy(vds->vd_table, (mod_hash_key_t)id) != 0)
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,
047ba61eb972395c8952e47676eefbb616aceec3achartre uint64_t curr_id = 0, curr_ldc_id = 0, curr_options = 0;
047ba61eb972395c8952e47676eefbb616aceec3achartre uint64_t prev_id = 0, prev_ldc_id = 0, prev_options = 0;
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 */
047ba61eb972395c8952e47676eefbb616aceec3achartre /* Validate that options have not changed */
047ba61eb972395c8952e47676eefbb616aceec3achartre vds_get_options(prev_md, prev_vd_node, &prev_options);
047ba61eb972395c8952e47676eefbb616aceec3achartre vds_get_options(curr_md, curr_vd_node, &curr_options);
047ba61eb972395c8952e47676eefbb616aceec3achartre PRN("Not changing vdisk: options changed from %lx to %lx",
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 */
047ba61eb972395c8952e47676eefbb616aceec3achartre if (vds_init_vd(vds, curr_id, curr_dev, curr_options,
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) !=
8fce2fd6e90ed9f282bb13d9bf5be9648b8421e0achartre /* read any user defined driver types from conf file and update list */
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 return (0);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (0);