Skip to content

Commit

Permalink
net/sysctl: put common multiplier outside the brackets
Browse files Browse the repository at this point in the history
Also add an explanation of the logic behind this calculation.

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
  • Loading branch information
Snorch committed Feb 3, 2025
1 parent 7eaf433 commit 7f35e46
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions criu/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -2149,10 +2149,16 @@ static int dump_netns_conf(struct ns_id *ns, struct cr_imgset *fds)
list_for_each_entry(p, &ns->net.ids, node)
i++;

/*
* Here we allocate one single big buffer for storing multiple arrays
* of protobuf entries and pointers to entries in it and we later use
* xptr_pull_s to claim a part of this buffer of proper size for each
* particular array. Next we read data from sysctl files to those
* arrays and then finally save them into images.
*/
o_buf = buf = xmalloc(i * (sizeof(NetnsId *) + sizeof(NetnsId)) +
size4 * (sizeof(SysctlEntry *) + sizeof(SysctlEntry)) * 2 +
size6 * (sizeof(SysctlEntry *) + sizeof(SysctlEntry)) * 2 +
sizex * (sizeof(SysctlEntry *) + sizeof(SysctlEntry)));
(size4 * 2 + size6 * 2 + sizex) *
(sizeof(SysctlEntry *) + sizeof(SysctlEntry)));
if (!buf)
goto out;

Expand Down

0 comments on commit 7f35e46

Please sign in to comment.