Ignore:
Timestamp:
Sep 25, 2013, 9:03:25 AM (11 years ago)
Author:
Bruno Cornec
Message:
  • revert r3188 & r3189 as I started to work on branch 3.0 before deciding it was much better to do it in 3.2. This will allow some small maintenance work on 3.0 if needed, while pushing all the rest to 3.2 and providing early access to it.
File:
1 edited

Legend:

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

    r3188 r3192  
    335335#ifdef __FreeBSD__
    336336    int i, j;
    337     char *org = NULL;
    338337
    339338    fprintf(fout, "\nvolume %s\n", raidrec->volname);
    340339    for (i = 0; i < raidrec->plexes; ++i) {
     340        char org[24];
    341341        switch (raidrec->plex[i].raidlevel) {
    342342        case -1:
    343             mr_asprintf(org, "concat");
     343            strcpy(org, "concat");
    344344            break;
    345345        case 0:
    346             mr_asprintf(org, "striped");
     346            strcpy(org, "striped");
    347347            break;
    348348        case 5:
    349             mr_asprintf(org, "raid5");
     349            strcpy(org, "raid5");
    350350            break;
    351351        }
    352352        fprintf(fout, "  plex org %s", org);
    353         mr_free(org);
    354 
    355353        if (raidrec->plex[i].raidlevel != -1) {
    356354            fprintf(fout, " %ik", raidrec->plex[i].stripesize);
     
    359357
    360358        for (j = 0; j < raidrec->plex[i].subdisks; ++j) {
    361             fprintf(fout, "    sd drive %s size 0\n", raidrec->plex[i].sd[j].which_device);
     359            fprintf(fout, "    sd drive %s size 0\n",
     360                    raidrec->plex[i].sd[j].which_device);
    362361        }
    363362    }
     
    428427int get_next_raidtab_line(FILE * fin, char *label, char *value)
    429428{
    430     char *incoming = NULL;
     429    char *incoming;
    431430    char *p;
    432 
     431    char *q;
     432
     433    malloc_string(incoming);
    433434    assert(fin != NULL);
    434435    assert(label != NULL);
     
    437438    label[0] = value[0] = '\0';
    438439    if (feof(fin)) {
     440        paranoid_free(incoming);
    439441        return (1);
    440442    }
    441     for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
    442         mr_strip_spaces(incoming);
     443    for (q = fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin) && (q != NULL);
     444         q = fgets(incoming, MAX_STR_LEN - 1, fin)) {
     445        strip_spaces(incoming);
    443446        p = strchr(incoming, ' ');
    444447        if (strlen(incoming) < 3 || incoming[0] == '#' || !p) {
    445             mr_free(incoming);
    446448            continue;
    447449        }
     
    452454        strcpy(label, incoming);
    453455        strcpy(value, p);
    454         mr_free(incoming);
     456        paranoid_free(incoming);
    455457        return (0);
    456458    }
    457     mr_free(incoming);
    458459    return (1);
    459460}
     
    472473{
    473474    FILE *fin;
     475    char *tmp1 = NULL;
    474476    int items;
    475477
     
    502504
    503505            if (get_option_state(argc, argv, "hotspare")) {
    504                 strcpy(raidlist->spares.el[raidlist->spares.entries].name, drivename);
    505                 strcpy(raidlist->spares.el[raidlist->spares.entries].  device, devname);
     506                strcpy(raidlist->spares.el[raidlist->spares.entries].name,
     507                       drivename);
     508                strcpy(raidlist->spares.el[raidlist->spares.entries].
     509                       device, devname);
    506510                raidlist->spares.el[raidlist->spares.entries].index =
    507511                    raidlist->disks.entries;
    508512                raidlist->spares.entries++;
    509513            } else {
    510                 strcpy(raidlist->disks.el[raidlist->disks.entries].name, drivename);
    511                 strcpy(raidlist->disks.el[raidlist->disks.entries].device, devname);
     514                strcpy(raidlist->disks.el[raidlist->disks.entries].name,
     515                       drivename);
     516                strcpy(raidlist->disks.el[raidlist->disks.entries].device,
     517                       devname);
    512518                raidlist->disks.el[raidlist->disks.entries].index =
    513519                    raidlist->disks.entries;
     
    581587    fclose(fin);
    582588    log_it("Raidtab loaded successfully.");
    583     log_it("%d RAID devices in raidtab", raidlist->entries);
     589    mr_asprintf(tmp1, "%d RAID devices in raidtab", raidlist->entries);
     590    log_it(tmp1);
     591    mr_free(tmp1);
    584592    return (0);
    585593}
     
    588596#else
    589597
    590 int load_raidtab_into_raidlist(struct raidlist_itself *raidlist, char *fname) {
    591 
    592     FILE *fin = NULL;
    593     char *label = NULL;
    594     char *value = NULL;
     598int load_raidtab_into_raidlist(struct raidlist_itself *raidlist,
     599                               char *fname)
     600{
     601    FILE *fin;
     602    char *label;
     603    char *value;
    595604    int items;
    596605    int v;
     
    671680
    672681    /*@ add mallocs * */
     682    char *tmp = NULL;
    673683    char *labelB;
    674684    char *valueB;
     
    729739        }
    730740        if (!disklist) {
    731             log_it("Ignoring '%s %s' pair of disk %s", labelB, valueB, label);
     741            mr_asprintf(tmp, "Ignoring '%s %s' pair of disk %s", labelB, valueB, label);
     742            log_it(tmp);
     743            mr_free(tmp);
    732744        } else {
    733745            index = atoi(valueB);
     
    799811    static char *argv[64];
    800812    char **ap;
    801     char *line = NULL;
    802 
    803     mr_getline(line, f);
    804     if (feof(f)) {
     813    char *q;
     814    char *line = (char *) malloc(MAX_STR_LEN);
     815
     816    if (!line)
     817        errx(1,
     818             "unable to allocate %i bytes of memory for `char *line' at %s:%i",
     819             MAX_STR_LEN, __FILE__, __LINE__);
     820    q = fgets(line, MAX_STR_LEN, f);
     821    if (feof(f) && (q != NULL)) {
    805822        log_it("[GNVCL] Uh... I reached the EOF.");
    806823        return 0;
     
    813830            cnt++;
    814831        }
    815     mr_free(line);
    816832
    817833    if (strchr(argv[cnt - 1], '\n')) {
     
    11031119            while((token = mr_strtok (string, delims, &lastpos))) {
    11041120                if ((pos = strstr(token, "("))) {
    1105                     type = *(pos+1);
     1121                    type = *(pos+1);
    11061122                } else {
    1107                     type = ' ';
     1123                    type = ' ';
    11081124                }
    11091125                pos = strstr(token, "[");
     
    11111127                switch(type) {
    11121128                case ' ': // normal data disks
    1113                     raidlist->el[raidlist->entries].data_disks.el[raidlist->el[raidlist->entries].data_disks.entries].index = atoi(pos + 1);
    1114                     mr_asprintf(strtmp,"%s%s", device_prefix, token);
    1115                     strcpy(raidlist->el[raidlist->entries].data_disks.el[raidlist->el[raidlist->entries].data_disks.entries].device, strtmp);
    1116                     mr_free(strtmp);
    1117                     raidlist->el[raidlist->entries].data_disks.entries++;
    1118                     break;
     1129                    raidlist->el[raidlist->entries].data_disks.el[raidlist->el[raidlist->entries].data_disks.entries].index = atoi(pos + 1);
     1130                    mr_asprintf(strtmp,"%s%s", device_prefix, token);
     1131                    strcpy(raidlist->el[raidlist->entries].data_disks.el[raidlist->el[raidlist->entries].data_disks.entries].device, strtmp);
     1132                    mr_free(strtmp);
     1133                    raidlist->el[raidlist->entries].data_disks.entries++;
     1134                    break;
    11191135                case 'S': // spare disks
    1120                     raidlist->el[raidlist->entries].spare_disks.el[raidlist->el[raidlist->entries].spare_disks.entries].index = atoi(pos + 1);
    1121                     mr_asprintf(strtmp,"%s%s", device_prefix, token);
    1122                     strcpy(raidlist->el[raidlist->entries].spare_disks.el[raidlist->el[raidlist->entries].spare_disks.entries].device, strtmp);
    1123                     mr_free(strtmp);
    1124                     raidlist->el[raidlist->entries].spare_disks.entries++;
    1125                     break;
     1136                    raidlist->el[raidlist->entries].spare_disks.el[raidlist->el[raidlist->entries].spare_disks.entries].index = atoi(pos + 1);
     1137                    mr_asprintf(strtmp,"%s%s", device_prefix, token);
     1138                    strcpy(raidlist->el[raidlist->entries].spare_disks.el[raidlist->el[raidlist->entries].spare_disks.entries].device, strtmp);
     1139                    mr_free(strtmp);
     1140                    raidlist->el[raidlist->entries].spare_disks.entries++;
     1141                    break;
    11261142                case 'F': // failed disks
    1127                     raidlist->el[raidlist->entries].failed_disks.el[raidlist->el[raidlist->entries].failed_disks.entries].index = atoi(pos + 1);
    1128                     mr_asprintf(strtmp,"%s%s", device_prefix, token);
    1129                     strcpy(raidlist->el[raidlist->entries].failed_disks.el[raidlist->el[raidlist->entries].failed_disks.entries].device, strtmp);
    1130                     mr_free(strtmp);
    1131                     raidlist->el[raidlist->entries].failed_disks.entries++;
    1132                     log_it("At least one failed disk found in RAID array.\n");
    1133                     break;
     1143                    raidlist->el[raidlist->entries].failed_disks.el[raidlist->el[raidlist->entries].failed_disks.entries].index = atoi(pos + 1);
     1144                    mr_asprintf(strtmp,"%s%s", device_prefix, token);
     1145                    strcpy(raidlist->el[raidlist->entries].failed_disks.el[raidlist->el[raidlist->entries].failed_disks.entries].device, strtmp);
     1146                    mr_free(strtmp);
     1147                    raidlist->el[raidlist->entries].failed_disks.entries++;
     1148                    log_it("At least one failed disk found in RAID array.\n");
     1149                    break;
    11341150                default: // error
    1135                     log_msg(1, "Unknown device type '%c'\n", type);
    1136                     mr_free(string);
    1137                     mr_free(token);
    1138                     return 1;
    1139                     break;
     1151                    log_msg(1, "Unknown device type '%c'\n", type);
     1152                    mr_free(string);
     1153                    mr_free(token);
     1154                    return 1;
     1155                    break;
    11401156                }
    11411157                mr_free(token);
     
    11461162            for (i=0; i<raidlist->el[raidlist->entries].data_disks.entries;i++) {
    11471163                if (raidlist->el[raidlist->entries].data_disks.el[i].index < index_min) {
    1148                     index_min = raidlist->el[raidlist->entries].data_disks.el[i].index;
     1164                    index_min = raidlist->el[raidlist->entries].data_disks.el[i].index;
    11491165                }
    11501166            }
    11511167            if (index_min > 0) {
    11521168                for (i=0; i<raidlist->el[raidlist->entries].data_disks.entries;i++) {
    1153                     raidlist->el[raidlist->entries].data_disks.el[i].index = raidlist->el[raidlist->entries].data_disks.el[i].index - index_min;   
     1169                    raidlist->el[raidlist->entries].data_disks.el[i].index = raidlist->el[raidlist->entries].data_disks.el[i].index - index_min;   
    11541170                }
    11551171            }
     
    11571173            for (i=0; i<raidlist->el[raidlist->entries].spare_disks.entries;i++) {
    11581174                if (raidlist->el[raidlist->entries].spare_disks.el[i].index < index_min) {
    1159                     index_min = raidlist->el[raidlist->entries].spare_disks.el[i].index;
     1175                    index_min = raidlist->el[raidlist->entries].spare_disks.el[i].index;
    11601176                }
    11611177            }
    11621178            if (index_min > 0) {
    11631179                for (i=0; i<raidlist->el[raidlist->entries].spare_disks.entries;i++) {
    1164                         raidlist->el[raidlist->entries].spare_disks.el[i].index = raidlist->el[raidlist->entries].spare_disks.el[i].index - index_min; 
     1180                    raidlist->el[raidlist->entries].spare_disks.el[i].index = raidlist->el[raidlist->entries].spare_disks.el[i].index - index_min; 
    11651181                }
    11661182            }
     
    11681184            for (i=0; i<raidlist->el[raidlist->entries].failed_disks.entries;i++) {
    11691185                if (raidlist->el[raidlist->entries].failed_disks.el[i].index < index_min) {
    1170                     index_min = raidlist->el[raidlist->entries].failed_disks.el[i].index;
     1186                    index_min = raidlist->el[raidlist->entries].failed_disks.el[i].index;
    11711187                }
    11721188            }
    11731189            if (index_min > 0) {
    11741190                for (i=0; i<raidlist->el[raidlist->entries].failed_disks.entries;i++) {
    1175                         raidlist->el[raidlist->entries].failed_disks.el[i].index = raidlist->el[raidlist->entries].failed_disks.el[i].index - index_min;   
     1191                    raidlist->el[raidlist->entries].failed_disks.el[i].index = raidlist->el[raidlist->entries].failed_disks.el[i].index - index_min;   
    11761192                }
    11771193            }
     
    11891205            } else {
    11901206                while (*pos != ' ') {
    1191                     pos -= 1;
    1192                     if (pos < string) {
    1193                         log_it("String underflow!\n");
    1194                         mr_free(string);
    1195                         return 1;
    1196                     }
     1207                    pos -= 1;
     1208                    if (pos < string) {
     1209                            log_it("String underflow!\n");
     1210                            mr_free(string);
     1211                            return 1;
     1212                    }
    11971213                }
    11981214                raidlist->el[raidlist->entries].chunk_size = atoi(pos + 1);
     
    12081224            if (!(pos = strchr(string, '\%'))) {
    12091225                if (strcasestr(string, "delayed")) {
    1210                     raidlist->el[raidlist->entries].progress = -1;  // delayed (therefore, stuck at 0%)
     1226                    raidlist->el[raidlist->entries].progress = -1;  // delayed (therefore, stuck at 0%)
    12111227                } else {
    1212                     raidlist->el[raidlist->entries].progress = 999; // not found
     1228                    raidlist->el[raidlist->entries].progress = 999; // not found
    12131229                }
    12141230            } else {
    12151231                while (*pos != ' ') {
    1216                     pos -= 1;
    1217                     if (pos < string) {
    1218                         printf("ERROR: String underflow!\n");
    1219                         mr_free(string);
    1220                         return 1;
    1221                     }
     1232                    pos -= 1;
     1233                    if (pos < string) {
     1234                        printf("ERROR: String underflow!\n");
     1235                            mr_free(string);
     1236                            return 1;
     1237                    }
    12221238                }
    12231239                raidlist->el[raidlist->entries].progress = atoi(pos);
    12241240            }
    12251241            break;
    1226         default: // error or IN PROGRESS
     1242        default: // error or IN PROGRESS
    12271243            if (raidlist->el[raidlist->entries].progress != -1 &&
    12281244                raidlist->el[raidlist->entries].progress != 999) {
     
    12301246            }
    12311247            break;
    1232         }
    1233     row++;
     1248        }
     1249        row++;
    12341250    }
    12351251    // free string
Note: See TracChangeset for help on using the changeset viewer.