File: error.c

package info (click to toggle)
evms 2.5.2-1.sarge2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 14,248 kB
  • ctags: 15,488
  • sloc: ansic: 201,340; perl: 12,421; sh: 4,262; makefile: 1,516; yacc: 316; sed: 16
file content (521 lines) | stat: -rw-r--r-- 10,163 bytes parent folder | download
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
/*
 *   (C) Copyright IBM Corp. 2004
 *
 *   This program is free software;  you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
 *   the GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program;  if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * Module: Error Plugin
 * File: evms2/engine/plugins/error/error.c
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <plugin.h>
#include "error.h"

engine_functions_t *EngFncs;

/**
 * error_setup_evms_plugin
 **/
static int error_setup_evms_plugin(engine_functions_t *functions)
{
	int rc;
	EngFncs	= functions;

	LOG_ENTRY();

	rc = EngFncs->register_name(ERROR_NAME);
	if (rc) {
		LOG_ERROR("Error registering directory name.\n");
	}

	LOG_EXIT_INT(rc);
	return rc;
}

/**
 * error_cleanup_evms_plugin
 **/
static void error_cleanup_evms_plugin(void)
{
	LOG_ENTRY();
	EngFncs->unregister_name(ERROR_NAME);
	LOG_EXIT_VOID();
}

/**
 * error_can_delete
 *
 * Error objects can always be deleted.
 **/
static int error_can_delete(storage_object_t *object)
{
	LOG_ENTRY();
	LOG_EXIT_INT(0);
	return 0;
}

/**
 * error_discover
 *
 * Nothing to discover, since error objects aren't stored anywhere.
 *
 * FIXME: Search for DM devices with "Error" names and create objects for them?
 *        Then if someone tries to create an object with the same name and
 *        size, we can just return the existing object. This should help
 *        prevent leaving stale devices around in DM.
 *        
 **/
static int error_discover(list_anchor_t input_objects,
			  list_anchor_t output_objects,
			  boolean final_call)
{
	LOG_ENTRY();
	EngFncs->merge_lists(output_objects, input_objects, NULL, NULL);
	LOG_EXIT_INT(0);
	return 0;
}

/**
 * create_object
 **/
static storage_object_t *create_error_object(char *error_name,
					     u_int64_t size,
					     object_type_t type)
{
	storage_object_t *object = NULL;
	int rc;

	LOG_ENTRY();

	switch (type) {
	case DISK:
		rc = EngFncs->allocate_logical_disk(error_name, &object);
		break;
	case SEGMENT:
		rc = EngFncs->allocate_segment(error_name, &object);
		break;
	case REGION:
		rc = EngFncs->allocate_region(error_name, &object);
		break;
	case EVMS_OBJECT:
		rc = EngFncs->allocate_evms_object(error_name, &object);
		break;
	default:
		rc = EINVAL;
		break;
	}

	if (rc) {
		goto out;
	}

	object->size = size;
	object->data_type = DATA_TYPE;
	object->plugin = my_plugin_record;

out:
	LOG_EXIT_PTR(object);
	return object;
}

/**
 * error_create
 *
 * Create a new error object. Available options are:
 * - name: A string value specifying the name of the new error object.
 * - size: A ui64 value specifying the size (in sectors) of the new object.
 * - type: A string value specifying the type of object. The string must
 *         be "disk", "segment", "region", or "feature_object".
 * No objects are consumed when creating an error object, so the
 * input_objects list is ignored.
 **/
static int error_create(list_anchor_t input_objects,
			option_array_t *options,
			list_anchor_t output_objects)
{
	storage_object_t *object;
	char error_name[EVMS_NAME_SIZE+1];
	char *input_name;
	object_type_t type;
	u_int64_t size;
	int rc;

	LOG_ENTRY();

	parse_options(options, &input_name, &size, &type);
	rc = verify_options(input_name, type);
	if (rc) {
		goto out;
	}

	generate_error_name(input_name, error_name);
	object = create_error_object(error_name, size, type);
	if (!object) {
		rc = EINVAL;
		goto out;
	}

	EngFncs->dm_update_status(object);
	EngFncs->insert_thing(output_objects, object, INSERT_AFTER, NULL);

out:
	LOG_EXIT_INT(rc);
	return rc;
}

/**
 * error_discard
 **/
static int error_discard(list_anchor_t objects)
{
	storage_object_t *object;
	list_element_t iter;

	LOG_ENTRY();

	LIST_FOR_EACH(objects, iter, object) {
		EngFncs->free_storage_object(object);
	}

	LOG_EXIT_INT(0);
	return 0;
}

/**
 * error_delete
 **/
static int error_delete(storage_object_t *object,
			list_anchor_t child_objects)
{
	LOG_ENTRY();

	EngFncs->free_storage_object(object);

	LOG_EXIT_INT(0);
	return 0;
}

/**
 * error_commit_changes
 *
 * No metadata to commit.
 **/
static int error_commit_changes(storage_object_t *object,
				commit_phase_t phase)
{
	LOG_ENTRY();
	object->flags &= ~(SOFLAG_NEW | SOFLAG_DIRTY);
	LOG_EXIT_INT(0);
	return 0;
}

/**
 * error_can_activate
 **/
static int error_can_activate(storage_object_t *object)
{
	LOG_ENTRY();
	LOG_EXIT_INT(0);
	return 0;
}

/**
 * error_activate
 **/
static int error_activate(storage_object_t *object)
{
	dm_target_t target;
	int rc;

	LOG_ENTRY();

	target.start = 0;
	target.length = object->size;
	/* FIXME: Make a config-file or creation option so users
	 *        can select between "error" and "zero" targets.
	 */
	target.type = DM_TARGET_ERROR;
	target.data.linear = NULL;
	target.params = NULL;
	target.next = NULL;

	rc = EngFncs->dm_activate(object, &target);
	if (!rc) {
		object->flags &= ~SOFLAG_NEEDS_ACTIVATE;
	}

	LOG_EXIT_INT(rc);
	return rc;
}

/**
 * error_can_deactivate
 **/
static int error_can_deactivate(storage_object_t *object)
{
	LOG_ENTRY();
	LOG_EXIT_INT(0);
	return 0;
}

/**
 * error_deactivate
 **/
static int error_deactivate(storage_object_t *object)
{
	int rc;

	LOG_ENTRY();

	rc = EngFncs->dm_deactivate(object);
	if (!rc) {
		object->flags &= ~SOFLAG_NEEDS_DEACTIVATE;
	}

	LOG_EXIT_INT(0);
	return 0;
}

/**
 * error_get_option_count
 *
 * Get the total number of supported options for the specified task.
 **/
static int error_get_option_count(task_context_t *context)
{
	int count;

	LOG_ENTRY();

	switch (context->action) {
	case EVMS_Task_Create:
		count = ERROR_OPTION_COUNT;
		break;

	default:
		count = -1;
		break;
	}

	LOG_EXIT_INT(count);
	return count;
}

/**
 * error_init_task
 *
 * Initialize a user-task with the appropriate information for your plugin.
 * Set up all initial values in the option_descriptors in the context record
 * for the given task.
 **/
static int error_init_task(task_context_t *context)
{
	int rc;

	LOG_ENTRY();

	switch (context->action) {
	case EVMS_Task_Create:
		rc = init_create_task(context);
		break;

	default:
		rc = EINVAL;
		break;
	}

	LOG_EXIT_INT(rc);
	return rc;
}

/**
 * error_set_object
 **/
static int error_set_objects(task_context_t *context,
			     list_anchor_t declined_objects,
			     task_effect_t *effect)
{
	int rc;

	LOG_ENTRY();

	switch (context->action) {
	case EVMS_Task_Create:
		rc = 0;
		break;

	default:
		rc = EINVAL;
		break;
	}

	LOG_EXIT_INT(rc);
	return rc;
}

/**
 * error_set_option
 *
 * Examine the specified value, and determine if it is valid for the task and
 * option_descriptor index. If it is acceptable, set that value in the
 * appropriate entry in the option_descriptor. The value may be adjusted if
 * necessary/allowed. If so, set the effect return value accordingly.
 **/
static int error_set_option(task_context_t *context,
			    u_int32_t index,
			    value_t *value,
			    task_effect_t *effect)
{
	int rc;

	LOG_ENTRY();

	switch (context->action) {
	case EVMS_Task_Create:
		rc = set_create_option(context, index, value, effect);
		break;

	default:
		rc = EINVAL;
		break;
	}

	LOG_EXIT_INT(rc);
	return rc;
}

/**
 * error_read
 *
 * Silently ignore reads. Return a zero-filled data buffer.
 **/
static int error_read(storage_object_t *object,
		      lsn_t lsn,
		      sector_count_t count,
		      void *buffer)
{
	LOG_ENTRY();
	memset(buffer, 0, count << EVMS_VSECTOR_SIZE_SHIFT);
	LOG_EXIT_INT(0);
	return 0;
}

/**
 * error_write
 *
 * Silently ignore writes.
 **/
static int error_write(storage_object_t *object,
		       lsn_t lsn,
		       sector_count_t count,
		       void *buffer)
{
	LOG_ENTRY();
	LOG_EXIT_INT(0);
	return 0;
}

/**
 * error_add_sectors_to_kill_list
 *
 * Silently ignore.
 **/
static int error_add_sectors_to_kill_list(storage_object_t *object,
					  lsn_t lsn,
					  sector_count_t count)
{
	LOG_ENTRY();
	LOG_EXIT_INT(0);
	return 0;
}

/**
 * error_backup_metadata
 *
 * No metadata to save to the backup database.
 **/
static int error_backup_metadata(storage_object_t *object)
{
	LOG_ENTRY();
	LOG_EXIT_INT(0);
	return 0;
}

/*
 * Table of standard plugin APIs for the Error plugin.
 */
static plugin_functions_t error_functions = {
	.setup_evms_plugin		= error_setup_evms_plugin,
	.cleanup_evms_plugin		= error_cleanup_evms_plugin,
	.can_delete			= error_can_delete,
	.discover			= error_discover,
	.create				= error_create,
	.discard			= error_discard,
	.delete				= error_delete,
	.commit_changes			= error_commit_changes,
	.can_activate			= error_can_activate,
	.activate			= error_activate,
	.can_deactivate			= error_can_deactivate,
	.deactivate			= error_deactivate,
	.get_option_count		= error_get_option_count,
	.init_task			= error_init_task,
	.set_objects			= error_set_objects,
	.set_option			= error_set_option,
	.read				= error_read,
	.write				= error_write,
	.add_sectors_to_kill_list	= error_add_sectors_to_kill_list,
	.backup_metadata		= error_backup_metadata,
};

/*
 * Plugin record for the Error plugin.
 */
plugin_record_t error_plugin = {
	.id = SetPluginID(EVMS_OEM_IBM,
			  EVMS_DEVICE_MANAGER,
			  3),
	.version = {
		.major		= MAJOR_VERSION,
		.minor		= MINOR_VERSION,
		.patchlevel	= PATCH_LEVEL
	},
	.required_engine_api_version = {
		.major		= 15,
		.minor		= 0,
		.patchlevel	= 0
	},
	.required_plugin_api_version = {
		.plugin	= {
			.major		= 13,
			.minor		= 1,
			.patchlevel	= 0
		}
	},
	.short_name = "Error",
	.long_name = "Error Device Manager",
	.oem_name = "IBM",
	.functions = {
		.plugin = &error_functions
	},
};

plugin_record_t *evms_plugin_records[] = {
	&error_plugin,
	NULL
};