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.3 2007/11/27 07:44:38 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);
61 super_alist_destroy(void *info, int32_t blk, int32_t radix)
67 super_alist_alloc_fwd(void *info, int32_t blk, int32_t radix,
68 int32_t count, int32_t atblk, int32_t *fullp)
70 struct volume_info *vol = info;
71 struct supercl_info *supercl;
75 sclno = blk / HAMMER_SCL_MAXCLUSTERS;
76 supercl = get_supercl(vol, sclno);
77 r = hammer_alist_alloc_fwd(&supercl->clu_alist, count, atblk - blk);
78 if (r != HAMMER_ALIST_BLOCK_NONE)
80 *fullp = hammer_alist_isfull(&supercl->clu_alist);
85 super_alist_alloc_rev(void *info, int32_t blk, int32_t radix,
86 int32_t count, int32_t atblk, int32_t *fullp)
88 struct volume_info *vol = info;
89 struct supercl_info *supercl;
93 sclno = blk / HAMMER_SCL_MAXCLUSTERS;
94 supercl = get_supercl(vol, sclno);
95 r = hammer_alist_alloc_rev(&supercl->clu_alist, count, atblk - blk);
96 if (r != HAMMER_ALIST_BLOCK_NONE)
98 *fullp = hammer_alist_isfull(&supercl->clu_alist);
103 super_alist_free(void *info, int32_t blk, int32_t radix,
104 int32_t base_blk, int32_t count, int32_t *emptyp)
106 struct volume_info *vol = info;
107 struct supercl_info *supercl;
110 sclno = blk / HAMMER_SCL_MAXCLUSTERS;
111 supercl = get_supercl(vol, sclno);
112 hammer_alist_free(&supercl->clu_alist, base_blk, count);
113 *emptyp = hammer_alist_isempty(&supercl->clu_alist);
117 super_alist_print(void *info, int32_t blk, int32_t radix, int tab)
122 hammer_super_alist_template(hammer_alist_config_t config)
124 config->bl_radix_init = super_alist_init;
125 config->bl_radix_destroy = super_alist_destroy;
126 config->bl_radix_alloc_fwd = super_alist_alloc_fwd;
127 config->bl_radix_alloc_rev = super_alist_alloc_rev;
128 config->bl_radix_free = super_alist_free;
129 config->bl_radix_print = super_alist_print;