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/super_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 super_alist_init(void *info
, int32_t blk
, int32_t radix
)
47 struct volume_info
*vol
= info
;
48 struct supercl_info
*supercl
;
52 * Calculate the super-cluster number containing the cluster (blk)
53 * and obtain the super-cluster buffer.
55 sclno
= blk
/ HAMMER_SCL_MAXCLUSTERS
;
56 supercl
= get_supercl(vol
, sclno
);
58 printf("super_alist_init: blk %d radix %d\n", blk
, radix
);
63 super_alist_destroy(void *info
, int32_t blk
, int32_t radix
)
65 printf("super_alist_destroy: blk %d radix %d\n", blk
, radix
);
70 super_alist_alloc_fwd(void *info
, int32_t blk
, int32_t radix
,
71 int32_t count
, int32_t atblk
, int32_t *fullp
)
73 struct volume_info
*vol
= info
;
74 struct supercl_info
*supercl
;
78 sclno
= blk
/ HAMMER_SCL_MAXCLUSTERS
;
79 supercl
= get_supercl(vol
, sclno
);
80 r
= hammer_alist_alloc_fwd(&supercl
->alist
, count
, atblk
- blk
);
81 if (r
!= HAMMER_ALIST_BLOCK_NONE
)
83 *fullp
= hammer_alist_isfull(&supercl
->alist
);
88 super_alist_alloc_rev(void *info
, int32_t blk
, int32_t radix
,
89 int32_t count
, int32_t atblk
, int32_t *fullp
)
91 struct volume_info
*vol
= info
;
92 struct supercl_info
*supercl
;
96 sclno
= blk
/ HAMMER_SCL_MAXCLUSTERS
;
97 supercl
= get_supercl(vol
, sclno
);
98 r
= hammer_alist_alloc_rev(&supercl
->alist
, count
, atblk
- blk
);
99 if (r
!= HAMMER_ALIST_BLOCK_NONE
)
101 *fullp
= hammer_alist_isfull(&supercl
->alist
);
106 super_alist_free(void *info
, int32_t blk
, int32_t radix
,
107 int32_t base_blk
, int32_t count
, int32_t *emptyp
)
109 struct volume_info
*vol
= info
;
110 struct supercl_info
*supercl
;
113 sclno
= blk
/ HAMMER_SCL_MAXCLUSTERS
;
114 supercl
= get_supercl(vol
, sclno
);
115 printf("super_alist_free: blk %d radix %d base_blk %d count %d\n",
116 blk
, radix
, base_blk
, count
);
117 hammer_alist_free(&supercl
->alist
, base_blk
, count
);
118 *emptyp
= hammer_alist_isempty(&supercl
->alist
);
122 super_alist_print(void *info
, int32_t blk
, int32_t radix
, int tab
)
127 hammer_super_alist_template(hammer_alist_config_t config
)
129 config
->bl_radix_init
= super_alist_init
;
130 config
->bl_radix_destroy
= super_alist_destroy
;
131 config
->bl_radix_alloc_fwd
= super_alist_alloc_fwd
;
132 config
->bl_radix_alloc_rev
= super_alist_alloc_rev
;
133 config
->bl_radix_free
= super_alist_free
;
134 config
->bl_radix_print
= super_alist_print
;