NAME
bufq_init
,
bufq_switch
, bufq_destroy
,
bufq_queue
, bufq_dequeue
,
bufq_requeue
, bufq_peek
,
bufq_drain
—
buf queues
SYNOPSIS
#include
<sys/buf.h>
int
bufq_init
(struct
bufq *bufq, int
type);
int
bufq_switch
(struct
bufq *bufq, int
type);
void
bufq_destroy
(struct
bufq *bufq);
void
bufq_queue
(struct
bufq *bufq, struct buf
*bp);
struct buf *
bufq_dequeue
(struct
bufq *bufq);
void
bufq_requeue
(struct
bufq *bufq, struct buf
*bp);
int
bufq_peek
(struct
bufq *bufq);
void
bufq_drain
(struct
bufq *bufq);
DESCRIPTION
The bufq API implements queueing and scheduling of I/O operations on disk devices. It provides multiple scheduling algorithms within the API.
It is the responsibility of the disk device driver to provide pre-allocated bufq structures.
bufq_init
()
initialises the bufq structure and allocates any state
required by the scheduling algorithm by the type
argument.
bufq_switch
()
can be used to change the scheduler currently used by
bufq to the algorithm specified by
type.
The type argument to
bufq_init
()
and bufq_switch
() can be one of the following
scheduling algorithms:
BUFQ_FIFO
- A simple First-In First-Out queue.
BUFQ_NSCAN
- Takes batches of "N" bufs from the queue and sorts them for optimal head movement.
BUFQ_DEFAULT
- This currently aliases
BUFQ_NSCAN
.
bufq_destroy
()
frees any state that was used by the scheduler.
bufq_queue
()
is used to add the buf specified by bp to the
bufq queue.
bufq_dequeue
()
is used to get the next buf the bufq has scheduled to
be serviced by a disk. The buf will be removed from the queue.
bufq_requeue
()
can be used to return a previously dequeued buf specified by
bp to the head of the queue of
bufq.
bufq_peek
()
allows the caller to determine if there are more bufs queued on
bufq without modifying the list of bufs.
bufq_drain
()
is a convenience function for devices that have detached. It removes all the
bufs currently queued on bufq, marks them as failed
with an ENXIO
error, and returns them to the block
layer via biodone(9).
CONTEXT
bufq_init
(),
bufq_switch
(), and
bufq_destroy
() can be called during autoconf, or
from process context.
bufq_queue
,
bufq_dequeue
, bufq_requeue
,
bufq_peek
, and bufq_drain
can be called during autoconf, from process context, or from interrupt
context.
RETURN VALUES
bufq_init
() and
bufq_switch
() will return 0 on success, or an error
code as per errno(2).
bufq_dequeue
() returns the next buf that
is scheduled to be serviced by the disk. NULL
is
returned if there are no bufs available on the queue.
bufq_peek
() returns 1 if there are bufs
available to be scheduled on the disk, otherwise 0.
SEE ALSO
HISTORY
The bufq API was written by Thordur I. Bjornsson and David Gwynne <dlg@openbsd.org>. The bufq API first appeared in OpenBSD 4.8 and finally succeeded in fully replacing disksort in OpenBSD 5.5.