Changeset 3566 for branches


Ignore:
Timestamp:
Apr 13, 2016, 12:58:26 PM (3 years ago)
Author:
bruno
Message:
  • Fix a bug in mr_strip_space (end of string was on char too far)
  • Dynamic memory allocation for load_raidtab_into_raidlist and get_next_raidtab_line
  • Add a test to test_mountlist to rewrite the raitab, allowing comparison with original
  • Fix #780, #781 and #757 with a new raitab handling as a consequence
Location:
branches/3.2/mondo
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mondo/src/common/libmondo-raid.c

    r3380 r3566  
    243243    items++;
    244244    disklist->entries = items;
     245    log_msg(3, "Adding device %s (%d)", device_to_add, index);
    245246}
    246247#endif
     
    372373        fprintf(fout, "    raid-level            linear\n");
    373374    } else {
    374         fprintf(fout, "    raid-level            %d\n",
    375                 raidrec->raid_level);
    376     }
    377     fprintf(fout, "    nr-raid-disks         %d\n",
    378             raidrec->data_disks.entries);
     375        fprintf(fout, "    raid-level            %d\n", raidrec->raid_level);
     376    }
     377    fprintf(fout, "    nr-raid-disks         %d\n", raidrec->data_disks.entries);
    379378    if (raidrec->spare_disks.entries > 0) {
    380         fprintf(fout, "    nr-spare-disks        %d\n",
    381                 raidrec->spare_disks.entries);
     379        fprintf(fout, "    nr-spare-disks        %d\n", raidrec->spare_disks.entries);
    382380    }
    383381    if (raidrec->parity_disks.entries > 0) {
    384         fprintf(fout, "    nr-parity-disks       %d\n",
    385                 raidrec->parity_disks.entries);
    386     }
    387     fprintf(fout, "    persistent-superblock %d\n",
    388             raidrec->persistent_superblock);
     382        fprintf(fout, "    nr-parity-disks       %d\n", raidrec->parity_disks.entries);
     383    }
     384    fprintf(fout, "    persistent-superblock %d\n", raidrec->persistent_superblock);
    389385    if (raidrec->chunk_size > -1) {
    390386      fprintf(fout, "    chunk-size            %d\n", raidrec->chunk_size);
     
    426422 * @return 0 if the line was read and stored successfully, 1 if we're at end of file.
    427423 */
    428 int get_next_raidtab_line(FILE * fin, char *label, char *value)
     424static int get_next_raidtab_line(FILE * fin, char **label, char **value)
    429425{
    430426    char *incoming = NULL;
    431     char *p;
     427    char *p = NULL;
    432428
    433429    assert(fin != NULL);
    434     assert(label != NULL);
    435     assert(value != NULL);
    436 
    437     label[0] = value[0] = '\0';
     430
    438431    if (feof(fin)) {
    439432        return (1);
    440433    }
     434
    441435    for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
     436        log_msg(10,"Found in raidtab line: %s",incoming);
    442437        mr_strip_spaces(incoming);
    443438        p = strchr(incoming, ' ');
     
    450445            p++;
    451446        }
    452         strcpy(label, incoming);
    453         strcpy(value, p);
    454         mr_free(incoming);
     447        *label = incoming;
     448        *value = p;
     449        log_msg(10,"Found in raidtab pair: %s|%s",*label,*value);
    455450        return (0);
    456451    }
    457     mr_free(incoming);
    458452    return (1);
    459453}
     
    468462 */
    469463#ifdef __FreeBSD__
    470 int load_raidtab_into_raidlist(struct raidlist_itself *raidlist,
    471                                char *fname)
     464int load_raidtab_into_raidlist(struct raidlist_itself *raidlist, char *fname)
    472465{
    473466    FILE *fin;
     
    503496            if (get_option_state(argc, argv, "hotspare")) {
    504497                strcpy(raidlist->spares.el[raidlist->spares.entries].name, drivename);
    505                 strcpy(raidlist->spares.el[raidlist->spares.entries].  device, devname);
    506                 raidlist->spares.el[raidlist->spares.entries].index =
    507                     raidlist->disks.entries;
     498                strcpy(raidlist->spares.el[raidlist->spares.entries].device, devname);
     499                raidlist->spares.el[raidlist->spares.entries].index = raidlist->disks.entries;
    508500                raidlist->spares.entries++;
    509501            } else {
    510502                strcpy(raidlist->disks.el[raidlist->disks.entries].name, drivename);
    511503                strcpy(raidlist->disks.el[raidlist->disks.entries].device, devname);
    512                 raidlist->disks.el[raidlist->disks.entries].index =
    513                     raidlist->disks.entries;
     504                raidlist->disks.el[raidlist->disks.entries].index = raidlist->disks.entries;
    514505                raidlist->disks.entries++;
    515506            }
     
    593584    char *label = NULL;
    594585    char *value = NULL;
    595     int items;
    596     int v;
     586    int items = 0;
     587    int v = 0;
    597588
    598589    assert(raidlist != NULL);
     
    608599        return (1);
    609600    }
    610     malloc_string(label);
    611     malloc_string(value);
    612     items = 0;
    613601    log_it("Loading raidtab...");
    614     get_next_raidtab_line(fin, label, value);
     602    get_next_raidtab_line(fin, &label, &value);
    615603    while (!feof(fin)) {
    616604        log_msg(1, "Looking for raid record #%d", items);
     
    621609            strcpy(raidlist->el[items].additional_vars.el[v].label, label);
    622610            strcpy(raidlist->el[items].additional_vars.el[v].value, value);
     611            mr_free(label);
    623612            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);
    624613            v++;
    625             get_next_raidtab_line(fin, label, value);
    626         }
     614            get_next_raidtab_line(fin, &label, &value);
     615        }
     616
    627617        raidlist->el[items].additional_vars.entries = v;
    628618        if (feof(fin)) {
     
    632622        log_msg(2, "Record #%d (%s) found", items, value);
    633623        strcpy(raidlist->el[items].raid_device, value);
    634         for (get_next_raidtab_line(fin, label, value);
    635              !feof(fin) && strcmp(label, "raiddev");
    636              get_next_raidtab_line(fin, label, value)) {
     624        mr_free(label);
     625        for (get_next_raidtab_line(fin, &label, &value); !feof(fin) && strcmp(label, "raiddev"); get_next_raidtab_line(fin, &label, &value)) {
    637626            process_raidtab_line(fin, &raidlist->el[items], label, value);
     627            mr_free(label);
    638628        }
    639629        items++;
    640630    }
     631    mr_free(label);
    641632    paranoid_fclose(fin);
    642633    raidlist->entries = items;
    643634    log_msg(1, "Raidtab loaded successfully.");
    644635    log_msg(1, "%d RAID devices in raidtab", items);
    645     paranoid_free(label);
    646     paranoid_free(value);
    647636    return (0);
    648637}
     
    665654 */
    666655void
    667 process_raidtab_line(FILE * fin,
    668                      struct raid_device_record *raidrec,
    669                      char *label, char *value)
     656process_raidtab_line(FILE * fin, struct raid_device_record *raidrec, char *label, char *value)
    670657{
    671658
    672659    /*@ add mallocs * */
    673     char *labelB;
    674     char *valueB;
     660    char *labelB = NULL;
     661    char *valueB = NULL;
    675662
    676663    struct list_of_disks *disklist;
     
    678665    int v;
    679666
    680     malloc_string(labelB);
    681     malloc_string(valueB);
    682667    assert(fin != NULL);
    683668    assert(raidrec != NULL);
     
    716701        log_msg(4,"Found raid parity %d",raidrec->parity);
    717702    } else if (!strcmp(label, "device")) {
    718         get_next_raidtab_line(fin, labelB, valueB);
     703        get_next_raidtab_line(fin, &labelB, &valueB);
    719704        if (!strcmp(labelB, "raid-disk")) {
    720705            disklist = &raidrec->data_disks;
     
    734719            add_disk_to_raid_device(disklist, value, index);
    735720        }
     721        mr_free(labelB);
    736722    } else {
    737723        v = raidrec->additional_vars.entries;
     
    742728        raidrec->additional_vars.entries = v;
    743729    }
    744     paranoid_free(labelB);
    745     paranoid_free(valueB);
    746730}
    747731#endif
     
    755739 */
    756740void
    757 save_disklist_to_file(char *listname,
    758                       struct list_of_disks *disklist, FILE * fout)
     741save_disklist_to_file(char *listname, struct list_of_disks *disklist, FILE * fout)
    759742{
    760743    int i;
     
    765748
    766749    for (i = 0; i < disklist->entries; i++) {
    767         fprintf(fout, "    device                %s\n",
    768                 disklist->el[i].device);
     750        fprintf(fout, "    device                %s\n", disklist->el[i].device);
    769751        fprintf(fout, "    %-21s %d\n", listname, disklist->el[i].index);
    770752    }
  • branches/3.2/mondo/src/lib/mr_str.c

    r3294 r3566  
    182182        }
    183183        /* Erase the end of the string if needed */
    184         j++;
    185184        in_out[j] = '\0';
    186185    }
  • branches/3.2/mondo/test/test-mountlist.c

    r3564 r3566  
    9191mr_free(flaws_str);
    9292
    93 log_it("before check raidlist content");
    94 log_it("after check raidlist content");
     93log_it("before write again raidlist content");
     94save_raidlist_to_raidtab(raidlist, RAIDTAB_TEST".new");
     95log_it("after write again raidlist content");
    9596
    9697log_it("before create mdadm dev");
     98/*
    9799create_raid_device_via_mdadm(raidlist,"/dev/md0",FALSE);
    98100create_raid_device_via_mdadm(raidlist,"/dev/md1",FALSE);
     101*/
    99102log_it("after create mdadm dev");
    100103
Note: See TracChangeset for help on using the changeset viewer.