Esempio n. 1
0
File: mdt.c Progetto: LaHaine/lmt
int
lmt_mdt_decode_v1_mdtinfo (const char *s, char **mdtnamep,
                           uint64_t *inodes_freep, uint64_t *inodes_totalp,
                           uint64_t *kbytes_freep, uint64_t *kbytes_totalp,
                           List *mdopsp)
{
    int retval = -1;
    char *mdtname = xmalloc (strlen(s) + 1);
    char *cpy = NULL;
    uint64_t kbytes_free, kbytes_total;
    uint64_t inodes_free, inodes_total;
    List mdops = list_create ((ListDelF)free);
    int i = 0;

    if (sscanf (s, "%[^;];%"PRIu64";%"PRIu64";%"PRIu64";%"PRIu64";",
                mdtname, &inodes_free, &inodes_total,
                &kbytes_free, &kbytes_total) != 5) {
        if (lmt_conf_get_proto_debug ())
            msg ("lmt_mdt_v1: parse error: mdtinfo");
        goto done;
    }
    if (!(s = strskip (s, 5, ';'))) {
        if (lmt_conf_get_proto_debug ())
            msg ("lmt_mdt_v1: parse error: skipping mdtinfo");
        goto done;
    }
    while ((cpy = strskipcpy (&s, 3, ';'))) {
        if (i >= optablen_mdt_v1) {
            if (lmt_conf_get_proto_debug ())
                msg ("lmt_mdt_v1: parse error: too many mdops");
            free (cpy);
            goto done;
        }
        strappendfield (&cpy, optab_mdt_v1[i++], ';');
        list_append (mdops, cpy);
    }
    if (strlen (s) > 0) {
        if (lmt_conf_get_proto_debug ())
            msg ("lmt_mdt_v1: parse error: mdtinfo: string not exhausted");
        goto done;
    }
    *mdtnamep = mdtname;
    *inodes_freep = inodes_free;
    *inodes_totalp = inodes_total;
    *kbytes_freep = kbytes_free;
    *kbytes_totalp = kbytes_total;
    *mdopsp = mdops;
    retval = 0;
done:
    if (retval < 0) {
        free (mdtname);
        list_destroy (mdops);
    }
    return retval;
}
Esempio n. 2
0
File: tparse.c Progetto: LLNL/lmt
void
parse_utils (void)
{
    int i;
    const char *s[] = {
        "foo;bar;baz",
        "foo;bar;baz;",
    };

    for (i = 0; i < sizeof (s) / sizeof (s[0]); i++) {
        const char *p;

        p = strskip(s[i], 0, ';');
        msg ("strskip 0: %s", p == s[i] ? "OK" : "FAIL");
        p = strskip(s[i], 1, ';');
        msg ("strskip 1: %s", p == s[i]+4 ? "OK" : "FAIL");
        p = strskip(s[i], 2, ';');
        msg ("strskip 2: %s", p == s[i]+8 ? "OK" : "FAIL");
        p = strskip(s[i], 3, ';');
        msg ("strskip 3: %s", p == s[i]+strlen (s[i]) ? "OK" : "FAIL");
        p = strskip(s[i], 4, ';');
        msg ("strskip 4: %s", p ==  NULL ? "OK" : "FAIL");
    }
    for (i = 0; i < sizeof (s) / sizeof (s[0]); i++) {
        const char *q = s[i];
        char *p;

        while ((p = strskipcpy (&q, 1, ';'))) {
            msg ("strskipcpy 1: '%s'", p);
            free (p);
        }
        if (strlen (q) > 0)
            msg ("strskipcpy failed to consume entire string");
    }
    {
        char *p = xstrdup ("fubar");

        strappendfield (&p, "smurf", ';');
        msg ("strappendfield: %s", p);
        free (p);
    }
    
}
Esempio n. 3
0
File: mdt.c Progetto: LaHaine/lmt
int
lmt_mdt_decode_v1 (const char *s, char **mdsnamep, float *pct_cpup,
                   float *pct_memp, List *mdtinfop)
{
    const int mdtfields = 5 + 3 * optablen_mdt_v1;
    int retval = -1;
    char *mdsname = xmalloc (strlen(s) + 1);
    char *cpy = NULL;
    float pct_mem, pct_cpu;
    List mdtinfo = list_create ((ListDelF)free);

    if (sscanf (s, "%*f;%[^;];%f;%f;", mdsname, &pct_cpu, &pct_mem) != 3) {
        if (lmt_conf_get_proto_debug ())
            msg ("lmt_mdt_v1: parse error: mdsinfo");
        goto done;
    }
    if (!(s = strskip (s, 4, ';'))) {
        if (lmt_conf_get_proto_debug ())
            msg ("lmt_mdt_v1: parse error: skipping mdsinfo");
        goto done;
    }
    mdtinfo = list_create ((ListDelF)free);
    while ((cpy = strskipcpy (&s, mdtfields, ';')))
        list_append (mdtinfo, cpy);
    if (strlen (s) > 0) {
        if (lmt_conf_get_proto_debug ())
            msg ("lmt_mdt_v1: parse error: string not exhausted");
        goto done;
    }
    *mdsnamep = mdsname;
    *pct_cpup = pct_cpu;
    *pct_memp = pct_mem;
    *mdtinfop = mdtinfo;
    retval = 0;
done:
    if (retval < 0) {
        free (mdsname);
        list_destroy (mdtinfo);
    }
    return retval;
}
Esempio n. 4
0
File: ost.c Progetto: haasken/lmt
int
lmt_ost_decode_v2 (const char *s, char **ossnamep, float *pct_cpup,
                   float *pct_memp, List *ostinfop)
{
    int retval = -1;
    char *ossname =  xmalloc (strlen(s) + 1);
    char *cpy = NULL;
    float pct_mem, pct_cpu;
    List ostinfo = list_create ((ListDelF)free);

    if (sscanf (s, "%*f;%[^;];%f;%f;", ossname, &pct_cpu, &pct_mem) != 3) {
        if (lmt_conf_get_proto_debug ())
            msg ("lmt_ost_v2: parse error: oss component");
        goto done;
    }
    if (!(s = strskip (s, 4, ';'))) {
        if (lmt_conf_get_proto_debug ())
            msg ("lmt_ost_v2: parse error: skipping oss component");
        goto done;
    }
    while ((cpy = strskipcpy (&s, 15, ';')))
        list_append (ostinfo, cpy);
    if (strlen (s) > 0) {
        if (lmt_conf_get_proto_debug ())
            msg ("lmt_ost_v2: parse error: string not exhausted");
        goto done;
    }
    *ossnamep = ossname;
    *pct_cpup = pct_cpu;
    *pct_memp = pct_mem;
    *ostinfop = ostinfo;
    retval = 0;
done:
    if (retval < 0) {
        free (ossname);
        list_destroy (ostinfo);
    }
    return retval;
}
Esempio n. 5
0
File: mdt.c Progetto: LaHaine/lmt
int lmt_mds_decode_v2 (const char *s, char **mdsnamep, char **mdtnamep,
                       float *pct_cpup, float *pct_memp,
                       uint64_t *inodes_freep, uint64_t *inodes_totalp,
                       uint64_t *kbytes_freep, uint64_t *kbytes_totalp,
                       List *mdopsp)
{
    char *mdsname = xmalloc (strlen(s) + 1);
    char *mdtname = xmalloc (strlen(s) + 1);
    List mdops = list_create ((ListDelF)free);
    int i = 0, retval = -1;
    char *cpy = NULL;
    float pct_mem, pct_cpu;
    uint64_t kbytes_free, kbytes_total;
    uint64_t inodes_free, inodes_total;

    if (sscanf (s, "%*f;%[^;];%[^;];%f;%f;%"
                PRIu64";%"PRIu64";%"PRIu64";%"PRIu64";", mdsname, mdtname,
                &pct_cpu, &pct_mem, &inodes_free, &inodes_total,
                &kbytes_free, &kbytes_total) != 8) {
        if (lmt_conf_get_proto_debug ())
            msg ("lmt_mds_v2: parse error: mds component");
        goto done;
    }
    if (!(s = strskip (s, 9, ';'))) {
        if (lmt_conf_get_proto_debug ())
            msg ("lmt_mds_v2: parse error: skipping mds component");
        goto done;
    }
    while ((cpy = strskipcpy (&s, 3, ';'))) {
        if (i >= optablen_mds_v2) {
            if (lmt_conf_get_proto_debug ())
                msg ("lmt_mds_v2: parse error: too many mdops");
            free (cpy);
            goto done;
        }
        strappendfield (&cpy, optab_mds_v2[i++], ';');
        if (!list_append (mdops, cpy)) {
            free (cpy);
            goto done;
        }
    }
    if (strlen (s) > 0) {
        msg ("lmt_mds_v2: parse error: string not exhausted");
        goto done;
    }
    *mdsnamep = mdsname;
    *mdtnamep = mdtname;
    *pct_cpup = pct_cpu;
    *pct_memp = pct_mem;
    *inodes_freep = inodes_free;
    *inodes_totalp = inodes_total;
    *kbytes_freep = kbytes_free;
    *kbytes_totalp = kbytes_total;
    *mdopsp = mdops;
    retval = 0;
done:
    if (retval < 0) {
        free (mdsname);
        free (mdtname);
        list_destroy (mdops);
    }
    return retval;
}