Home | History | Annotate | Line # | Download | only in kern
bufq_fcfs.c revision 1.6.72.1
      1  1.6.72.1  yamt /*	$NetBSD: bufq_fcfs.c,v 1.6.72.1 2008/05/18 12:35:06 yamt Exp $	*/
      2       1.1  yamt /*	NetBSD: subr_disk.c,v 1.61 2004/09/25 03:30:44 thorpej Exp 	*/
      3       1.1  yamt 
      4       1.1  yamt /*-
      5       1.1  yamt  * Copyright (c) 1996, 1997, 1999, 2000 The NetBSD Foundation, Inc.
      6       1.1  yamt  * All rights reserved.
      7       1.1  yamt  *
      8       1.1  yamt  * This code is derived from software contributed to The NetBSD Foundation
      9       1.1  yamt  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
     10       1.1  yamt  * NASA Ames Research Center.
     11       1.1  yamt  *
     12       1.1  yamt  * Redistribution and use in source and binary forms, with or without
     13       1.1  yamt  * modification, are permitted provided that the following conditions
     14       1.1  yamt  * are met:
     15       1.1  yamt  * 1. Redistributions of source code must retain the above copyright
     16       1.1  yamt  *    notice, this list of conditions and the following disclaimer.
     17       1.1  yamt  * 2. Redistributions in binary form must reproduce the above copyright
     18       1.1  yamt  *    notice, this list of conditions and the following disclaimer in the
     19       1.1  yamt  *    documentation and/or other materials provided with the distribution.
     20       1.1  yamt  *
     21       1.1  yamt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     22       1.1  yamt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     23       1.1  yamt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     24       1.1  yamt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     25       1.1  yamt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     26       1.1  yamt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     27       1.1  yamt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     28       1.1  yamt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     29       1.1  yamt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     30       1.1  yamt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     31       1.1  yamt  * POSSIBILITY OF SUCH DAMAGE.
     32       1.1  yamt  */
     33       1.1  yamt 
     34       1.1  yamt /*
     35       1.1  yamt  * Copyright (c) 1982, 1986, 1988, 1993
     36       1.1  yamt  *	The Regents of the University of California.  All rights reserved.
     37       1.1  yamt  * (c) UNIX System Laboratories, Inc.
     38       1.1  yamt  * All or some portions of this file are derived from material licensed
     39       1.1  yamt  * to the University of California by American Telephone and Telegraph
     40       1.1  yamt  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
     41       1.1  yamt  * the permission of UNIX System Laboratories, Inc.
     42       1.1  yamt  *
     43       1.1  yamt  * Redistribution and use in source and binary forms, with or without
     44       1.1  yamt  * modification, are permitted provided that the following conditions
     45       1.1  yamt  * are met:
     46       1.1  yamt  * 1. Redistributions of source code must retain the above copyright
     47       1.1  yamt  *    notice, this list of conditions and the following disclaimer.
     48       1.1  yamt  * 2. Redistributions in binary form must reproduce the above copyright
     49       1.1  yamt  *    notice, this list of conditions and the following disclaimer in the
     50       1.1  yamt  *    documentation and/or other materials provided with the distribution.
     51       1.1  yamt  * 3. Neither the name of the University nor the names of its contributors
     52       1.1  yamt  *    may be used to endorse or promote products derived from this software
     53       1.1  yamt  *    without specific prior written permission.
     54       1.1  yamt  *
     55       1.1  yamt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     56       1.1  yamt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     57       1.1  yamt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     58       1.1  yamt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     59       1.1  yamt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     60       1.1  yamt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     61       1.1  yamt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     62       1.1  yamt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     63       1.1  yamt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     64       1.1  yamt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     65       1.1  yamt  * SUCH DAMAGE.
     66       1.1  yamt  *
     67       1.1  yamt  *	@(#)ufs_disksubr.c	8.5 (Berkeley) 1/21/94
     68       1.1  yamt  */
     69       1.1  yamt 
     70       1.1  yamt #include <sys/cdefs.h>
     71  1.6.72.1  yamt __KERNEL_RCSID(0, "$NetBSD: bufq_fcfs.c,v 1.6.72.1 2008/05/18 12:35:06 yamt Exp $");
     72       1.1  yamt 
     73       1.1  yamt #include <sys/param.h>
     74       1.1  yamt #include <sys/systm.h>
     75       1.1  yamt #include <sys/buf.h>
     76       1.2  yamt #include <sys/bufq.h>
     77       1.4  yamt #include <sys/bufq_impl.h>
     78       1.1  yamt #include <sys/malloc.h>
     79       1.1  yamt 
     80       1.1  yamt /*
     81       1.1  yamt  * First-come first-served sort for disks.
     82       1.1  yamt  *
     83       1.1  yamt  * Requests are appended to the queue without any reordering.
     84       1.1  yamt  */
     85       1.1  yamt 
     86       1.1  yamt struct bufq_fcfs {
     87       1.1  yamt 	TAILQ_HEAD(, buf) bq_head;	/* actual list of buffers */
     88       1.1  yamt };
     89       1.1  yamt 
     90       1.3  yamt static void bufq_fcfs_init(struct bufq_state *);
     91       1.3  yamt static void bufq_fcfs_put(struct bufq_state *, struct buf *);
     92       1.3  yamt static struct buf *bufq_fcfs_get(struct bufq_state *, int);
     93       1.3  yamt 
     94       1.4  yamt BUFQ_DEFINE(fcfs, 10, bufq_fcfs_init);
     95       1.3  yamt 
     96       1.1  yamt static void
     97       1.1  yamt bufq_fcfs_put(struct bufq_state *bufq, struct buf *bp)
     98       1.1  yamt {
     99       1.1  yamt 	struct bufq_fcfs *fcfs = bufq->bq_private;
    100       1.1  yamt 
    101       1.1  yamt 	TAILQ_INSERT_TAIL(&fcfs->bq_head, bp, b_actq);
    102       1.1  yamt }
    103       1.1  yamt 
    104       1.1  yamt static struct buf *
    105       1.1  yamt bufq_fcfs_get(struct bufq_state *bufq, int remove)
    106       1.1  yamt {
    107       1.1  yamt 	struct bufq_fcfs *fcfs = bufq->bq_private;
    108       1.1  yamt 	struct buf *bp;
    109       1.1  yamt 
    110       1.1  yamt 	bp = TAILQ_FIRST(&fcfs->bq_head);
    111       1.1  yamt 
    112       1.1  yamt 	if (bp != NULL && remove)
    113       1.1  yamt 		TAILQ_REMOVE(&fcfs->bq_head, bp, b_actq);
    114       1.1  yamt 
    115       1.1  yamt 	return (bp);
    116       1.1  yamt }
    117       1.1  yamt 
    118  1.6.72.1  yamt static struct buf *
    119  1.6.72.1  yamt bufq_fcfs_cancel(struct bufq_state *bufq, struct buf *buf)
    120  1.6.72.1  yamt {
    121  1.6.72.1  yamt 	struct bufq_fcfs *fcfs = bufq->bq_private;
    122  1.6.72.1  yamt 	struct buf *bp;
    123  1.6.72.1  yamt 
    124  1.6.72.1  yamt 	bp = TAILQ_FIRST(&fcfs->bq_head);
    125  1.6.72.1  yamt 	while (bp) {
    126  1.6.72.1  yamt 		if (bp == buf) {
    127  1.6.72.1  yamt 			TAILQ_REMOVE(&fcfs->bq_head, bp, b_actq);
    128  1.6.72.1  yamt 			return buf;
    129  1.6.72.1  yamt 		}
    130  1.6.72.1  yamt 		bp = TAILQ_NEXT(bp, b_actq);
    131  1.6.72.1  yamt 	}
    132  1.6.72.1  yamt 	return NULL;
    133  1.6.72.1  yamt }
    134  1.6.72.1  yamt 
    135       1.3  yamt static void
    136       1.1  yamt bufq_fcfs_init(struct bufq_state *bufq)
    137       1.1  yamt {
    138       1.1  yamt 	struct bufq_fcfs *fcfs;
    139       1.1  yamt 
    140       1.1  yamt 	bufq->bq_get = bufq_fcfs_get;
    141       1.1  yamt 	bufq->bq_put = bufq_fcfs_put;
    142  1.6.72.1  yamt 	bufq->bq_cancel = bufq_fcfs_cancel;
    143       1.5  yamt 	bufq->bq_private = malloc(sizeof(struct bufq_fcfs), M_DEVBUF, M_ZERO);
    144       1.1  yamt 	fcfs = (struct bufq_fcfs *)bufq->bq_private;
    145       1.1  yamt 	TAILQ_INIT(&fcfs->bq_head);
    146       1.1  yamt }
    147