source: MondoRescue/branches/3.1/mondo/src/common/libmondo-raid.c@ 3147

Last change on this file since 3147 was 3147, checked in by Bruno Cornec, 11 years ago
  • First pass on svn merge -r 2935:3146 ../3.0
  • Property svn:keywords set to Id
File size: 36.5 KB
RevLine 
[1]1/* libmondo-raid.c subroutines for handling RAID
[128]2 $Id: libmondo-raid.c 3147 2013-06-19 06:34:46Z bruno $
[1]3*/
4
5
6/**
7 * @file
8 * Functions for handling RAID (especially during restore).
9 */
10
11#include "my-stuff.h"
12#include "mondostructures.h"
[541]13#include "libmondo-gui-EXT.h"
[1]14#include "libmondo-files-EXT.h"
15#include "libmondo-tools-EXT.h"
16#include "libmondo-string-EXT.h"
[3147]17#include "libmondo-fork-EXT.h"
[541]18#include "lib-common-externs.h"
[1]19#include "libmondo-raid.h"
[2211]20#include "mr_mem.h"
[2241]21#include "mr_str.h"
[1]22
23#ifdef __FreeBSD__
24/* Nonstandard library functions: */
[128]25extern void errx(int exitval, const char *fmt, ...);
26extern char *strsep(char **stringp, const char *delim);
[1]27#endif
28
29/*@unused@*/
[128]30//static char cvsid[] = "$Id: libmondo-raid.c 3147 2013-06-19 06:34:46Z bruno $";
[1]31
32
33/**
34 * @addtogroup raidGroup
35 * @{
36 */
37/**
38 * See if a particular RAID level is supported by the kernel.
39 * @param raidno The RAID level (-1 through 5) to check. -1 means "linear" under Linux and
40 * "concatenated" under FreeBSD. It's really the same thing, just different wording.
41 * @return TRUE if it's supported, FALSE if not.
42 */
[128]43bool is_this_raid_personality_registered(int raidno)
[1]44{
45#ifdef __FreeBSD__
[128]46 return ((raidno == -1) || (raidno == 0) || (raidno == 1)
47 || (raidno == 5)) ? TRUE : FALSE;
[1]48#else
[128]49 /*@ buffer ********************************************************** */
[2211]50 char *command = NULL;
[128]51 int res;
52
[2323]53 mr_asprintf(command, "grep \"");
[128]54 if (raidno == -1) {
[2211]55 mr_strcat(command, "linear");
[128]56 } else {
[2211]57 mr_strcat(command, "raid%d", raidno);
[128]58 }
[2211]59 mr_strcat(command, "\" /proc/mdstat > /dev/null 2> /dev/null");
[128]60 log_it("Is raid %d registered? Command = '%s'", raidno, command);
61 res = system(command);
62 paranoid_free(command);
[2211]63
[128]64 if (res) {
65 return (FALSE);
66 } else {
67 return (TRUE);
68 }
[1]69#endif
70}
71
72
73
74
75
76
77/**
78 * Search for @p device in @p disklist.
79 * @param disklist The disklist to search in.
80 * @param device The device to search for.
81 * @return The index number of @p device, or -1 if it does not exist.
82 */
83int
[128]84where_in_drivelist_is_drive(struct list_of_disks *disklist, char *device)
[1]85{
86
[128]87 /*@ int ************************************************************* */
88 int i = 0;
[1]89
[128]90 assert(disklist != NULL);
91 assert_string_is_neither_NULL_nor_zerolength(device);
[1]92
[128]93 for (i = 0; i < disklist->entries; i++) {
94 if (!strcmp(disklist->el[i].device, device)) {
95 break;
96 }
[1]97 }
[128]98 if (i == disklist->entries) {
99 return (-1);
100 } else {
101 return (i);
102 }
[1]103}
104
105
106
107
108
109
110
111
112/**
113 * Determine which RAID device is using a particular partition.
114 * @param raidlist The RAID information structure.
115 * @param device The partition to find out about.
116 * @return The index number of the RAID device using @p device, or -1 if there is none.
117 */
118int
[128]119which_raid_device_is_using_this_partition(struct raidlist_itself *raidlist,
120 char *device)
[1]121{
122#ifdef __FreeBSD__
123// FreeBSD-specific version of which_raid_device_is_using_this_partition()
[128]124 /*@ int ********************************************************* */
125 int i = 0;
[1]126
[128]127 for (i = 0; i < raidlist->entries; i++) {
128 bool thisone = FALSE;
129 int j, k, l;
130
131 for (j = 0; j < raidlist->el[i].plexes; ++j) {
132 for (k = 0; k < raidlist->el[i].plex[j].subdisks; ++k) {
133 for (l = 0; l < raidlist->disks.entries; ++l) {
134 if (!strcmp(raidlist->disks.el[l].device,
135 device) &&
136 !strcmp(raidlist->el[i].plex[j].sd[k].which_device,
137 raidlist->disks.el[l].name))
138 thisone = TRUE;
139 }
140 }
[1]141 }
[128]142
143 if (thisone) {
144 break;
145 }
[1]146 }
[128]147 if (i == raidlist->entries) {
148 return (-1);
149 } else {
150 return (i);
[1]151 }
152}
153
154#else
155// Linux-specific version of which_raid_device_is_using_this_partition()
156// and one other function which FreeBSD doesn't use
157
[128]158 int current_raiddev = 0;
[1]159
[128]160 assert_string_is_neither_NULL_nor_zerolength(device);
161 assert(raidlist != NULL);
[1]162
[128]163 for (current_raiddev = 0; current_raiddev < raidlist->entries;
164 current_raiddev++) {
165 if (where_in_drivelist_is_drive
166 (&raidlist->el[current_raiddev].data_disks, device) >= 0
167 || where_in_drivelist_is_drive(&raidlist->el[current_raiddev].
168 spare_disks, device) >= 0
169 || where_in_drivelist_is_drive(&raidlist->el[current_raiddev].
170 parity_disks, device) >= 0
171 || where_in_drivelist_is_drive(&raidlist->el[current_raiddev].
172 failed_disks, device) >= 0) {
173 break;
174 }
[1]175 }
[128]176 if (current_raiddev == raidlist->entries) {
177 return (-1);
178 } else {
179 return (current_raiddev);
180 }
[1]181}
182
183/**
184 * Write an @c int variable to a list of RAID variables.
185 * @param raidrec The RAID device record to write to.
186 * @param lino The variable index number to modify/create.
187 * @param label The label to write.
188 * @param value The value to write.
189 */
190void
[128]191write_variableINT_to_raid_var_line(struct raid_device_record *raidrec,
192 int lino, char *label, int value)
[1]193{
[128]194 /*@ buffers ***************************************************** */
[2260]195 char *sz_value = NULL;
[1]196
[128]197 assert(raidrec != NULL);
198 assert(label != NULL);
[1]199
[2323]200 mr_asprintf(sz_value, "%d", value);
[128]201 strcpy(raidrec->additional_vars.el[lino].label, label);
202 strcpy(raidrec->additional_vars.el[lino].value, sz_value);
[2260]203 mr_free(sz_value);
[1]204}
205#endif
206
207
208
209
210
211
212
213
214#ifdef __FreeBSD__
215/**
216 * Add a disk to a RAID plex.
217 * @param p The plex to add the device to.
218 * @param device_to_add The device to add to @p p.
219 */
[128]220void add_disk_to_raid_device(struct vinum_plex *p, char *device_to_add)
[1]221{
[128]222 strcpy(p->sd[p->subdisks].which_device, device_to_add);
223 ++p->subdisks;
[1]224
225}
226#else
227/**
228 * Add a disk to a RAID device.
229 * @param disklist The disklist to add the device to.
230 * @param device_to_add The device to add to @p disklist.
231 * @param index The index number of the disklist entry we're creating.
232 */
[128]233void add_disk_to_raid_device(struct list_of_disks *disklist,
234 char *device_to_add, int index)
[1]235{
[128]236 int items;
[1]237
[128]238 assert(disklist != NULL);
239 assert_string_is_neither_NULL_nor_zerolength(device_to_add);
240 items = disklist->entries;
241 strcpy(disklist->el[items].device, device_to_add);
242 disklist->el[items].index = index;
243 items++;
244 disklist->entries = items;
[1]245}
246#endif
247
248
249/**
250 * Save the additional RAID variables to a stream.
251 * @param vars The RAID variable list to save.
252 * @param fout The FILE pointer to save them to.
253 */
[128]254void
255save_additional_vars_to_file(struct additional_raid_variables *vars,
256 FILE * fout)
[1]257{
[128]258 int i;
[1]259
[128]260 assert(vars != NULL);
261 assert(fout != NULL);
[1]262
[128]263 for (i = 0; i < vars->entries; i++) {
264 fprintf(fout, " %-21s %s\n", vars->el[i].label,
265 vars->el[i].value);
266 }
[1]267}
268
269
270/**
271 * Save a raidlist structure to disk in raidtab format.
272 * @param raidlist The raidlist to save.
273 * @param fname The file to save it to.
274 * @return 0, always.
275 * @bug Return value is redundant.
276 */
[128]277int save_raidlist_to_raidtab(struct raidlist_itself *raidlist, char *fname)
[1]278{
[128]279 FILE *fout;
280 int current_raid_device;
[1]281#ifdef __FreeBSD__
[128]282 int i;
[1]283#else
284// Linux
285#endif
286
[128]287 assert(raidlist != NULL);
288 assert_string_is_neither_NULL_nor_zerolength(fname);
[1]289
[128]290 if (raidlist->entries <= 0) {
291 unlink(fname);
292 log_it("Deleting raidtab (no RAID devs anyway)");
293 return (0);
294 }
295 if (!(fout = fopen(fname, "w"))) {
296 log_OS_error("Failed to save raidlist");
297 return (1);
298 }
299 fprintf(fout, "# Generated by Mondo Rescue\n");
[1]300
301#ifdef __FreeBSD__
[128]302 for (i = 0; i < raidlist->disks.entries; ++i) {
303 fprintf(fout, "drive %s device %s\n", raidlist->disks.el[i].name,
304 raidlist->disks.el[i].device);
305 }
306 for (i = 0; i < (raidlist->spares.entries); ++i) {
307 fprintf(fout, "drive %s device %s hotspare\n",
308 raidlist->spares.el[i].name,
309 raidlist->spares.el[i].device);
310 }
[1]311#endif
312
[128]313 for (current_raid_device = 0; current_raid_device < raidlist->entries;
314 current_raid_device++) {
315 save_raidrec_to_file(&raidlist->el[current_raid_device], fout);
316 }
317 paranoid_fclose(fout);
318 return (0);
[1]319}
320
321
322/**
323 * Save an individual RAID device record to a stream.
324 * @param raidrec The RAID device record to save.
325 * @param fout The stream to save it to.
326 */
[128]327void save_raidrec_to_file(struct
[1]328#ifdef __FreeBSD__
[128]329 vinum_volume
[1]330#else
[128]331 raid_device_record
[1]332#endif
[128]333 * raidrec, FILE * fout)
[1]334{
335#ifdef __FreeBSD__
[128]336 int i, j;
[2334]337 char *org = NULL;
[1]338
[128]339 fprintf(fout, "\nvolume %s\n", raidrec->volname);
340 for (i = 0; i < raidrec->plexes; ++i) {
341 switch (raidrec->plex[i].raidlevel) {
342 case -1:
[2334]343 mr_asprintf(org, "concat");
[128]344 break;
345 case 0:
[2334]346 mr_asprintf(org, "striped");
[128]347 break;
348 case 5:
[2334]349 mr_asprintf(org, "raid5");
[128]350 break;
351 }
352 fprintf(fout, " plex org %s", org);
[2334]353 mr_free(org);
354
[128]355 if (raidrec->plex[i].raidlevel != -1) {
356 fprintf(fout, " %ik", raidrec->plex[i].stripesize);
357 }
358 fprintf(fout, "\n");
359
360 for (j = 0; j < raidrec->plex[i].subdisks; ++j) {
[2334]361 fprintf(fout, " sd drive %s size 0\n", raidrec->plex[i].sd[j].which_device);
[128]362 }
[1]363 }
[128]364#else
365 assert(raidrec != NULL);
366 assert(fout != NULL);
367
368 fprintf(fout, "raiddev %s\n", raidrec->raid_device);
[558]369 if (raidrec->raid_level == -2) {
370 fprintf(fout, " raid-level multipath\n");
371 } else if (raidrec->raid_level == -1) {
[128]372 fprintf(fout, " raid-level linear\n");
373 } else {
374 fprintf(fout, " raid-level %d\n",
375 raidrec->raid_level);
[1]376 }
[128]377 fprintf(fout, " nr-raid-disks %d\n",
378 raidrec->data_disks.entries);
[558]379 if (raidrec->spare_disks.entries > 0) {
380 fprintf(fout, " nr-spare-disks %d\n",
381 raidrec->spare_disks.entries);
382 }
[128]383 if (raidrec->parity_disks.entries > 0) {
384 fprintf(fout, " nr-parity-disks %d\n",
385 raidrec->parity_disks.entries);
[1]386 }
[128]387 fprintf(fout, " persistent-superblock %d\n",
388 raidrec->persistent_superblock);
[558]389 if (raidrec->chunk_size > -1) {
390 fprintf(fout, " chunk-size %d\n", raidrec->chunk_size);
391 }
392 if (raidrec->parity > -1) {
393 switch(raidrec->parity) {
394 case 0:
395 fprintf(fout, " parity-algorithm left-asymmetric\n");
396 break;
397 case 1:
398 fprintf(fout, " parity-algorithm right-asymmetric\n");
399 break;
400 case 2:
401 fprintf(fout, " parity-algorithm left-symmetric\n");
402 break;
403 case 3:
404 fprintf(fout, " parity-algorithm right-symmetric\n");
405 break;
406 default:
407 fatal_error("Unknown RAID parity algorithm.");
408 break;
409 }
410 }
[128]411 save_additional_vars_to_file(&raidrec->additional_vars, fout);
412 fprintf(fout, "\n");
413 save_disklist_to_file("raid-disk", &raidrec->data_disks, fout);
414 save_disklist_to_file("spare-disk", &raidrec->spare_disks, fout);
415 save_disklist_to_file("parity-disk", &raidrec->parity_disks, fout);
416 save_disklist_to_file("failed-disk", &raidrec->failed_disks, fout);
417 fprintf(fout, "\n");
[1]418#endif
419}
420
421/**
422 * Retrieve the next line from a raidtab stream.
423 * @param fin The file to read the input from.
424 * @param label Where to put the line's label.
425 * @param value Where to put the line's value.
426 * @return 0 if the line was read and stored successfully, 1 if we're at end of file.
427 */
[2407]428void get_next_raidtab_line(FILE * fin, char **label, char **value)
[1]429{
[2357]430 char *incoming = NULL;
[128]431 char *p;
[3147]432 char *q;
[1]433
[128]434 assert(fin != NULL);
[1]435
[128]436 if (feof(fin)) {
[2407]437 return;
[1]438 }
[2357]439 for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
440 mr_strip_spaces(incoming);
[128]441 p = strchr(incoming, ' ');
442 if (strlen(incoming) < 3 || incoming[0] == '#' || !p) {
[2357]443 mr_free(incoming);
[128]444 continue;
445 }
446 *(p++) = '\0';
447 while (*p == ' ') {
448 p++;
449 }
[2407]450 mr_asprintf(*label, "%s", incoming);
451 mr_asprintf(*value, "%s", p);
[2357]452 mr_free(incoming);
[2407]453 return;
[128]454 }
[2357]455 mr_free(incoming);
[2407]456 return;
[1]457}
458
459
460
461/**
462 * Load a raidtab file into a raidlist structure.
463 * @param raidlist The raidlist to fill.
464 * @param fname The file to read from.
465 * @return 0 for success, 1 for failure.
466 */
467#ifdef __FreeBSD__
[128]468int load_raidtab_into_raidlist(struct raidlist_itself *raidlist,
469 char *fname)
[1]470{
[128]471 FILE *fin;
472 int items;
[1]473
[128]474 raidlist->spares.entries = 0;
475 raidlist->disks.entries = 0;
476 if (length_of_file(fname) < 5) {
477 log_it("Raidtab is very small or non-existent. Ignoring it.");
478 raidlist->entries = 0;
479 return (0);
[1]480 }
[128]481 if (!(fin = fopen(fname, "r"))) {
482 log_it("Cannot open raidtab");
483 return (1);
[1]484 }
[128]485 items = 0;
486 log_it("Loading raidtab...");
487 while (!feof(fin)) {
488 int argc;
489 char **argv = get_next_vinum_conf_line(fin, &argc);
490 if (!argv)
491 break;
492 if (!strcmp(argv[0], "drive")) {
493 char *drivename, *devname;
494 if (argc < 4)
495 continue;
496 drivename = argv[1];
497 devname = get_option_val(argc, argv, "device");
498 if (!devname)
499 continue;
[1]500
[128]501 if (get_option_state(argc, argv, "hotspare")) {
[2334]502 strcpy(raidlist->spares.el[raidlist->spares.entries].name, drivename);
503 strcpy(raidlist->spares.el[raidlist->spares.entries]. device, devname);
[128]504 raidlist->spares.el[raidlist->spares.entries].index =
505 raidlist->disks.entries;
506 raidlist->spares.entries++;
507 } else {
[2334]508 strcpy(raidlist->disks.el[raidlist->disks.entries].name, drivename);
509 strcpy(raidlist->disks.el[raidlist->disks.entries].device, devname);
[128]510 raidlist->disks.el[raidlist->disks.entries].index =
511 raidlist->disks.entries;
512 raidlist->disks.entries++;
513 }
514 } else if (!strcmp(argv[0], "volume")) {
515 char *volname;
516 if (argc < 2)
517 continue;
518 volname = argv[1];
519 strcpy(raidlist->el[raidlist->entries].volname, volname);
520 raidlist->el[raidlist->entries].plexes = 0;
521 raidlist->entries++;
522 } else if (!strcmp(argv[0], "plex")) {
523 int raidlevel, stripesize;
524 char *org = 0;
525 char **tmp = 0;
526 if (argc < 3)
527 continue;
528 org = get_option_val(argc, argv, "org");
529 if (!org)
530 continue;
531 if (strcmp(org, "concat")) {
532 tmp = get_option_vals(argc, argv, "org", 2);
533 if (tmp && tmp[1]) {
534 stripesize = (int) (size_spec(tmp[1]) / 1024);
535 } else
536 stripesize = 279;
537 } else
538 stripesize = 0;
[1]539
[128]540 if (!strcmp(org, "concat")) {
541 raidlevel = -1;
542 } else if (!strcmp(org, "striped")) {
543 raidlevel = 0;
544 } else if (!strcmp(org, "raid5")) {
545 raidlevel = 5;
546 } else
547 continue;
548
549 raidlist->el[raidlist->entries - 1].plex
550 [raidlist->el[raidlist->entries - 1].plexes].raidlevel =
551 raidlevel;
552 raidlist->el[raidlist->entries -
553 1].plex[raidlist->el[raidlist->entries -
554 1].plexes].stripesize =
555 stripesize;
556 raidlist->el[raidlist->entries -
557 1].plex[raidlist->el[raidlist->entries -
558 1].plexes].subdisks = 0;
559 raidlist->el[raidlist->entries - 1].plexes++;
560 } else if ((!strcmp(argv[0], "sd"))
561 || (!strcmp(argv[0], "subdisk"))) {
562 char *drive = 0;
563 if (argc < 3)
564 continue;
565 drive = get_option_val(argc, argv, "drive");
566 if (!drive)
567 continue;
568
569 strcpy(raidlist->el[raidlist->entries - 1].plex
570 [raidlist->el[raidlist->entries - 1].plexes - 1].sd
571 [raidlist->el[raidlist->entries - 1].plex
572 [raidlist->el[raidlist->entries - 1].plexes -
573 1].subdisks].which_device, drive);
574 raidlist->el[raidlist->entries -
575 1].plex[raidlist->el[raidlist->entries -
576 1].plexes - 1].subdisks++;
577 }
[1]578 }
[128]579 fclose(fin);
580 log_it("Raidtab loaded successfully.");
[2324]581 log_it("%d RAID devices in raidtab", raidlist->entries);
[128]582 return (0);
[1]583}
584
585
586#else
587
[2407]588int load_raidtab_into_raidlist(struct raidlist_itself *raidlist, char *fname) {
589
590 FILE *fin = NULL;
591 char *label = NULL;
592 char *value = NULL;
[128]593 int items;
594 int v;
[1]595
[128]596 assert(raidlist != NULL);
597 assert_string_is_neither_NULL_nor_zerolength(fname);
[1]598
[128]599 if (length_of_file(fname) < 5) {
600 log_it("Raidtab is very small or non-existent. Ignoring it.");
601 raidlist->entries = 0;
602 return (0);
[1]603 }
[128]604 if (!(fin = fopen(fname, "r"))) {
605 log_it("Cannot open raidtab");
606 return (1);
[1]607 }
[3147]608 malloc_string(label);
609 malloc_string(value);
[128]610 items = 0;
611 log_it("Loading raidtab...");
[2407]612 get_next_raidtab_line(fin, &label, &value);
[128]613 while (!feof(fin)) {
614 log_msg(1, "Looking for raid record #%d", items);
615 initialize_raidrec(&raidlist->el[items]);
616 v = 0;
617 /* find the 'raiddev' entry, indicating the start of the block of info */
618 while (!feof(fin) && strcmp(label, "raiddev")) {
619 strcpy(raidlist->el[items].additional_vars.el[v].label, label);
620 strcpy(raidlist->el[items].additional_vars.el[v].value, value);
[3147]621 log_msg(2,"Found raidtab entry Label: %s Value: %s",raidlist->el[items].additional_vars.el[v].label,raidlist->el[items].additional_vars.el[v].value);
[128]622 v++;
[2407]623 mr_free(label);
624 mr_free(value);
625 get_next_raidtab_line(fin, &label, &value);
[128]626 }
627 raidlist->el[items].additional_vars.entries = v;
628 if (feof(fin)) {
629 log_msg(1, "No more records.");
630 continue;
631 }
632 log_msg(2, "Record #%d (%s) found", items, value);
633 strcpy(raidlist->el[items].raid_device, value);
[2407]634 mr_free(label);
635 mr_free(value);
636 for (get_next_raidtab_line(fin, &label, &value); !feof(fin) && strcmp(label, "raiddev"); get_next_raidtab_line(fin, &label, &value)) {
[128]637 process_raidtab_line(fin, &raidlist->el[items], label, value);
[2407]638 mr_free(label);
639 mr_free(value);
[128]640 }
[2407]641 mr_free(label);
642 mr_free(value);
[128]643 items++;
[1]644 }
[2407]645 mr_free(label);
646 mr_free(value);
[128]647 paranoid_fclose(fin);
648 raidlist->entries = items;
649 log_msg(1, "Raidtab loaded successfully.");
650 log_msg(1, "%d RAID devices in raidtab", items);
651 return (0);
[1]652}
653#endif
654
655
656
657
658
659
660
661
662#ifndef __FreeBSD__
663/**
664 * Process a single line from the raidtab and store the results into @p raidrec.
665 * @param fin The stream to read the line from.
666 * @param raidrec The RAID device record to update.
667 * @param label Where to put the label processed.
668 * @param value Where to put the value processed.
669 */
670void
[128]671process_raidtab_line(FILE * fin,
672 struct raid_device_record *raidrec,
673 char *label, char *value)
[1]674{
675
[128]676 /*@ add mallocs * */
[2407]677 char *labelB = NULL;
678 char *valueB = NULL;
[1]679
[128]680 struct list_of_disks *disklist;
681 int index;
682 int v;
[1]683
[128]684 assert(fin != NULL);
685 assert(raidrec != NULL);
686 assert_string_is_neither_NULL_nor_zerolength(label);
687 assert(value != NULL);
[1]688
[128]689 if (!strcmp(label, "raid-level")) {
[558]690 if (!strcmp(value, "multipath")) {
691 raidrec->raid_level = -2;
692 } else if (!strcmp(value, "linear")) {
[128]693 raidrec->raid_level = -1;
694 } else {
695 raidrec->raid_level = atoi(value);
696 }
[3147]697 log_msg(4,"Found raid level %d",raidrec->raid_level);
[128]698 } else if (!strcmp(label, "nr-raid-disks")) { /* ignore it */
699 } else if (!strcmp(label, "nr-spare-disks")) { /* ignore it */
700 } else if (!strcmp(label, "nr-parity-disks")) { /* ignore it */
701 } else if (!strcmp(label, "nr-failed-disks")) { /* ignore it */
702 } else if (!strcmp(label, "persistent-superblock")) {
703 raidrec->persistent_superblock = atoi(value);
704 } else if (!strcmp(label, "chunk-size")) {
705 raidrec->chunk_size = atoi(value);
[558]706 } else if (!strcmp(label, "parity-algorithm")) {
707 if (!strcmp(value, "left-asymmetric")) {
708 raidrec->parity = 0;
709 } else if (!strcmp(value, "right-asymmetric")) {
710 raidrec->parity = 1;
711 } else if (!strcmp(value, "left-symmetric")) {
712 raidrec->parity = 2;
713 } else if (!strcmp(value, "right-symmetric")) {
714 raidrec->parity = 3;
715 } else {
716 log_msg(1, "Unknown RAID parity algorithm '%s'\n.", value);
717 }
[3147]718 log_msg(4,"Found raid parity %d",raidrec->parity);
[128]719 } else if (!strcmp(label, "device")) {
[2407]720 get_next_raidtab_line(fin, &labelB, &valueB);
[128]721 if (!strcmp(labelB, "raid-disk")) {
722 disklist = &raidrec->data_disks;
723 } else if (!strcmp(labelB, "spare-disk")) {
724 disklist = &raidrec->spare_disks;
725 } else if (!strcmp(labelB, "parity-disk")) {
726 disklist = &raidrec->parity_disks;
727 } else if (!strcmp(labelB, "failed-disk")) {
728 disklist = &raidrec->failed_disks;
729 } else {
730 disklist = NULL;
731 }
732 if (!disklist) {
[2324]733 log_it("Ignoring '%s %s' pair of disk %s", labelB, valueB, label);
[128]734 } else {
735 index = atoi(valueB);
736 add_disk_to_raid_device(disklist, value, index);
737 }
[2407]738 mr_free(labelB);
739 mr_free(valueB);
[128]740 } else {
741 v = raidrec->additional_vars.entries;
742 strcpy(raidrec->additional_vars.el[v].label, label);
743 strcpy(raidrec->additional_vars.el[v].value, value);
[3147]744 log_msg(4,"Found additional raid pair #%d: %s / %s",v,raidrec->additional_vars.el[v].label,raidrec->additional_vars.el[v].value);
745 v++;
746 raidrec->additional_vars.entries = v;
[1]747 }
748}
749#endif
750
751
752/**
753 * Save a disklist to a stream in raidtab format.
754 * @param listname One of "raid-disk", "spare-disk", "parity-disk", or "failed-disk".
755 * @param disklist The disklist to save to @p fout.
756 * @param fout The stream to write to.
757 */
[128]758void
759save_disklist_to_file(char *listname,
760 struct list_of_disks *disklist, FILE * fout)
[1]761{
[128]762 int i;
[1]763
[128]764 assert_string_is_neither_NULL_nor_zerolength(listname);
765 assert(disklist != NULL);
766 assert(fout != NULL);
[1]767
[128]768 for (i = 0; i < disklist->entries; i++) {
769 fprintf(fout, " device %s\n",
770 disklist->el[i].device);
771 fprintf(fout, " %-21s %d\n", listname, disklist->el[i].index);
772 }
[1]773}
774
775
776
777
778
779#ifdef __FreeBSD__
780/**
781 * Add a new plex to a volume. The index of the plex will be <tt>v-\>plexes - 1</tt>.
782 * @param v The volume to operate on.
783 * @param raidlevel The RAID level of the new plex.
784 * @param stripesize The stripe size (chunk size) of the new plex.
785 */
[128]786void add_plex_to_volume(struct vinum_volume *v, int raidlevel,
787 int stripesize)
[1]788{
[128]789 v->plex[v->plexes].raidlevel = raidlevel;
790 v->plex[v->plexes].stripesize = stripesize;
791 v->plex[v->plexes].subdisks = 0;
792 ++v->plexes;
[1]793}
794
795/**
796 * For internal use only.
797 */
[128]798char **get_next_vinum_conf_line(FILE * f, int *argc)
[1]799{
[128]800 int cnt = 0;
801 static char *argv[64];
802 char **ap;
[2357]803 char *line = NULL;
804
805 mr_getline(line, f);
[128]806 if (feof(f)) {
807 log_it("[GNVCL] Uh... I reached the EOF.");
808 return 0;
[1]809 }
810
[128]811 for (ap = argv; (*ap = strsep(&line, " \t")) != NULL;)
812 if (**ap != '\0') {
813 if (++ap >= &argv[64])
814 break;
815 cnt++;
816 }
[2357]817 mr_free(line);
[1]818
[128]819 if (strchr(argv[cnt - 1], '\n')) {
820 *(strchr(argv[cnt - 1], '\n')) = '\0';
821 }
822
823 if (argc)
824 *argc = cnt;
825 return argv;
[1]826}
827
828/**
829 * For internal use only.
830 */
[128]831char *get_option_val(int argc, char **argv, char *option)
[1]832{
[128]833 int i;
834 for (i = 0; i < (argc - 1); ++i) {
835 if (!strcmp(argv[i], option)) {
836 return argv[i + 1];
837 }
[1]838 }
[128]839 return 0;
[1]840}
841
842/**
843 * For internal use only.
844 */
[128]845char **get_option_vals(int argc, char **argv, char *option, int nval)
[1]846{
[128]847 int i, j;
848 static char **ret;
849 ret = (char **) malloc(nval * sizeof(char *));
850 for (i = 0; i < (argc - nval); ++i) {
851 if (!strcmp(argv[i], option)) {
852 for (j = 0; j < nval; ++j) {
853 ret[j] = (char *) malloc(strlen(argv[i + j + 1]) + 1);
854 strcpy(ret[j], argv[i + j + 1]);
855 }
856 return ret;
857 }
[1]858 }
[128]859 return 0;
[1]860}
861
862/**
863 * For internal use only.
864 */
[128]865bool get_option_state(int argc, char **argv, char *option)
[1]866{
[128]867 int i;
868 for (i = 0; i < argc; ++i)
869 if (!strcmp(argv[i], option))
870 return TRUE;
[1]871
[128]872 return FALSE;
[1]873}
874
875/**
876 * Taken from Vinum source -- for internal use only.
877 */
878long long size_spec(char *spec)
879{
[128]880 u_int64_t size;
881 char *s;
882 int sign = 1; /* -1 if negative */
[1]883
[128]884 size = 0;
885 if (spec != NULL) { /* we have a parameter */
886 s = spec;
887 if (*s == '-') { /* negative, */
888 sign = -1;
889 s++; /* skip */
890 }
891 if ((*s >= '0') && (*s <= '9')) { /* it's numeric */
892 while ((*s >= '0') && (*s <= '9')) /* it's numeric */
893 size = size * 10 + *s++ - '0'; /* convert it */
894 switch (*s) {
895 case '\0':
896 return size * sign;
[1]897
[128]898 case 'B':
899 case 'b':
900 case 'S':
901 case 's':
902 return size * sign * 512;
[1]903
[128]904 case 'K':
905 case 'k':
906 return size * sign * 1024;
[1]907
[128]908 case 'M':
909 case 'm':
910 return size * sign * 1024 * 1024;
[1]911
[128]912 case 'G':
913 case 'g':
914 return size * sign * 1024 * 1024 * 1024;
[1]915
[128]916 case 'T':
917 case 't':
918 log_it
919 ("Ok, I'm scared... Someone did a TERABYTE+ size-spec");
920 return size * sign * 1024 * 1024 * 1024 * 1024;
[1]921
[128]922 case 'P':
923 case 'p':
924 log_it
925 ("If I was scared last time, I'm freaked out now. Someone actually has a PETABYTE?!?!?!?!");
926 return size * sign * 1024 * 1024 * 1024 * 1024 * 1024;
[1]927
[128]928 case 'E':
929 case 'e':
930 log_it
931 ("Okay, I'm REALLY freaked out. Who could devote a whole EXABYTE to their data?!?!");
932 return size * sign * 1024 * 1024 * 1024 * 1024 * 1024 *
933 1024;
[1]934
[128]935 case 'Z':
936 case 'z':
937 log_it
938 ("WHAT!?!? A ZETABYTE!?!? You've GOT to be kidding me!!!");
939 return size * sign * 1024 * 1024 * 1024 * 1024 * 1024 *
940 1024 * 1024;
941
942 case 'Y':
943 case 'y':
944 log_it
945 ("Oh my gosh. You actually think a YOTTABYTE will get you anywhere? What're you going to do with 1,208,925,819,614,629,174,706,176 bytes?!?!");
946 popup_and_OK
[541]947 ("That sizespec is more than 1,208,925,819,614,629,174,706,176 bytes. You have a shocking amount of data. Please send a screenshot to the list :-)");
[128]948 return size * sign * 1024 * 1024 * 1024 * 1024 * 1024 *
949 1024 * 1024 * 1024;
950 }
951 }
[1]952 }
[128]953 return size * sign;
[1]954}
955
956#endif
957
958
959
960
[3147]961int parse_mdstat(char *mdstat_fname, struct raidlist_itself *raidlist, char *device_prefix) {
[128]962
[3147]963const char delims[] = " ";
[558]964
[3147]965FILE *fin = NULL;
966int res = 0, row, i, index_min;
967int v = 0;
968int lastpos = 0;
969size_t len = 0;
970char *token = NULL;
971char *string = NULL;
972char *cmd = NULL;
973char *pos = NULL;
974char type;
975char *strtmp = NULL;
976char *strtmp2 = NULL;
[558]977
978 // open file
979 if (!(fin = fopen(MDSTAT_FILE, "r"))) {
980 log_msg(1, "Could not open %s.\n", MDSTAT_FILE);
981 return 1;
982 }
983 // initialise record, build progress and row counters
984 raidlist->entries = 0;
985 raidlist->el[raidlist->entries].progress = 999;
986 row = 1;
987 // skip first output row - contains registered RAID levels
988 res = getline(&string, &len, fin);
989 // parse the rest
990 while ( !feof_unlocked(fin) ) {
991 res = getline(&string, &len, fin);
992 if (res <= 0) break;
993 // trim leading spaces
994 pos = string;
[671]995 while (*pos == ' ') pos += 1;
[2323]996 mr_asprintf(strtmp, "%s", pos);
[670]997 strcpy(string, strtmp);
[2324]998 mr_free(strtmp);
[558]999 // if we have newline after only spaces, this is a blank line, update
1000 // counters, otherwise do normal parsing
1001 if (*string == '\n') {
1002 row = 1;
1003 raidlist->entries++;
1004 raidlist->el[raidlist->entries].progress = 999;
1005 } else {
1006 switch (row) {
1007 case 1: // device information
1008 // check whether last line of record and if so skip
1009 pos = strcasestr(string, "unused devices: ");
1010 if (pos == string) {
1011 //raidlist->entries--;
1012 break;
[128]1013 }
[558]1014 // tokenise string
[2321]1015 token = mr_strtok(string, delims, &lastpos);
[558]1016 // get RAID device name
[2323]1017 mr_asprintf(strtmp,"%s%s", device_prefix, token);
[558]1018 strcpy(raidlist->el[raidlist->entries].raid_device, strtmp);
[2324]1019 mr_free(strtmp);
[2241]1020 mr_free(token);
[558]1021 // skip ':' and status
[2321]1022 token = mr_strtok(string, delims, &lastpos);
[2241]1023 mr_free(token);
[2321]1024 token = mr_strtok(string, delims, &lastpos);
[558]1025 if (!strcmp(token, "inactive")) {
1026 log_msg(1, "RAID device '%s' inactive.\n",
1027 raidlist->el[raidlist->entries].raid_device);
1028 paranoid_free(string);
[2241]1029 mr_free(token);
[558]1030 return 1;
[128]1031 }
[2241]1032 mr_free(token);
[559]1033
[558]1034 // get RAID level
[2321]1035 token = mr_strtok(string, delims, &lastpos);
[2937]1036 // skip potential auto-read-only entry
1037 if (!strcmp(token, "(auto-read-only)")) {
1038 mr_free(token);
1039 token = mr_strtok (string, delims, &lastpos);
1040 }
[558]1041 if (!strcmp(token, "multipath")) {
1042 raidlist->el[raidlist->entries].raid_level = -2;
1043 } else if (!strcmp(token, "linear")) {
1044 raidlist->el[raidlist->entries].raid_level = -1;
1045 } else if (!strcmp(token, "raid0")) {
1046 raidlist->el[raidlist->entries].raid_level = 0;
1047 } else if (!strcmp(token, "raid1")) {
1048 raidlist->el[raidlist->entries].raid_level = 1;
1049 } else if (!strcmp(token, "raid4")) {
1050 raidlist->el[raidlist->entries].raid_level = 4;
1051 } else if (!strcmp(token, "raid5")) {
1052 raidlist->el[raidlist->entries].raid_level = 5;
1053 } else if (!strcmp(token, "raid6")) {
1054 raidlist->el[raidlist->entries].raid_level = 6;
1055 } else if (!strcmp(token, "raid10")) {
1056 raidlist->el[raidlist->entries].raid_level = 10;
1057 } else {
[3147]1058 switch (row) {
1059 case 1: // device information
1060 // check whether last line of record and if so skip
1061 log_msg(8, "This is the device line\n");
1062 pos = strcasestr(string, "unused devices: ");
1063 if (pos != NULL) {
1064 break;
1065 }
1066 // tokenise string
1067 token = mr_strtok(string, delims, &lastpos);
1068 if (token == NULL) {
1069 // should not happen !
1070 break;
1071 }
1072 // get RAID device name
1073 mr_asprintf(&strtmp,"%s%s", device_prefix, token);
1074 strncpy(raidlist->el[raidlist->entries].raid_device, strtmp, 63);
1075 raidlist->el[raidlist->entries].raid_device[63] = '\0';
1076 mr_free(strtmp);
1077 mr_free(token);
1078 // store the UUID value in the additional_vars structure
1079 v = raidlist->el[raidlist->entries].additional_vars.entries;
1080 strcpy(raidlist->el[raidlist->entries].additional_vars.el[v].label, "UUID");
1081 mr_asprintf(&cmd,"mdadm --detail %s | grep UUID | cut -d: -f2- | sed 's/^ *//'", raidlist->el[raidlist->entries].raid_device);
1082 mr_asprintf(&strtmp, "%s", call_program_and_get_last_line_of_output(cmd));
1083 strcpy(raidlist->el[raidlist->entries].additional_vars.el[v].value, strtmp);
1084 mr_free(strtmp);
1085 v++;
1086 // store the Version value in the additional_vars structure
1087 strcpy(raidlist->el[raidlist->entries].additional_vars.el[v].label, "Version");
1088 mr_asprintf(&cmd,"mdadm --detail %s | grep Version | cut -d: -f2- | sed 's/^ *//'", raidlist->el[raidlist->entries].raid_device);
1089 mr_asprintf(&strtmp, "%s", call_program_and_get_last_line_of_output(cmd));
1090 strcpy(raidlist->el[raidlist->entries].additional_vars.el[v].value, strtmp);
1091 mr_free(strtmp);
1092 v++;
1093 raidlist->el[raidlist->entries].additional_vars.entries = v;
1094 // skip ':' and status
1095 token = mr_strtok (string, delims, &lastpos);
1096 if (token == NULL) {
1097 // should not happen !
1098 break;
1099 }
1100 mr_free(token);
1101 token = mr_strtok (string, delims, &lastpos);
1102 if (token == NULL) {
1103 // should not happen !
1104 break;
1105 }
1106 if (!strcmp(token, "inactive")) {
1107 log_msg(1, "RAID device '%s' inactive.\n",
1108 raidlist->el[raidlist->entries].raid_device);
1109 mr_free(string);
1110 mr_free(token);
1111 return 1;
1112 }
1113 mr_free(token);
[559]1114
[558]1115 // get RAID devices (type, index, device)
1116 // Note: parity disk for RAID4 is last normal disk, there is no '(P)'
1117 raidlist->el[raidlist->entries].data_disks.entries = 0;
1118 raidlist->el[raidlist->entries].spare_disks.entries = 0;
1119 raidlist->el[raidlist->entries].failed_disks.entries = 0;
[565]1120 while((token = mr_strtok (string, delims, &lastpos))) {
[558]1121 if ((pos = strstr(token, "("))) {
1122 type = *(pos+1);
1123 } else {
1124 type = ' ';
1125 }
1126 pos = strstr(token, "[");
1127 *pos = '\0';
1128 switch(type) {
1129 case ' ': // normal data disks
1130 raidlist->el[raidlist->entries].data_disks.el[raidlist->el[raidlist->entries].data_disks.entries].index = atoi(pos + 1);
[2323]1131 mr_asprintf(strtmp,"%s%s", device_prefix, token);
[558]1132 strcpy(raidlist->el[raidlist->entries].data_disks.el[raidlist->el[raidlist->entries].data_disks.entries].device, strtmp);
[2324]1133 mr_free(strtmp);
[558]1134 raidlist->el[raidlist->entries].data_disks.entries++;
1135 break;
1136 case 'S': // spare disks
1137 raidlist->el[raidlist->entries].spare_disks.el[raidlist->el[raidlist->entries].spare_disks.entries].index = atoi(pos + 1);
[2323]1138 mr_asprintf(strtmp,"%s%s", device_prefix, token);
[558]1139 strcpy(raidlist->el[raidlist->entries].spare_disks.el[raidlist->el[raidlist->entries].spare_disks.entries].device, strtmp);
[2324]1140 mr_free(strtmp);
[558]1141 raidlist->el[raidlist->entries].spare_disks.entries++;
1142 break;
1143 case 'F': // failed disks
1144 raidlist->el[raidlist->entries].failed_disks.el[raidlist->el[raidlist->entries].failed_disks.entries].index = atoi(pos + 1);
[2323]1145 mr_asprintf(strtmp,"%s%s", device_prefix, token);
[558]1146 strcpy(raidlist->el[raidlist->entries].failed_disks.el[raidlist->el[raidlist->entries].failed_disks.entries].device, strtmp);
[2324]1147 mr_free(strtmp);
[558]1148 raidlist->el[raidlist->entries].failed_disks.entries++;
1149 log_it("At least one failed disk found in RAID array.\n");
1150 break;
1151 default: // error
1152 log_msg(1, "Unknown device type '%c'\n", type);
1153 paranoid_free(string);
[559]1154 paranoid_free(token);
[558]1155 return 1;
1156 break;
1157 }
[2241]1158 mr_free(token);
[558]1159 }
[559]1160
[3147]1161 // get RAID devices (type, index, device)
1162 // Note: parity disk for RAID4 is last normal disk, there is no '(P)'
1163 raidlist->el[raidlist->entries].data_disks.entries = 0;
1164 raidlist->el[raidlist->entries].spare_disks.entries = 0;
1165 raidlist->el[raidlist->entries].failed_disks.entries = 0;
1166 while((token = mr_strtok (string, delims, &lastpos))) {
1167 if ((pos = strstr(token, "("))) {
1168 type = *(pos+1);
1169 } else {
1170 type = ' ';
1171 }
1172 pos = strstr(token, "[");
1173 *pos = '\0';
1174 switch(type) {
1175 case ' ': // normal data disks
1176 raidlist->el[raidlist->entries].data_disks.el[raidlist->el[raidlist->entries].data_disks.entries].index = atoi(pos + 1);
1177 mr_asprintf(&strtmp,"%s%s", device_prefix, token);
1178 strcpy(raidlist->el[raidlist->entries].data_disks.el[raidlist->el[raidlist->entries].data_disks.entries].device, strtmp);
1179 mr_free(strtmp);
1180 raidlist->el[raidlist->entries].data_disks.entries++;
1181 break;
1182 case 'S': // spare disks
1183 raidlist->el[raidlist->entries].spare_disks.el[raidlist->el[raidlist->entries].spare_disks.entries].index = atoi(pos + 1);
1184 mr_asprintf(&strtmp,"%s%s", device_prefix, token);
1185 strcpy(raidlist->el[raidlist->entries].spare_disks.el[raidlist->el[raidlist->entries].spare_disks.entries].device, strtmp);
1186 mr_free(strtmp);
1187 raidlist->el[raidlist->entries].spare_disks.entries++;
1188 break;
1189 case 'F': // failed disks
1190 raidlist->el[raidlist->entries].failed_disks.el[raidlist->el[raidlist->entries].failed_disks.entries].index = atoi(pos + 1);
1191 mr_asprintf(&strtmp,"%s%s", device_prefix, token);
1192 strcpy(raidlist->el[raidlist->entries].failed_disks.el[raidlist->el[raidlist->entries].failed_disks.entries].device, strtmp);
1193 mr_free(strtmp);
1194 raidlist->el[raidlist->entries].failed_disks.entries++;
1195 log_it("At least one failed disk found in RAID array.\n");
1196 break;
1197 default: // error
1198 log_msg(1, "Unknown device type '%c'\n", type);
1199 mr_free(string);
1200 mr_free(token);
1201 return 1;
1202 break;
1203 }
1204 mr_free(token);
1205 }
1206
[558]1207 // adjust index for each device so that it starts with 0 for every type
1208 index_min = 99;
1209 for (i=0; i<raidlist->el[raidlist->entries].data_disks.entries;i++) {
[3147]1210 if (raidlist->el[raidlist->entries].data_disks.el[i].index < index_min) {
1211 index_min = raidlist->el[raidlist->entries].data_disks.el[i].index;
1212 }
[558]1213 }
1214 if (index_min > 0) {
[3147]1215 for (i=0; i<raidlist->el[raidlist->entries].data_disks.entries;i++) {
1216 raidlist->el[raidlist->entries].data_disks.el[i].index = raidlist->el[raidlist->entries].data_disks.el[i].index - index_min;
1217 }
[558]1218 }
1219 index_min = 99;
1220 for (i=0; i<raidlist->el[raidlist->entries].spare_disks.entries;i++) {
[3147]1221 if (raidlist->el[raidlist->entries].spare_disks.el[i].index < index_min) {
1222 index_min = raidlist->el[raidlist->entries].spare_disks.el[i].index;
1223 }
[558]1224 }
1225 if (index_min > 0) {
[3147]1226 for (i=0; i<raidlist->el[raidlist->entries].spare_disks.entries;i++) {
1227 raidlist->el[raidlist->entries].spare_disks.el[i].index = raidlist->el[raidlist->entries].spare_disks.el[i].index - index_min;
1228 }
[558]1229 }
1230 index_min = 99;
1231 for (i=0; i<raidlist->el[raidlist->entries].failed_disks.entries;i++) {
[3147]1232 if (raidlist->el[raidlist->entries].failed_disks.el[i].index < index_min) {
1233 index_min = raidlist->el[raidlist->entries].failed_disks.el[i].index;
1234 }
[558]1235 }
1236 if (index_min > 0) {
[3147]1237 for (i=0; i<raidlist->el[raidlist->entries].failed_disks.entries;i++) {
1238 raidlist->el[raidlist->entries].failed_disks.el[i].index = raidlist->el[raidlist->entries].failed_disks.el[i].index - index_min;
1239 }
[558]1240 }
1241 break;
[3147]1242case 2: // config information
[558]1243 // check for persistent super block
1244 if (strcasestr(string, "super non-persistent")) {
[3147]1245 raidlist->el[raidlist->entries].persistent_superblock = 0;
1246 } else {
1247 raidlist->el[raidlist->entries].persistent_superblock = 1;
1248 }
1249 // extract chunk size
1250 if (!(pos = strcasestr(string, "k chunk"))) {
1251 raidlist->el[raidlist->entries].chunk_size = -1;
1252 } else {
1253 while (*pos != ' ') {
1254 pos -= 1;
1255 if (pos < string) {
1256 log_it("String underflow!\n");
1257 mr_free(string);
1258 return 1;
1259 }
1260 }
1261 raidlist->el[raidlist->entries].chunk_size = atoi(pos + 1);
1262 }
1263 // extract parity if present
1264 if ((pos = strcasestr(string, "algorithm"))) {
1265 raidlist->el[raidlist->entries].parity = atoi(pos + 9);
1266 } else {
1267 raidlist->el[raidlist->entries].parity = -1;
1268 }
1269 break;
1270 case 3: // optional build status information
1271 if (!(pos = strchr(string, '\%'))) {
1272 if (strcasestr(string, "delayed")) {
1273 raidlist->el[raidlist->entries].progress = -1; // delayed (therefore, stuck at 0%)
1274 } else {
1275 raidlist->el[raidlist->entries].progress = 999; // not found
1276 }
1277 } else {
1278 while (*pos != ' ') {
1279 pos -= 1;
1280 if (pos < string) {
1281 printf("ERROR: String underflow!\n");
1282 mr_free(string);
1283 return 1;
1284 }
1285 }
1286 raidlist->el[raidlist->entries].progress = atoi(pos);
1287 }
1288 break;
1289 default: // error or IN PROGRESS
1290 if (raidlist->el[raidlist->entries].progress != -1 &&
1291 raidlist->el[raidlist->entries].progress != 999) {
1292 log_msg(1, "Row %d should not occur in record!\n", row);
1293 }
1294 break;
1295 }
1296 row++;
[558]1297 }
[3147]1298 // free string
1299 mr_free(string);
1300}
1301// close file
1302fclose(fin);
1303// return success
1304return 0;
[558]1305
[1]1306}
1307
1308
1309
[558]1310
[3147]1311int create_raidtab_from_mdstat(char *mdstat_fname,char *raidtab_fname)
[1]1312{
[128]1313 struct raidlist_itself *raidlist;
1314 int retval = 0;
[1]1315
[128]1316 raidlist = malloc(sizeof(struct raidlist_itself));
[1]1317
[558]1318 // FIXME: Prefix '/dev/' should really be dynamic!
[3147]1319 if (parse_mdstat(mdstat_fname,raidlist, "/dev/")) {
1320 log_to_screen("Sorry, cannot read %s", mdstat_fname);
[128]1321 return (1);
1322 }
1323
1324 retval += save_raidlist_to_raidtab(raidlist, raidtab_fname);
1325 return (retval);
[1]1326}
1327
1328
1329
1330/* @} - end of raidGroup */
Note: See TracBrowser for help on using the repository browser.