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/newfs_hammer/Attic/buffer_alist.c,v 1.1 2007/10/16 18:30:53 dillon Exp $
37 * Implement the super-cluster A-list recursion for the cluster allocator.
39 * Volume A-list -> supercluster A-list -> cluster
42 #include "newfs_hammer.h"
45 buffer_alist_init(void *info
, int32_t blk
, int32_t radix
)
47 struct cluster_info
*cluster
= info
;
48 struct buffer_info
*buf
;
52 * Calculate the buffer number, initialize based on the buffer type.
53 * The buffer has already been allocated to assert that it has been
56 buf_no
= blk
/ HAMMER_FSBUF_MAXBLKS
;
57 buf
= get_buffer(cluster
, buf_no
, 0);
58 assert(buf
->ondisk
->head
.buf_type
!= 0);
64 buffer_alist_destroy(void *info
, int32_t blk
, int32_t radix
)
70 buffer_alist_alloc_fwd(void *info
, int32_t blk
, int32_t radix
,
71 int32_t count
, int32_t atblk
, int32_t *fullp
)
73 struct cluster_info
*cluster
= info
;
74 struct buffer_info
*buf
;
78 buf_no
= blk
/ HAMMER_FSBUF_MAXBLKS
;
79 buf
= get_buffer(cluster
, buf_no
, 0);
80 assert(buf
->ondisk
->head
.buf_type
!= 0);
82 r
= hammer_alist_alloc_fwd(&buf
->alist
, count
, atblk
- blk
);
83 if (r
!= HAMMER_ALIST_BLOCK_NONE
)
85 *fullp
= hammer_alist_isfull(&buf
->alist
);
90 buffer_alist_alloc_rev(void *info
, int32_t blk
, int32_t radix
,
91 int32_t count
, int32_t atblk
, int32_t *fullp
)
93 struct cluster_info
*cluster
= info
;
94 struct buffer_info
*buf
;
98 buf_no
= blk
/ HAMMER_FSBUF_MAXBLKS
;
99 buf
= get_buffer(cluster
, buf_no
, 0);
100 assert(buf
->ondisk
->head
.buf_type
!= 0);
102 r
= hammer_alist_alloc_rev(&buf
->alist
, count
, atblk
- blk
);
103 if (r
!= HAMMER_ALIST_BLOCK_NONE
)
105 *fullp
= hammer_alist_isfull(&buf
->alist
);
110 buffer_alist_free(void *info
, int32_t blk
, int32_t radix
,
111 int32_t base_blk
, int32_t count
, int32_t *emptyp
)
113 struct cluster_info
*cluster
= info
;
114 struct buffer_info
*buf
;
117 buf_no
= blk
/ HAMMER_FSBUF_MAXBLKS
;
118 buf
= get_buffer(cluster
, buf_no
, 0);
119 assert(buf
->ondisk
->head
.buf_type
!= 0);
120 hammer_alist_free(&buf
->alist
, base_blk
, count
);
121 *emptyp
= hammer_alist_isempty(&buf
->alist
);
125 buffer_alist_print(void *info
, int32_t blk
, int32_t radix
, int tab
)
130 hammer_buffer_alist_template(hammer_alist_config_t config
)
132 config
->bl_radix_init
= buffer_alist_init
;
133 config
->bl_radix_destroy
= buffer_alist_destroy
;
134 config
->bl_radix_alloc_fwd
= buffer_alist_alloc_fwd
;
135 config
->bl_radix_alloc_rev
= buffer_alist_alloc_rev
;
136 config
->bl_radix_free
= buffer_alist_free
;
137 config
->bl_radix_print
= buffer_alist_print
;