1235537Sgber/*-
2235537Sgber * Copyright (c) 2010-2012 Semihalf.
3235537Sgber * All rights reserved.
4235537Sgber *
5235537Sgber * Redistribution and use in source and binary forms, with or without
6235537Sgber * modification, are permitted provided that the following conditions
7235537Sgber * are met:
8235537Sgber * 1. Redistributions of source code must retain the above copyright
9235537Sgber *    notice, this list of conditions and the following disclaimer.
10235537Sgber * 2. Redistributions in binary form must reproduce the above copyright
11235537Sgber *    notice, this list of conditions and the following disclaimer in the
12235537Sgber *    documentation and/or other materials provided with the distribution.
13235537Sgber *
14235537Sgber * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15235537Sgber * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16235537Sgber * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17235537Sgber * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18235537Sgber * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19235537Sgber * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20235537Sgber * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21235537Sgber * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22235537Sgber * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23235537Sgber * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24235537Sgber * SUCH DAMAGE.
25235537Sgber */
26235537Sgber
27235537Sgber#include <sys/cdefs.h>
28235537Sgber__FBSDID("$FreeBSD$");
29235537Sgber
30235537Sgber#include <sys/param.h>
31235537Sgber#include <sys/systm.h>
32235537Sgber#include <sys/conf.h>
33235537Sgber#include <sys/kernel.h>
34235537Sgber#include <sys/lock.h>
35235537Sgber#include <sys/malloc.h>
36235537Sgber#include <sys/mount.h>
37235537Sgber#include <sys/mutex.h>
38235537Sgber#include <sys/buf.h>
39235537Sgber#include <sys/namei.h>
40235537Sgber#include <sys/vnode.h>
41235537Sgber#include <sys/bio.h>
42235537Sgber
43235537Sgber#include <fs/nandfs/nandfs_mount.h>
44235537Sgber#include <fs/nandfs/nandfs.h>
45235537Sgber#include <fs/nandfs/nandfs_subr.h>
46235537Sgber
47235537Sgberstruct buf *
48235537Sgbernandfs_geteblk(int size, int flags)
49235537Sgber{
50235537Sgber	struct buf *bp;
51235537Sgber
52235537Sgber	/*
53235537Sgber	 * XXX
54235537Sgber	 * Right now we can call geteblk with GB_NOWAIT_BD flag, which means
55235537Sgber	 * it can return NULL. But we cannot afford to get NULL, hence this panic.
56235537Sgber	 */
57235537Sgber	bp = geteblk(size, flags);
58235537Sgber	if (bp == NULL)
59235537Sgber		panic("geteblk returned NULL");
60235537Sgber
61235537Sgber	return (bp);
62235537Sgber}
63235537Sgber
64235537Sgbervoid
65235537Sgbernandfs_dirty_bufs_increment(struct nandfs_device *fsdev)
66235537Sgber{
67235537Sgber
68235537Sgber	mtx_lock(&fsdev->nd_mutex);
69235537Sgber	KASSERT(fsdev->nd_dirty_bufs >= 0, ("negative nd_dirty_bufs"));
70235537Sgber	fsdev->nd_dirty_bufs++;
71235537Sgber	mtx_unlock(&fsdev->nd_mutex);
72235537Sgber}
73235537Sgber
74235537Sgbervoid
75235537Sgbernandfs_dirty_bufs_decrement(struct nandfs_device *fsdev)
76235537Sgber{
77235537Sgber
78235537Sgber	mtx_lock(&fsdev->nd_mutex);
79235537Sgber	KASSERT(fsdev->nd_dirty_bufs > 0,
80235537Sgber	    ("decrementing not-positive nd_dirty_bufs"));
81235537Sgber	fsdev->nd_dirty_bufs--;
82235537Sgber	mtx_unlock(&fsdev->nd_mutex);
83235537Sgber}
84