fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _I(x) (((long)(&((nsc_io_t *)0)->x))/sizeof (long))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _nsc_uread(dev_t, uio_t *, cred_t *, nsc_fd_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _nsc_uwrite(dev_t, uio_t *, cred_t *, nsc_fd_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _nsc_rw_uio(nsc_fd_t *, uio_t *, uio_rw_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _nsc_alloc_dbuf(blind_t, nsc_off_t, nsc_size_t, int, nsc_dbuf_t **);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _nsc_read_dbuf(nsc_dbuf_t *, nsc_off_t, nsc_size_t, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _nsc_write_dbuf(nsc_dbuf_t *, nsc_off_t, nsc_size_t, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _nsc_zero_dbuf(nsc_dbuf_t *, nsc_off_t, nsc_size_t, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _nsc_dbuf_io(int (*)(), nsc_dbuf_t *, nsc_off_t, nsc_size_t, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic nsc_dbuf_t *_nsc_alloc_dhandle(void (*)(), void (*)(), void (*)());
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * _nsc_add_disk (nsc_io_t *io)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Add disk interface functions.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Updates the I/O module with the appropriate
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * interface routines.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Description:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Add functions to the I/O module to provide a disk
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or cache interface as appropriate.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((io->alloc_buf != nsc_ioerr && io->free_buf != nsc_fatal) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (io->write != nsc_fatal || (io->flag & NSC_FILTER)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io->free_h != nsc_fatal || io->alloc_buf != nsc_ioerr ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io->free_buf != nsc_fatal || io->read != nsc_fatal ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (io->uread == nsc_ioerr && io->uwrite == nsc_ioerr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Layer the generic nsc_buf_t provider onto a uio_t provider.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io->alloc_h = (nsc_buf_t *(*)())_nsc_alloc_dhandle;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (*fd->sf_aio->uread)(fd->sf_cd, uiop, crp, fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (*fd->sf_aio->uwrite)(fd->sf_cd, uiop, crp, fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_maxfbas(nsc_fd_t *fd, int flag, nsc_size_t *valp)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (*fd->sf_aio->maxfbas)(fd->sf_cd, flag, valp);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_control(nsc_fd_t *fd, int command, void *argp, int argl)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (*fd->sf_aio->control)(fd->sf_cd, command, argp, argl);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_nsc_uread(dev_t dev, uio_t *uiop, cred_t *crp, nsc_fd_t *fd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_nsc_uwrite(dev_t dev, uio_t *uiop, cred_t *crp, nsc_fd_t *fd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_nsc_rw_uio(nsc_fd_t *fd, uio_t *uiop, uio_rw_t rw)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* prevent non-FBA bounded I/O - this is a disk driver! */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (len > 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (rw == UIO_READ) ? NSC_RDBUF : NSC_WRBUF, &buf)) > 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else if ((rc = nsc_write(buf, pos, buflen, 0)) < 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_nsc_alloc_dhandle(void (*d_cb)(), void (*r_cb)(), void (*w_cb)())
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_kmem_free(h, sizeof (*h));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_nsc_alloc_dbuf(blind_t cd, nsc_off_t pos, nsc_size_t len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (h->db_maxfbas == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else if (h->db_maxfbas == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(h->db_addr = nsc_kmem_alloc(FBA_SIZE(len), KM_SLEEP, 0)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc = _nsc_dbuf_io(nsc_uread, h, pos, len, flag)) != 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* CONSTCOND */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte h->db_flag &= NSC_HALLOCATED; /* clear flags, preserve NSC_HALLOCATED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_nsc_read_dbuf(nsc_dbuf_t *h, nsc_off_t pos, nsc_size_t len, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (_nsc_dbuf_io(nsc_uread, h, pos, len, flag));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_nsc_write_dbuf(nsc_dbuf_t *h, nsc_off_t pos, nsc_size_t len, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (_nsc_dbuf_io(nsc_uwrite, h, pos, len, flag));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_nsc_zero_dbuf(nsc_dbuf_t *h, nsc_off_t pos, nsc_size_t len, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_nsc_dbuf_io(int (*fn)(), nsc_dbuf_t *h, nsc_off_t pos,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_size_t firstentryfix; /* value used for first entry */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pos < h->db_pos || pos + len > h->db_pos + h->db_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(&h->db_iov[0], (_NSC_DBUF_NVEC * sizeof (iovec_t)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * determine where in the vector array we should start.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Loop performing i/o to the underlying driver.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copy up to _NSC_DBUF_NVEC vector entries from the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * nsc_vec_t into the iovec_t so that the number of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * i/o operations is minimised.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(FBA_LEN(vp->sv_len) == FBA_NUM(vp->sv_len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT((vp->sv_len - firstentryfix) && vp->sv_addr);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iovp->iov_base = (caddr_t)vp->sv_addr + firstentryfix;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc != 0) {