Skip to content

Commit

Permalink
photosys: add idx for v6tab to mark its position
Browse files Browse the repository at this point in the history
For linux kernel, it exposes almost 100 lines for /proc/net/snmp6
file. Considering multiple-netns situations, too many lines had to
be read and transferred, which is quite time consuming and space
consuming.

Let's optimize this by adding 'idx' to mark the needed indicators'
position in struct v6tab. During the first time reading, e.i. the
init_net namespace, we record the positions. Then in the following
other netns, we only need to store and transfer indicators' values
according to their positions.

Signed-off-by: Fei Li <[email protected]>
  • Loading branch information
ShirleyFei committed Feb 21, 2023
1 parent 6d3a305 commit fd4ba50
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions photosyst.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ static struct udpv6_stats udpv6_tmp;
struct v6tab {
char *nam;
count_t *val;
int idx; /* the position of nam in /proc/snmp6 file */
};

static struct v6tab v6tab[] = {
Expand Down Expand Up @@ -1195,7 +1196,7 @@ photosyst(struct sstat *si)
if ( (fp = fopen("net/snmp6", "r")) != NULL)
{
count_t countval;
int cur = 0;
int cur = 0, idx = 0;

/*
** one name-value pair per line
Expand All @@ -1210,19 +1211,24 @@ photosyst(struct sstat *si)
if (strcmp(v6tab[cur].nam, nam) == 0)
{
*(v6tab[cur].val) = countval;
v6tab[cur].idx = idx;
}
else
{
for (cur=0; cur < v6tab_entries; cur++)
if (strcmp(v6tab[cur].nam, nam) == 0)
break;

if (cur < v6tab_entries) /* found ? */
if (cur < v6tab_entries) {/* found ? */
*(v6tab[cur].val) = countval;
v6tab[cur].idx = idx;
}
}

if (++cur >= v6tab_entries)
cur = 0;

idx++;
}

memcpy(&si->net.netns[0].ipv6, &ipv6_tmp, sizeof ipv6_tmp);
Expand Down

0 comments on commit fd4ba50

Please sign in to comment.