Correct a bug in the lockf code. F_NOEND was not being properly set.
[dragonfly.git] / sbin / newfs_hammer / super_alist.c
1 /*
2  * Copyright (c) 2007 The DragonFly Project.  All rights reserved.
3  * 
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@backplane.com>
6  * 
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 
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
16  *    distribution.
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.
20  * 
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
32  * SUCH DAMAGE.
33  * 
34  * $DragonFly: src/sbin/newfs_hammer/Attic/super_alist.c,v 1.1 2007/10/16 18:30:53 dillon Exp $
35  */
36 /*
37  * Implement the super-cluster A-list recursion for the cluster allocator.
38  *
39  * Volume A-list -> supercluster A-list -> cluster
40  */
41
42 #include "newfs_hammer.h"
43
44 static int
45 super_alist_init(void *info, int32_t blk, int32_t radix)
46 {
47         struct volume_info *vol = info;
48         struct supercl_info *supercl;
49         int32_t sclno;
50
51         /*
52          * Calculate the super-cluster number containing the cluster (blk)
53          * and obtain the super-cluster buffer.
54          */
55         sclno = blk / HAMMER_SCL_MAXCLUSTERS;
56         supercl = get_supercl(vol, sclno);
57
58         printf("super_alist_init: blk %d radix %d\n", blk, radix);
59         return(0);
60 }
61
62 static int
63 super_alist_destroy(void *info, int32_t blk, int32_t radix)
64 {
65         printf("super_alist_destroy: blk %d radix %d\n", blk, radix);
66         return(0);
67 }
68
69 static int
70 super_alist_alloc_fwd(void *info, int32_t blk, int32_t radix,
71                       int32_t count, int32_t atblk, int32_t *fullp)
72 {
73         struct volume_info *vol = info;
74         struct supercl_info *supercl;
75         int32_t sclno;
76         int32_t r;
77
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)
82                 r += blk;
83         *fullp = hammer_alist_isfull(&supercl->alist);
84         return(r);
85 }
86
87 static int
88 super_alist_alloc_rev(void *info, int32_t blk, int32_t radix,
89                       int32_t count, int32_t atblk, int32_t *fullp)
90 {
91         struct volume_info *vol = info;
92         struct supercl_info *supercl;
93         int32_t sclno;
94         int32_t r;
95
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)
100                 r += blk;
101         *fullp = hammer_alist_isfull(&supercl->alist);
102         return(r);
103 }
104
105 static void
106 super_alist_free(void *info, int32_t blk, int32_t radix,
107                  int32_t base_blk, int32_t count, int32_t *emptyp)
108 {
109         struct volume_info *vol = info;
110         struct supercl_info *supercl;
111         int32_t sclno;
112
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);
119 }
120
121 static void
122 super_alist_print(void *info, int32_t blk, int32_t radix, int tab)
123 {
124 }
125
126 void
127 hammer_super_alist_template(hammer_alist_config_t config)
128 {
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;
135 }
136