2 * Copyright (c) 2007 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * $DragonFly: src/sbin/hammer/Attic/buffer_alist.c,v 1.3 2008/01/03 06:48:45 dillon Exp $
37 * Implement the super-cluster A-list recursion for the cluster allocator.
39 * Volume A-list -> supercluster A-list -> cluster
42 #include <sys/types.h>
44 #include "hammer_util.h"
47 * Buffers are already initialized by alloc_new_buffer() so our init/destroy
48 * code shouldn't do anything.
51 buffer_alist_init(void *info __unused, int32_t blk __unused,
52 int32_t radix __unused, hammer_alloc_state_t state __unused)
58 buffer_alist_destroy(void *info __unused, int32_t blk __unused,
59 int32_t radix __unused)
65 buffer_alist_alloc_fwd(void *info, int32_t blk, int32_t radix __unused,
66 int32_t count, int32_t atblk, int32_t *fullp)
68 struct cluster_info *cluster = info;
69 struct buffer_info *buf;
73 buf_no = blk / HAMMER_FSBUF_MAXBLKS;
74 buf = get_buffer(cluster, buf_no, 0);
75 assert(buf->ondisk->head.buf_type != 0);
77 r = hammer_alist_alloc_fwd(&buf->alist, count, atblk - blk);
78 if (r != HAMMER_ALIST_BLOCK_NONE)
80 *fullp = hammer_alist_isfull(&buf->alist);
86 buffer_alist_alloc_rev(void *info, int32_t blk, int32_t radix __unused,
87 int32_t count, int32_t atblk, int32_t *fullp)
89 struct cluster_info *cluster = info;
90 struct buffer_info *buf;
94 buf_no = blk / HAMMER_FSBUF_MAXBLKS;
95 buf = get_buffer(cluster, buf_no, 0);
96 assert(buf->ondisk->head.buf_type != 0);
98 r = hammer_alist_alloc_rev(&buf->alist, count, atblk - blk);
99 if (r != HAMMER_ALIST_BLOCK_NONE)
101 *fullp = hammer_alist_isfull(&buf->alist);
107 buffer_alist_free(void *info, int32_t blk, int32_t radix __unused,
108 int32_t base_blk, int32_t count, int32_t *emptyp)
110 struct cluster_info *cluster = info;
111 struct buffer_info *buf;
114 buf_no = blk / HAMMER_FSBUF_MAXBLKS;
115 buf = get_buffer(cluster, buf_no, 0);
116 assert(buf->ondisk->head.buf_type != 0);
117 hammer_alist_free(&buf->alist, base_blk, count);
118 *emptyp = hammer_alist_isempty(&buf->alist);
123 buffer_alist_print(void *info __unused, int32_t blk __unused,
124 int32_t radix __unused, int tab __unused)
129 hammer_buffer_alist_template(hammer_alist_config_t config)
131 config->bl_radix_init = buffer_alist_init;
132 config->bl_radix_destroy = buffer_alist_destroy;
133 config->bl_radix_alloc_fwd = buffer_alist_alloc_fwd;
134 config->bl_radix_alloc_rev = buffer_alist_alloc_rev;
135 config->bl_radix_free = buffer_alist_free;
136 config->bl_radix_print = buffer_alist_print;