correctly detect leaf classes in tc when the leaf classes are attached to a qdisc instead of a class
Costa Tsaousis (ktsaou) committed
Apr 12, 2014 at 01:15 UTC
ce138752a221f05ca040dacabc0045ef3aaa107c
1 file changed
+37
-12
netdata.c
+37
-12
@@ -3175,6 +3175,7 @@ struct tc_class {
3175
char id[RRD_STATS_NAME_MAX + 1];
3176
char name[RRD_STATS_NAME_MAX + 1];
3177
3178
+ char leafid[RRD_STATS_NAME_MAX + 1];
3179
char parentid[RRD_STATS_NAME_MAX + 1];
3180
3181
int hasparent;
@@ -3195,11 +3196,14 @@ void tc_device_commit(struct tc_device *d)
3196
{
3197
// we only need to add leaf classes
3198
struct tc_class *c, *x;
3198
- for ( c = d->classes ; c ; c = c->next) {
3199
+
3200
+ for ( c = d->classes ; c ; c = c->next)
3201
c->isleaf = 1;
3202
3203
+ for ( c = d->classes ; c ; c = c->next) {
3204
for ( x = d->classes ; x ; x = x->next) {
3202
- if(strcmp(c->id, x->parentid) == 0) {
3205
+ if(x->parentid[0] && (strcmp(c->id, x->parentid) == 0 || strcmp(c->leafid, x->parentid) == 0)) {
3206
+ // debug(D_TC_LOOP, "In device '%s', class '%s' (leafid: '%s') has leaf the class '%s' (parentid: '%s').", d->name, c->name, c->leafid, x->name, x->parentid);
3207
c->isleaf = 0;
3208
x->hasparent = 1;
3209
}
@@ -3207,10 +3211,12 @@ void tc_device_commit(struct tc_device *d)
3211
}
3212
3213
// debugging:
3210
- // for ( c = d->classes ; c ; c = c->next) {
3211
- // if(c->isleaf && c->hasparent) debug(D_TC_LOOP, "Device %s, class %s, OK", d->name, c->id);
3212
- // else debug(D_TC_LOOP, "Device %s, class %s, IGNORE (isleaf: %d, hasparent: %d, parent: %s)", d->name, c->id, c->isleaf, c->hasparent, c->parentid);
3213
- // }
3214
+ /*
3215
+ for ( c = d->classes ; c ; c = c->next) {
3216
+ if(c->isleaf && c->hasparent) debug(D_TC_LOOP, "Device %s, class %s, OK", d->name, c->id);
3217
+ else debug(D_TC_LOOP, "Device %s, class %s, IGNORE (isleaf: %d, hasparent: %d, parent: %s)", d->name, c->id, c->isleaf, c->hasparent, c->parentid);
3218
+ }
3219
+ */
3220
3221
for ( c = d->classes ; c ; c = c->next) {
3222
if(c->isleaf && c->hasparent) break;
@@ -3264,7 +3270,7 @@ void tc_device_set_class_name(struct tc_device *d, char *id, char *name)
3270
for ( c = d->classes ; c ; c = c->next) {
3271
if(strcmp(c->id, id) == 0) {
3272
strncpy(c->name, name, RRD_STATS_NAME_MAX);
3267
- c->name[RRD_STATS_NAME_MAX] = '\0';
3273
+ // no need for null termination - it is already null
3274
break;
3275
}
3276
}
@@ -3285,15 +3291,16 @@ struct tc_device *tc_device_create(char *name)
3291
if(!d) return NULL;
3292
3293
strcpy(d->name, RRD_TYPE_TC ".");
3288
- strncpy(&d->name[RRD_TYPE_TC_LEN + 1], name, RRD_STATS_NAME_MAX - 3);
3289
- d->name[RRD_STATS_NAME_MAX] = '\0';
3294
+ strncpy(&d->name[RRD_TYPE_TC_LEN + 1], name, RRD_STATS_NAME_MAX - RRD_TYPE_TC_LEN - 1);
3295
3296
strcpy(d->id, d->name);
3297
3298
+ // no need for null termination on the strings, because of calloc()
3299
+
3300
return(d);
3301
}
3302
3296
-struct tc_class *tc_class_add(struct tc_device *n, char *id, char *parentid)
3303
+struct tc_class *tc_class_add(struct tc_device *n, char *id, char *parentid, char *leafid)
3304
{
3305
struct tc_class *c;
3306
@@ -3306,6 +3313,9 @@ struct tc_class *tc_class_add(struct tc_device *n, char *id, char *parentid)
3313
strncpy(c->id, id, RRD_STATS_NAME_MAX);
3314
strcpy(c->name, c->id);
3315
if(parentid) strncpy(c->parentid, parentid, RRD_STATS_NAME_MAX);
3316
+ if(leafid) strncpy(c->leafid, leafid, RRD_STATS_NAME_MAX);
3317
+
3318
+ // no need for null termination on the strings, because of calloc()
3319
3320
return(c);
3321
}
@@ -3363,6 +3373,8 @@ void *tc_main(void *ptr)
3373
char *id = strsep(&b, " \n"); // the class major:minor
3374
char *parent = strsep(&b, " \n"); // 'parent' or 'root'
3375
char *parentid = strsep(&b, " \n"); // the parent's id
3376
+ char *leaf = strsep(&b, " \n"); // 'leaf'
3377
+ char *leafid = strsep(&b, " \n"); // leafid
3378
3379
if(id && *id
3380
&& parent && *parent
@@ -3371,9 +3383,22 @@ void *tc_main(void *ptr)
3383
(strcmp(parent, "parent") == 0 && parentid && *parentid)
3384
|| strcmp(parent, "root") == 0
3385
)) {
3374
- if(strcmp(parent, "root") == 0) parentid = NULL;
3386
3376
- class = tc_class_add(device, id, parentid);
3387
+ if(strcmp(parent, "root") == 0) {
3388
+ parentid = NULL;
3389
+ leafid = NULL;
3390
+ }
3391
+ else if(!leaf || strcmp(leaf, "leaf") != 0)
3392
+ leafid = NULL;
3393
+
3394
+ char leafbuf[20 + 1] = "";
3395
+ if(leafid && leafid[strlen(leafid) - 1] == ':') {
3396
+ strncpy(leafbuf, leafid, 20 - 1);
3397
+ strcat(leafbuf, "1");
3398
+ leafid = leafbuf;
3399
+ }
3400
+
3401
+ class = tc_class_add(device, id, parentid, leafid);
3402
}
3403
}
3404
else if(device && class && (strcmp(p, "Sent") == 0)) {