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/super_alist.c,v 1.4 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>
43 #include "hammer_util.h"
46 super_alist_init(void *info
, int32_t blk
, int32_t radix __unused
,
47 hammer_alloc_state_t state
)
49 struct volume_info
*vol
= info
;
50 struct supercl_info
*supercl
;
54 * Calculate the super-cluster number containing the cluster (blk)
55 * and obtain the super-cluster buffer.
57 sclno
= blk
/ HAMMER_SCL_MAXCLUSTERS
;
58 supercl
= get_supercl(vol
, sclno
, state
);
64 super_alist_destroy(void *info __unused
, int32_t blk __unused
,
65 int32_t radix __unused
)
71 super_alist_alloc_fwd(void *info
, int32_t blk
, int32_t radix __unused
,
72 int32_t count
, int32_t atblk
, int32_t *fullp
)
74 struct volume_info
*vol
= info
;
75 struct supercl_info
*supercl
;
79 sclno
= blk
/ HAMMER_SCL_MAXCLUSTERS
;
80 supercl
= get_supercl(vol
, sclno
, 0);
81 r
= hammer_alist_alloc_fwd(&supercl
->clu_alist
, count
, atblk
- blk
);
82 if (r
!= HAMMER_ALIST_BLOCK_NONE
)
84 *fullp
= hammer_alist_isfull(&supercl
->clu_alist
);
90 super_alist_alloc_rev(void *info
, int32_t blk
, int32_t radix __unused
,
91 int32_t count
, int32_t atblk
, int32_t *fullp
)
93 struct volume_info
*vol
= info
;
94 struct supercl_info
*supercl
;
98 sclno
= blk
/ HAMMER_SCL_MAXCLUSTERS
;
99 supercl
= get_supercl(vol
, sclno
, 0);
100 r
= hammer_alist_alloc_rev(&supercl
->clu_alist
, count
, atblk
- blk
);
101 if (r
!= HAMMER_ALIST_BLOCK_NONE
)
103 *fullp
= hammer_alist_isfull(&supercl
->clu_alist
);
104 rel_supercl(supercl
);
109 super_alist_free(void *info
, int32_t blk
, int32_t radix __unused
,
110 int32_t base_blk
, int32_t count
, int32_t *emptyp
)
112 struct volume_info
*vol
= info
;
113 struct supercl_info
*supercl
;
116 sclno
= blk
/ HAMMER_SCL_MAXCLUSTERS
;
117 supercl
= get_supercl(vol
, sclno
, 0);
119 hammer_alist_free(&supercl
->clu_alist
, base_blk
, count
);
120 *emptyp
= hammer_alist_isempty(&supercl
->clu_alist
);
121 rel_supercl(supercl
);
125 super_alist_print(void *info __unused
, int32_t blk __unused
,
126 int32_t radix __unused
, int tab __unused
)
131 hammer_super_alist_template(hammer_alist_config_t config
)
133 config
->bl_radix_init
= super_alist_init
;
134 config
->bl_radix_destroy
= super_alist_destroy
;
135 config
->bl_radix_alloc_fwd
= super_alist_alloc_fwd
;
136 config
->bl_radix_alloc_rev
= super_alist_alloc_rev
;
137 config
->bl_radix_free
= super_alist_free
;
138 config
->bl_radix_print
= super_alist_print
;