/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Pipe I/O Backend
*
* In order to implement dcmd pipelines, we provide a pipe i/o backend that
* can be used to connect two mdb_iob structures (a read and write end).
* This backend is selected when mdb_iob_pipe is used to construct a pair of
* iobs. Each iob points at the same i/o backend (the pipe i/o), and the
* backend manages a circular fixed-size buffer which moves data between
* the reader and writer. The caller provides read and write-side service
* routines that are expected to perform context switching (see mdb_context.c).
* The pipe implementation is relatively simple: the writer calls any of the
* mdb_iob_* routines to fill the write-side iob, and when this iob needs to
* flush data to the underlying i/o, pio_write() below is called. This
* routine copies data into the pipe buffer until no more free space is
* available, and then calls the read-side service routine (presuming that
* when it returns, more free space will be available). On the read-side,
* pio_read() copies data up from the pipe buffer into the read-side iob.
* If pio_read() is called and the pipe buffer is empty, pio_read() calls
* the write-side service routine to force the writer to produce more data.
*/
#include <sys/sysmacros.h>
#include <stropts.h>
#include <limits.h>
#include <mdb/mdb_modapi.h>
#include <mdb/mdb_debug.h>
#include <mdb/mdb_string.h>
#include <mdb/mdb_context.h>
#include <mdb/mdb_io_impl.h>
#include <mdb/mdb_frame.h>
typedef struct pipe_data {
} pipe_data_t;
static ssize_t
{
if (nbytes == 0)
return (0); /* return 0 for zero-length read */
}
break;
}
/*
* Case 1: The amount to read overlaps the end of the
* circular buffer. 'n1' will be the amount to copy
* from the end of the buffer, and 'n2' will be the
* amount to copy from the beginning. Note that since
* n <= pipe_used, it is impossible to read past
* pipe_wrndx into undefined territory.
*/
} else {
/*
* Case 2: The easy case. Simply copy the data over
* to the buffer.
*/
}
}
/*
* If we have a writer, but pipe_wrsvc failed to produce any data,
* we return EAGAIN. If there is no writer, then return 0 for EOF.
*/
else
return (0);
}
}
static ssize_t
{
break; /* if nothing consumed by reader, exit */
}
/*
* Case 1: The data will overlap the circular buffer
* boundary. In this case, 'n1' will be the number of
* bytes to put at the end of the buffer, and 'n2' will
* be the number of bytes to put at the beginning.
* Note that since n <= pipe_free, it is impossible to
* overlap rdndx with the initial data.
*/
} else {
/*
* Case 2: The easy case. Simply copy the data into
* the buffer.
*/
}
}
}
/*
* Provide support for STREAMS-style write-side flush ioctl. This can be
* used by the caller to force a context switch to the read-side.
*/
static int
{
return (0);
}
static void
{
}
/*ARGSUSED*/
static const char *
{
return ("(pipeline)");
}
static void
{
/*
* Here we take advantage of the IOP_LINK calls made to associate each
* i/o backend with its iob to determine our read and write iobs.
*/
else
} else
}
static void
{
/*
* The IOP_UNLINK call will be made when one of our associated iobs is
* destroyed. If the read-side iob is being destroyed, we simply set
* pipe_rdiob to NULL, forcing subsequent pio_write() calls to fail
* with EPIPE. Things are more complicated when the write-side is
* being destroyed. If this is the last close prior to destroying the
* pipe, we need to arrange for any in-transit data to be consumed by
* the reader. We first set pipe_wriob to NULL, which forces pio_read
* to return EOF when all in-transit data is consumed. We then call
* the read-service routine while there is still a reader and pipe_used
* is non-zero, indicating there is still data in the pipe.
*/
return; /* no reader and nothing to read */
/*
* Note that we need to use a do-while construct here
* so that we resume the reader's context at *least*
* once. This forces it to read EOF and exit even if
* the pipeline is already completely flushed.
*/
do {
break;
}
break; /* don't read if error bit set */
}
}
}
} else
}
};
mdb_io_t *
{
return (io);
}
int
{
return (1);
}
return (0);
}