File: sdext_plug.c

package info (click to toggle)
reiser4progs 1.0.6-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 5,348 kB
  • ctags: 3,714
  • sloc: ansic: 33,468; sh: 8,489; makefile: 1,012
file content (209 lines) | stat: -rw-r--r-- 4,752 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/* Copyright (C) 2001-2005 by Hans Reiser, licensing governed by
   reiser4progs/COPYING.
   
   sdext_plug.c -- plugin id stat data extension plugin. */

#include "sdext_plug.h"

reiser4_core_t *sdext_pset_core = NULL;

#ifndef ENABLE_MINIMAL
static void sdext_plug_info(stat_entity_t *stat) {
	sdext_plug_t *ext;
	uint8_t i;

	stat->info.digest = NULL;
	
	/* When inserting new extentions, nothing to be done. */
	if (stat->plug->p.id.id != SDEXT_PSET_ID || !stat) 
		return;
	
	ext = (sdext_plug_t *)stat_body(stat);
	for (i = 0; i < sdext_plug_get_count(ext); i++) {
		rid_t mem, id;
		
		mem = sdext_plug_get_member(ext, i);
		id = sdext_plug_get_pid(ext, i);

		if (mem != SDEXT_PSET_ID)
			continue;
		
		stat->info.digest = sdext_pset_core->pset_ops.find(mem, id, 1);
		if (stat->info.digest == INVAL_PTR)
			stat->info.digest = NULL;
		
		return;
	}
}
#endif

uint32_t sdext_plug_length(stat_entity_t *stat, void *hint) {
	uint16_t count = 0;
	uint64_t mask;
	
	aal_assert("vpf-1844", stat != NULL || hint != NULL);
	
	/* If hint is given, count its pset. */
	if (hint) {
		sdhint_plug_t *h = (sdhint_plug_t *)hint;
		
		mask = h->plug_mask;
		
		while (mask) {
			if (mask & 1) count++;
			mask >>= 1;
		}
	} else {
		sdext_plug_t *plug = (sdext_plug_t *)stat_body(stat);
		
		count = sdext_plug_get_count(plug);
	}
	
	/* Count on-disk pset. */
	return sizeof(sdext_plug_slot_t) * count + 
		(count ? sizeof(sdext_plug_t) : 0);
}

static errno_t sdext_plug_open(stat_entity_t *stat, void *hint) {
	sdhint_plug_t *plugh;
	sdext_plug_t *ext;
	int is_pset;
	uint16_t i;
	
	aal_assert("vpf-1597", stat != NULL);
	aal_assert("vpf-1598", hint != NULL);

	plugh = (sdhint_plug_t *)hint;
	ext = (sdext_plug_t *)stat_body(stat);

	is_pset = stat->plug->p.id.id == SDEXT_PSET_ID;
	
	aal_memset(plugh, 0, sizeof(sdhint_plug_t));
	
	for (i = 0; i < sdext_plug_get_count(ext); i++) {
		rid_t mem, id;
		
		mem = sdext_plug_get_member(ext, i);
		id = sdext_plug_get_pid(ext, i);
		
		/* Check the member id valideness. */
		if (mem >= PSET_STORE_LAST)
			return -EIO;
		
		/* Check if we met this member already. */
		if (plugh->plug_mask & (1 << mem))
			return -EIO;
		
		/* Obtain the plugin by the id. */
		plugh->plug[mem] = sdext_pset_core->pset_ops.find(
						mem, id, is_pset);
		
		if (plugh->plug[mem] == INVAL_PTR) {
#ifndef ENABLE_MINIMAL
			aal_error("Node (%llu), item (%u): Failed to find "
				  "a plugin of the pset member (%u), id "
				  "(%u).", place_blknr(stat->place),
				  stat->place->pos.item, mem, id);
			return -EIO;
#else
			plugh->plug[mem] = NULL;
#endif
		}
		
		/* For those where no plugin is found but the id is correct, 
		   keep the id in plug set, remember it is a parameter. */
		if (plugh->plug[mem] == NULL)
			plugh->plug[mem] = (void *)id;
		
		plugh->plug_mask |= (1 << mem);
	}

	return 0;
}

#ifndef ENABLE_MINIMAL
static errno_t sdext_plug_init(stat_entity_t *stat, void *hint) {
	sdhint_plug_t *plugh;
	tree_entity_t *tree;
	sdext_plug_t *ext;
	uint16_t count = 0;
	uint16_t id;
	rid_t mem;
	
	aal_assert("vpf-1600", stat != NULL);
	aal_assert("vpf-1599", hint != NULL);
	
	plugh = (sdhint_plug_t *)hint;
	ext = (sdext_plug_t *)stat_body(stat);
	tree = stat->place->node->tree;
	
	for (mem = 0; mem < PSET_STORE_LAST; mem++) {
		/* Find the plugin to be stored. */
		if (!(plugh->plug_mask & (1 << mem)))
			continue;

		sdext_plug_set_member(ext, count, mem);

		id = (tree->param_mask & (1 << mem)) ? 
			((uint32_t)plugh->plug[mem]) : 
			plugh->plug[mem]->id.id;
		
		sdext_plug_set_pid(ext, count, id);
		count++;
	}
	
	sdext_plug_set_count(ext, count);
	
	return 0;
}

extern errno_t sdext_plug_check_struct(stat_entity_t *stat, 
				       repair_hint_t *hint);

extern void sdext_plug_print(stat_entity_t *stat, 
			     aal_stream_t *stream, 
			     uint16_t options);

#endif

reiser4_sdext_plug_t sdext_pset_plug = {
	.p = {
		.id    = {SDEXT_PSET_ID, 0, SDEXT_PLUG_TYPE},
#ifndef ENABLE_MINIMAL
		.label = "sdext_plugin_set",
		.desc  = "Plugin Set StatData extension plugin.",
#endif
	},

#ifndef ENABLE_MINIMAL
	.init	 	= sdext_plug_init,
	.info		= sdext_plug_info,
	.print   	= sdext_plug_print,
	.check_struct   = sdext_plug_check_struct,
#else
	.info		= NULL,
#endif
	.open	 	= sdext_plug_open,
	.length	 	= sdext_plug_length
};

reiser4_sdext_plug_t sdext_hset_plug = {
	.p = {
		.id    = {SDEXT_HSET_ID, 0, SDEXT_PLUG_TYPE},
#ifndef ENABLE_MINIMAL
		.label = "sdext_heir_set",
		.desc  = "Heir Set StatData extension plugin.",
#endif
	},

#ifndef ENABLE_MINIMAL
	.init	 	= sdext_plug_init,
	.info		= sdext_plug_info,
	.print   	= sdext_plug_print,
	.check_struct   = sdext_plug_check_struct,
#else
	.info		= NULL,
#endif
	.open	 	= sdext_plug_open,
	.length	 	= sdext_plug_length
};