Пример #1
0
TEST(VolumeMapTestGroup, VolumeMapParseBytes) {
    ssize_t parsedVal = parseBytes("5");
    CHECK(parsedVal == 5);

    parsedVal = parseBytes("5k");
    CHECK(parsedVal = 5 * 1024);

    parsedVal = parseBytes("500K");
    CHECK(parsedVal == 500 * 1024);

    parsedVal = parseBytes("500KB");
    CHECK(parsedVal == 500 * 1024);
}
Пример #2
0
VariableLengthInt::VariableLengthInt(FBufferReader & input) {

	parseBytes(input);
}
Пример #3
0
int _parseFlag(char *flagStr, VolumeMapFlag **flags, size_t *flagCapacity) {
    if (flagStr == NULL) return 0;
    if (flags == NULL) return 1;

    size_t flagIdx = 0;
    char *ptr = flagStr;
    char *sptr = flagStr;
    char *limit = flagStr + strlen(flagStr);
    char *flagName = NULL;
    VolMapPerNodeCacheConfig *cache = NULL;
    char **kvArray = NULL;
    size_t kvCount = 0;

    VolumeMapFlag flag;

    memset(&flag, 0, sizeof(VolumeMapFlag));

    if (sptr == limit) return 0;

    /* advance flagPtr to end of list */
    for (flagIdx = 0; flagIdx < *flagCapacity; flagIdx++) {
        if ((*flags)[flagIdx].type == 0) break;
    }

    ptr = strchr(sptr, '=');
    if (ptr == NULL) ptr = limit;
    *ptr = 0;

    /* now sptr is pointing to the name of the flag;
       ptr is either pointing to the end of the string (equal to limit) or
       is pointing to the character before the first key in a comma
       delimited list of key/value pairs */
    flagName = strdup(sptr);
    sptr = ptr + 1;
    while (sptr < limit) {
        char *vptr = strchr(sptr, '=');
        ptr = strchr(sptr, ',');
        if (ptr == NULL) ptr = limit;
        *ptr = 0;
        if (vptr != NULL) {
            *vptr++ = 0;
        }
        kvArray = (char **) realloc(kvArray, sizeof(char *) * (kvCount + 2));
        if (kvArray == NULL) {
            fprintf(stderr, "Unknown flag: couldn't parse flag name\n");
            goto __parseFlags_exit_unclean;
        }
        kvArray[kvCount++] = sptr;
        kvArray[kvCount++] = vptr;
        sptr = ptr + 1;
    }
    if (flagName == NULL) {
        fprintf(stderr, "Unknown flag: couldn't parse flag name\n");
        goto __parseFlags_exit_unclean;
    }

    /* parse flag */
    if (strcasecmp(flagName, "ro") == 0) {
        flag.type = VOLMAP_FLAG_READONLY;
        if (kvCount > 0) {
            fprintf(stderr, "Flag ro takes no arguments, failed to parse.\n");
            goto __parseFlags_exit_unclean;
        }
    } else if (strcasecmp(flagName, "rec") == 0) {
        flag.type = VOLMAP_FLAG_RECURSIVE;
        if (kvCount > 0) {
            fprintf(stderr, "Flag rec takes no arguments, failed to parse.\n");
            goto __parseFlags_exit_unclean;
        }
    } else if (strcasecmp(flagName, "perNodeCache") == 0) {
        size_t kvIdx = 0;
        flag.type = VOLMAP_FLAG_PERNODECACHE;
        cache = (VolMapPerNodeCacheConfig *) malloc(sizeof(VolMapPerNodeCacheConfig));
        memset(cache, 0, sizeof(VolMapPerNodeCacheConfig));

        /* TODO move these configs into udiRoot.conf */
        cache->cacheSize = 0;
        cache->blockSize = 1024 * 1024; /* default 1MB */
        cache->fstype = strdup("xfs");
        cache->method = strdup("loop");
        flag.value = cache;

        for (kvIdx = 0; kvIdx < kvCount; kvIdx += 2) {
            char *key = kvArray[kvIdx];
            char *value = kvArray[kvIdx + 1];

            if (key == NULL) {
                fprintf(stderr, "Failed to parse volmap flag value\n");
                goto __parseFlags_exit_unclean;
            }
            if (strcasecmp(key, "size") == 0) {
                cache->cacheSize = parseBytes(value);
                if (cache->cacheSize <= 0) {
                    fprintf(stderr, "Invalid size for perNodeCache: %s\n", value);
                    goto __parseFlags_exit_unclean;
                }
            } else if (strcasecmp(key, "fs") == 0) {
                if (cache->fstype != NULL) {
                    free(cache->fstype);
                    cache->fstype = NULL;
                }
                if (value != NULL) {
                    if (strcasecmp(value, "xfs") == 0) {
                        cache->fstype = strdup("xfs");
                    }
                }
                if (cache->fstype == NULL) {
                    fprintf(stderr, "Invalid fstype for perNodeCache: %s\n", value);
                    goto __parseFlags_exit_unclean;
                }
            } else if (strcasecmp(key, "bs") == 0) {
                cache->blockSize = parseBytes(value);
                if (cache->blockSize <= 0) {
                    fprintf(stderr, "Invalid blocksize for perNodeCache: %s\n", value);
                    goto __parseFlags_exit_unclean;
                }
            } else if (strcasecmp(key, "method") == 0) {
                if (cache->method != NULL) {
                    free(cache->method);
                    cache->method = NULL;
                }
                if (value != NULL) {
                    if (strcasecmp(value, "loop") == 0) {
                        cache->method = strdup("loop");
                    }
                }
                if (cache->method == NULL) {
                    fprintf(stderr, "Invalid method for perNodeCache: %s\n", value);
                    goto __parseFlags_exit_unclean;
                }
            }
        }
        if (validate_VolMapPerNodeCacheConfig(cache) != 0) {
            fprintf(stderr, "Invalid configuration for perNodeCache %d\n", validate_VolMapPerNodeCacheConfig(cache));
            goto __parseFlags_exit_unclean;
        }
        cache = NULL;
    } else if (strcasecmp(flagName, "slave") == 0) {
        flag.type = VOLMAP_FLAG_SLAVE;
        if (kvCount > 0) {
            fprintf(stderr, "Flag slave takes no arguments, failed to parse.\n");
            goto __parseFlags_exit_unclean;
        }
    } else if (strcasecmp(flagName, "private") == 0) {
        flag.type = VOLMAP_FLAG_PRIVATE;
        if (kvCount > 0) {
            fprintf(stderr, "Flag private takes no arguments, failed to parse.\n");
            goto __parseFlags_exit_unclean;
        }
    } else {
        fprintf(stderr, "Unknown flag: %s\n", sptr);
        goto __parseFlags_exit_unclean;
    }

    if (flagIdx >= *flagCapacity) {
        VolumeMapFlag *tmp = (VolumeMapFlag *) realloc(*flags, sizeof(VolumeMapFlag) * (*flagCapacity + 2));
        if (tmp == NULL) {
            fprintf(stderr, "Failed to allocate memory!\n");
            goto __parseFlags_exit_unclean;
        }
        *flags = tmp;
        *flagCapacity += 1;
    }
    memcpy(&((*flags)[flagIdx++]), &flag, sizeof(VolumeMapFlag));
    memset(&((*flags)[flagIdx]), 0, sizeof(VolumeMapFlag));

    if (flagName != NULL) {
        free(flagName);
        flagName = NULL;
    }
    if (kvArray != NULL) {
        free(kvArray);
        kvArray = NULL;
    }

    return 0;
__parseFlags_exit_unclean:
    if (flagName != NULL) {
        free(flagName);
        flagName = NULL;
    }
    if (kvArray != NULL) {
        free(kvArray);
        kvArray = NULL;
    }
    if (cache != NULL) {
         free_VolMapPerNodeCacheConfig(cache);
         cache = NULL;
    }
    return 1;
}
Пример #4
0
static int _assign(const char *key, const char *value, void *t_config) {
    UdiRootConfig *config = (UdiRootConfig *)t_config;
    if (strcmp(key, "udiMount") == 0) {
        config->udiMountPoint = strdup(value);
        if (config->udiMountPoint == NULL) return 1;
    } else if (strcmp(key, "loopMount") == 0) {
        config->loopMountPoint = strdup(value);
        if (config->loopMountPoint == NULL) return 1;
    } else if (strcmp(key, "imagePath") == 0) {
        config->imageBasePath = strdup(value);
        if (config->imageBasePath == NULL) return 1;
    } else if (strcmp(key, "udiRootPath") == 0) {
        config->udiRootPath = strdup(value);
        if (config->udiRootPath == NULL) return 1;
    } else if (strcmp(key, "perNodeCachePath") == 0) {
        config->perNodeCachePath = strdup(value);
    } else if (strcmp(key, "perNodeCacheSizeLimit") == 0) {
        config->perNodeCacheSizeLimit = parseBytes(value);
    } else if (strcmp(key, "perNodeCacheAllowedFsType") == 0) {
        char *valueDup = strdup(value);
        char *search = valueDup;
        char *svPtr = NULL;
        char *ptr = NULL;
        while ((ptr = strtok_r(search, " ", &svPtr)) != NULL) {
            char **pncPtr = config->perNodeCacheAllowedFsType +
                    config->perNodeCacheAllowedFsType_size;

            strncpy_StringArray(ptr, strlen(ptr), &pncPtr,
                    &(config->perNodeCacheAllowedFsType),
                    &(config->perNodeCacheAllowedFsType_capacity),
                    PNCALLOWEDFS_ALLOC_BLOCK);
            config->perNodeCacheAllowedFsType_size++;
            search = NULL;
        }
        free(valueDup);
    } else if (strcmp(key, "sitePreMountHook") == 0) {
        config->sitePreMountHook = strdup(value);
        if (config->sitePreMountHook == NULL) return 1;
    } else if (strcmp(key, "sitePostMountHook") == 0) {
        config->sitePostMountHook = strdup(value);
        if (config->sitePostMountHook == NULL) return 1;
    } else if (strcmp(key, "optUdiImage") == 0) {
        config->optUdiImage = strdup(value);
        if (config->optUdiImage == NULL) return 1;
    } else if (strcmp(key, "etcPath") == 0) {
        config->etcPath = strdup(value);
        if (config->etcPath == NULL) return 1;
    } else if (strcmp(key, "allowLocalChroot") == 0) {
        config->allowLocalChroot = atoi(value) != 0;
    } else if (strcmp(key, "autoLoadKernelModule") == 0) {
        config->autoLoadKernelModule = atoi(value);
    } else if (strcmp(key, "mountPropagationStyle") == 0) {
        if (strcmp(value, "private") == 0) {
            config->mountPropagationStyle = VOLMAP_FLAG_PRIVATE;
        } else if (strcmp(value, "slave") == 0) {
            config->mountPropagationStyle = VOLMAP_FLAG_SLAVE;
        } else {
            return 1;
        }
    } else if (strcmp(key, "mountUdiRootWritable") == 0) {
        config->mountUdiRootWritable = atoi(value);
    } else if (strcmp(key, "maxGroupCount") == 0) {
        config->maxGroupCount = strtoul(value, NULL, 10);
    } else if (strcmp(key, "modprobePath") == 0) {
        config->modprobePath = strdup(value);
    } else if (strcmp(key, "insmodPath") == 0) {
        config->insmodPath = strdup(value);
    } else if (strcmp(key, "cpPath") == 0) {
        config->cpPath = strdup(value);
    } else if (strcmp(key, "mvPath") == 0) {
        config->mvPath = strdup(value);
    } else if (strcmp(key, "chmodPath") == 0) {
        config->chmodPath = strdup(value);
    } else if (strcmp(key, "ddPath") == 0) {
        config->ddPath = strdup(value);
    } else if (strcmp(key, "mkfsXfsPath") == 0) {
        config->mkfsXfsPath = strdup(value);
    } else if (strcmp(key, "rootfsType") == 0) {
        config->rootfsType = strdup(value);
    } else if (strcmp(key, "gatewayTimeout") == 0) {
        config->gatewayTimeout = strtoul(value, NULL, 10);
    } else if (strcmp(key, "kmodBasePath") == 0) {
        struct utsname uts;
        memset(&uts, 0, sizeof(struct utsname));
        if (uname(&uts) != 0) {
            fprintf(stderr, "FAILED to get uname data!\n");
            return 1;
        }
        config->kmodBasePath = strdup(value);
        if (config->kmodBasePath == NULL) return 1;
        config->kmodPath = alloc_strgenf("%s/%s", config->kmodBasePath, uts.release);
    } else if (strcmp(key, "kmodCacheFile") == 0) {
        config->kmodCacheFile = strdup(value);
        if (config->kmodCacheFile == NULL) return 1;
    } else if (strcmp(key, "siteFs") == 0) {
        if (config->siteFs == NULL) {
            config->siteFs = (VolumeMap *) malloc(sizeof(VolumeMap));
            memset(config->siteFs, 0, sizeof(VolumeMap));
        }
        if (parseVolumeMapSiteFs(value, config->siteFs) != 0) {
            fprintf(stderr, "FAILED to parse siteFs volumeMap\n");
            return 1;
        }
    } else if (strcmp(key, "siteEnv") == 0) {
        char *valueDup = strdup(value);
        char *search = valueDup;
        char *svPtr = NULL;
        char *ptr = NULL;
        while ((ptr = strtok_r(search, " ", &svPtr)) != NULL) {
            char **siteEnvPtr = config->siteEnv + config->siteEnv_size;
            strncpy_StringArray(ptr, strlen(ptr), &siteEnvPtr, &(config->siteEnv), &(config->siteEnv_capacity), SITEFS_ALLOC_BLOCK);
            config->siteEnv_size++;
            search = NULL;
        }
        free(valueDup);
    } else if (strcmp(key, "siteEnvAppend") == 0) {
        char *valueDup = strdup(value);
        char *search = valueDup;
        char *svPtr = NULL;
        char *ptr = NULL;
        while ((ptr = strtok_r(search, " ", &svPtr)) != NULL) {
            char **siteEnvAppendPtr = config->siteEnvAppend + config->siteEnvAppend_size;
            strncpy_StringArray(ptr, strlen(ptr), &siteEnvAppendPtr, &(config->siteEnvAppend), &(config->siteEnvAppend_capacity), SITEFS_ALLOC_BLOCK);
            config->siteEnvAppend_size++;
            search = NULL;
        }
        free(valueDup);
    } else if (strcmp(key, "siteEnvPrepend") == 0) {
        char *valueDup = strdup(value);
        char *search = valueDup;
        char *svPtr = NULL;
        char *ptr = NULL;
        while ((ptr = strtok_r(search, " ", &svPtr)) != NULL) {
            char **siteEnvPrependPtr = config->siteEnvPrepend + config->siteEnvPrepend_size;
            strncpy_StringArray(ptr, strlen(ptr), &siteEnvPrependPtr, &(config->siteEnvPrepend), &(config->siteEnvPrepend_capacity), SITEFS_ALLOC_BLOCK);
            config->siteEnvPrepend_size++;
            search = NULL;
        }
        free(valueDup);
    } else if (strcmp(key, "imageGateway") == 0) {
        char *valueDup = strdup(value);
        char *search = valueDup;
        int ret = 0;
        char *svPtr = NULL;
        char *ptr = NULL;
        while ((ptr = strtok_r(search, " ", &svPtr)) != NULL) {
            char **gwUrlPtr = config->gwUrl + config->gwUrl_size;
            strncpy_StringArray(ptr, strlen(ptr), &(gwUrlPtr), &(config->gwUrl), &(config->gwUrl_capacity), SERVER_ALLOC_BLOCK);
            config->gwUrl_size++;
            search = NULL;
        }
        free(valueDup);
        return ret;
    } else if (strcmp(key, "batchType") == 0) {
        config->batchType = strdup(value);
        if (config->batchType == NULL) return 1;
    } else if (strcmp(key, "system") == 0) {
        config->system = strdup(value);
        if (config->system == NULL) return 1;
    } else if (strcmp(key, "defaultImageType") == 0) {
        config->defaultImageType = strdup(value);
    } else if (strcmp(key, "nodeContextPrefix") == 0) {
        /* do nothing, this key is defunct */
    } else {
        printf("Couldn't understand key: %s\n", key);
        return 2;
    }
    return 0; 
}
Пример #5
0
bool LH_DriveStatsData::getData(float& value, QString& text, QString& units)
{

    value = 0;
    text = "";
    units = "";

    if(driveInfo.setDrive(ui_->valueText(mon_type)))
    {
        if(dataMode_ & mdmNumbers) ui_->append(mon_item, "Bytes Read");
        if(dataMode_ & mdmNumbers) ui_->append(mon_item, "Bytes Written");
        if(dataMode_ & mdmNumbers) ui_->append(mon_item, "Read Count");
        if(dataMode_ & mdmNumbers) ui_->append(mon_item, "Write Count");
        if(dataMode_ & mdmNumbers) ui_->append(mon_item, "Read Time");
        if(dataMode_ & mdmNumbers) ui_->append(mon_item, "Write Time");
        if(dataMode_ & mdmNumbers) ui_->append(mon_item, "Idle Time");
        if(dataMode_ & mdmNumbers) ui_->append(mon_item, "Queue Depth");
        if(dataMode_ & mdmNumbers) ui_->append(mon_item, "Free Space");
        if(dataMode_ & mdmNumbers) ui_->append(mon_item, "Used Space");
        if(dataMode_ & mdmNumbers) ui_->append(mon_item, "Total Space");

        if(dataMode_ & mdmPie) ui_->append(mon_item, "Disk Space");

        ui_->refresh(mon_item);
        ui_->changeItemSelection();
    }
    else
        driveInfo.update();
    if(driveInfo.valid())
    {
        units = (this->adaptiveUnits() && ui_->setup_unit_selection_->valueText()=="(Auto)")? "" : ui_->setup_unit_selection_->valueText();

        if(ui_->valueText(mon_item) == "Bytes Read")
            parseBytes(driveInfo.BytesRead(), value, text, units);
        if(ui_->valueText(mon_item) == "Bytes Written")
            parseBytes(driveInfo.BytesWritten(), value, text, units);
        if(ui_->valueText(mon_item) == "Read Count")
            value = driveInfo.ReadCount();
        if(ui_->valueText(mon_item) == "Write Count")
            value = driveInfo.WriteCount();
        if(ui_->valueText(mon_item) == "Read Time")
        {
            value = driveInfo.ReadTime();
            units = "%";
        }
        if(ui_->valueText(mon_item) == "Write Time")
        {
            value = driveInfo.WriteTime();
            units = "%";
        }
        if(ui_->valueText(mon_item) == "Idle Time")
        {
            value = driveInfo.IdleTime();
            units = "%";
        }
        if(ui_->valueText(mon_item) == "Queue Depth")
            value = driveInfo.QueueDepth();
        if(ui_->valueText(mon_item) == "Free Space")
            parseBytes(driveInfo.FreeSpace(), value, text, units);
        if(ui_->valueText(mon_item) == "Used Space")
            parseBytes(driveInfo.UsedSpace(), value, text, units);
        if(ui_->valueText(mon_item) == "Total Space")
            parseBytes(driveInfo.TotalSpace(), value, text, units);

        if(ui_->valueText(mon_item) == "Disk Space")
            value = driveInfo.UsedSpace();
    }

    return driveInfo.valid();
}
Пример #6
0
void WebVTTParser::fileFinished()
{
    ASSERT(m_state != Finished);
    parseBytes("\n\n", 2);
    m_state = Finished;
}