fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
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 *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
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 *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/types.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ksynch.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/errno.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/uio.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include <sys/ddi.h>
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define __NSC_GEN__
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "nsc_dev.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#ifdef DS_DDICT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "../contract.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "../nsctl.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#define _I(x) (((long)(&((nsc_io_t *)0)->x))/sizeof (long))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_def_t _nsc_cache_def[] = {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "AllocBuf", (uintptr_t)nsc_ioerr, _I(alloc_buf),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "FreeBuf", (uintptr_t)nsc_fatal, _I(free_buf),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Read", (uintptr_t)nsc_fatal, _I(read),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Write", (uintptr_t)nsc_fatal, _I(write),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Zero", (uintptr_t)nsc_fatal, _I(zero),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Copy", (uintptr_t)nsc_ioerr, _I(copy),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "CopyDirect", (uintptr_t)nsc_ioerr, _I(copy_direct),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Uncommit", (uintptr_t)nsc_null, _I(uncommit),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "AllocHandle", (uintptr_t)nsc_null, _I(alloc_h),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "FreeHandle", (uintptr_t)nsc_fatal, _I(free_h),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "TrackSize", (uintptr_t)nsc_null, _I(trksize),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Discard", (uintptr_t)nsc_null, _I(discard),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Sizes", (uintptr_t)nsc_null, _I(sizes),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "GetPinned", (uintptr_t)nsc_null, _I(getpin),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "NodeHints", (uintptr_t)nsc_inval, _I(nodehints),
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte 0, 0, 0
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte};
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _nsc_alloc_buf_h(blind_t, nsc_off_t, nsc_size_t, int,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_buf_t **, nsc_fd_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int _nsc_copy_h(nsc_buf_t *, nsc_buf_t *, nsc_off_t,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t, nsc_size_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern nsc_io_t *_nsc_reserve_io(char *, int);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void _nsc_release_io(nsc_io_t *);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern kmutex_t _nsc_io_lock;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_nsc_add_cache(nsc_io_t *io)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_buf_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_alloc_handle(nsc_fd_t *fd, void (*d_cb)(), void (*r_cb)(), void (*w_cb)())
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_buf_t *h = (*fd->sf_aio->alloc_h)(d_cb, r_cb, w_cb, fd->sf_cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (h)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte h->sb_fd = fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (h);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_free_handle(nsc_buf_t *h)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (h == NULL || (h->sb_flag & NSC_ABUF))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((*h->sb_fd->sf_aio->free_h)(h, h->sb_fd->sf_cd));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_alloc_abuf(nsc_off_t pos, nsc_size_t len, int flag, nsc_buf_t **ptr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_buf_t *h;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_io_t *io;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*ptr != NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & NSC_NODATA)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io = _nsc_reserve_io(NULL, NSC_ANON);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (io == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENOBUFS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((h = (*io->alloc_h)(NULL, NULL, NULL, NSC_ANON_CD)) == NULL) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _nsc_release_io(io);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENOBUFS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = (*io->alloc_buf)(NSC_ANON_CD, pos, len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NSC_NOCACHE|flag, &h, NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc <= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte h->sb_flag &= ~NSC_HALLOCATED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte h->sb_flag |= NSC_ABUF;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte h->sb_fd = (nsc_fd_t *)io; /* note overloaded field */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *ptr = h;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_nsc_io_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io->abufcnt++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_nsc_io_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _nsc_release_io(io);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_alloc_buf(nsc_fd_t *fd, nsc_off_t pos, nsc_size_t len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int flag, nsc_buf_t **ptr)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int (*fn)() = _nsc_alloc_buf_h;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((fd->sf_avail & NSC_WRITE) == 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (flag & NSC_WRBUF)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EACCES);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((flag & (NSC_READ|NSC_WRITE|NSC_NODATA)) ==
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (NSC_READ|NSC_NODATA)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * NSC_NODATA access checks.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - NSC_READ|NSC_NODATA is illegal since there would
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * be no data buffer to immediately read the data into.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - NSC_WRITE|NSC_NODATA is valid since the client can
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * provide the buffer and then call nsc_write() as
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * necessary.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * - NSC_NODATA is valid since the client can provide the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * buffer and then call nsc_read() or nsc_write() as
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * necessary.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EACCES);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (*ptr) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fn = fd->sf_aio->alloc_buf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*ptr)->sb_fd = fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (*fn)(fd->sf_cd, pos, len, flag, ptr, fd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* ARGSUSED */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_nsc_alloc_buf_h(blind_t cd, nsc_off_t pos, nsc_size_t len,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int flag, nsc_buf_t **ptr, nsc_fd_t *fd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_buf_t *h;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(h = nsc_alloc_handle(fd, NULL, NULL, NULL)))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (ENOBUFS);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((rc = nsc_alloc_buf(fd, pos, len, flag, &h)) <= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte h->sb_flag &= ~NSC_HALLOCATED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *ptr = h;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) nsc_free_handle(h);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_read(nsc_buf_t *h, nsc_off_t pos, nsc_size_t len, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((h->sb_flag & NSC_ABUF) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((h->sb_flag & NSC_NODATA) && h->sb_vec == NULL))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((*h->sb_fd->sf_aio->read)(h, pos, len, flag));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_write(nsc_buf_t *h, nsc_off_t pos, nsc_size_t len, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((h->sb_flag & NSC_ABUF) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((h->sb_flag & NSC_NODATA) && h->sb_vec == NULL))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((*h->sb_fd->sf_aio->write)(h, pos, len, flag));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_zero(nsc_buf_t *h, nsc_off_t pos, nsc_size_t len, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((h->sb_flag & NSC_ABUF) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((h->sb_flag & NSC_NODATA) && h->sb_vec == NULL))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((*h->sb_fd->sf_aio->zero)(h, pos, len, flag));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_copy(nsc_buf_t *h1, nsc_buf_t *h2, nsc_off_t pos1,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t pos2, nsc_size_t len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_io_t *io1, *io2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = EIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((h1->sb_flag & NSC_NODATA) && h1->sb_vec == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((h2->sb_flag & NSC_NODATA) && h2->sb_vec == NULL))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (h1->sb_fd && h2->sb_fd) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io1 = (h1->sb_flag & NSC_ABUF) ?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (nsc_io_t *)h1->sb_fd : h1->sb_fd->sf_aio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io2 = (h2->sb_flag & NSC_ABUF) ?
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (nsc_io_t *)h2->sb_fd : h2->sb_fd->sf_aio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (io1 == io2)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = (*io1->copy)(h1, h2, pos1, pos2, len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc != EIO)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (_nsc_copy_h(h1, h2, pos1, pos2, len));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic int
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte_nsc_copy_h(nsc_buf_t *h1, nsc_buf_t *h2, nsc_off_t pos1,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t pos2, nsc_size_t len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_vec_t *v1, *v2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uchar_t *a1, *a2;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int sz, l1, l2, lenbytes; /* byte sizes within an nsc_vec_t */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pos1 < h1->sb_pos || pos1 + len > h1->sb_pos + h1->sb_len ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pos2 < h2->sb_pos || pos2 + len > h2->sb_pos + h2->sb_len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* find starting point in "from" vector */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte v1 = h1->sb_vec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pos1 -= h1->sb_pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; pos1 >= FBA_NUM(v1->sv_len); v1++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pos1 -= FBA_NUM(v1->sv_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte a1 = v1->sv_addr + FBA_SIZE(pos1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte l1 = v1->sv_len - FBA_SIZE(pos1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* find starting point in "to" vector */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte v2 = h2->sb_vec;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pos2 -= h2->sb_pos;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (; pos2 >= FBA_NUM(v2->sv_len); v2++)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pos2 -= FBA_NUM(v2->sv_len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte a2 = v2->sv_addr + FBA_SIZE(pos2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte l2 = v2->sv_len - FBA_SIZE(pos2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* copy required data */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ASSERT(FBA_SIZE(len) < INT_MAX);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lenbytes = (int)FBA_SIZE(len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while (lenbytes) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sz = min(l1, l2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sz = min(sz, lenbytes);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bcopy(a1, a2, sz);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte l1 -= sz; l2 -= sz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte a1 += sz; a2 += sz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte lenbytes -= sz;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!l1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte a1 = (++v1)->sv_addr, l1 = v1->sv_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!l2)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte a2 = (++v2)->sv_addr, l2 = v2->sv_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_copy_direct(nsc_buf_t *h1, nsc_buf_t *h2, nsc_off_t pos1,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_off_t pos2, nsc_size_t len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc = EIO;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!h1 || !h2)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EINVAL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (((h1->sb_flag & NSC_NODATA) && h1->sb_vec == NULL) ||
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ((h2->sb_flag & NSC_NODATA) && h2->sb_vec == NULL))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((h2->sb_flag & NSC_RDWR) != NSC_WRITE) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "nsc_copy_direct: h2 (%p) flags (%x) include NSC_READ",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void *)h2, h2->sb_flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((h2->sb_flag & NSC_WRTHRU) == 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmn_err(CE_WARN,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "nsc_copy_direct: h2 (%p) flags (%x) do not "
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "include NSC_WRTHRU", (void *)h2, h2->sb_flag);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte h2->sb_flag |= NSC_WRTHRU;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (h1->sb_fd && h2->sb_fd && h1->sb_fd->sf_aio == h2->sb_fd->sf_aio)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = (*h1->sb_fd->sf_aio->copy_direct)(h1, h2, pos1, pos2, len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc != EIO)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The slow way ...
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_copy(h1, h2, pos1, pos2, len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rc <= 0)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = nsc_write(h2, pos2, len, NSC_WRTHRU);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_uncommit(nsc_buf_t *h, nsc_off_t pos, nsc_size_t len, int flag)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (h->sb_flag & NSC_ABUF)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (EIO);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return ((*h->sb_fd->sf_aio->uncommit)(h, pos, len, flag));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_free_buf(nsc_buf_t *h)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_io_t *io;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int abuf;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int rc;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (h == NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (0);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if ((h->sb_flag & NSC_NODATA) && (h->sb_vec != NULL)) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte h->sb_vec = NULL;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte abuf = (h->sb_flag & NSC_ABUF);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (abuf)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io = (nsc_io_t *)h->sb_fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io = h->sb_fd->sf_aio;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rc = (*io->free_buf)(h);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (abuf && rc <= 0) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&_nsc_io_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte io->abufcnt--;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&_nsc_io_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_node_hints(uint_t *hints)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (_nsc_call_io(_I(nodehints), (blind_t)hints,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (blind_t)NSC_GET_NODE_HINT, 0));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_node_hints_set(uint_t hints)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (_nsc_call_io(_I(nodehints), (blind_t)(unsigned long)hints,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (blind_t)NSC_SET_NODE_HINT, 0));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_cache_sizes(int *asize, int *wsize)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (_nsc_call_io(_I(sizes), (blind_t)asize, (blind_t)wsize, 0));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_set_trksize(nsc_fd_t *fd, nsc_size_t trsize)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (*fd->sf_aio->trksize)(fd->sf_cd, trsize);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_get_pinned(nsc_fd_t *fd)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (*fd->sf_aio->getpin)(fd->sf_cd);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteint
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_discard_pinned(nsc_fd_t *fd, nsc_off_t pos, nsc_size_t len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (*fd->sf_aio->discard)(fd->sf_cd, pos, len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_pinned_data(nsc_iodev_t *iodev, nsc_off_t pos, nsc_size_t len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_fd_t *fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!iodev)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&iodev->si_dev->nsc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iodev->si_busy++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&iodev->si_dev->nsc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (fd = iodev->si_open; fd; fd = fd->sf_next)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fd->sf_avail & _NSC_ATTACH)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*fd->sf_pinned)(fd->sf_arg, pos, len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _nsc_wake_dev(iodev->si_dev, &iodev->si_busy);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortevoid
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortensc_unpinned_data(nsc_iodev_t *iodev, nsc_off_t pos, nsc_size_t len)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte nsc_fd_t *fd;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!iodev)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_enter(&iodev->si_dev->nsc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte iodev->si_busy++;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte mutex_exit(&iodev->si_dev->nsc_lock);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte for (fd = iodev->si_open; fd; fd = fd->sf_next)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (fd->sf_avail & _NSC_ATTACH)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*fd->sf_unpinned)(fd->sf_arg, pos, len);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte _nsc_wake_dev(iodev->si_dev, &iodev->si_busy);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte}