From: Christian Brauner Date: Mon, 30 Aug 2021 11:52:51 +0000 (+0200) Subject: tree-wide: fix list_entry() X-Git-Tag: lxc-5.0.0~97^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d696c45e73f545c2bdfcc095481bdf048f9f4cd6;p=thirdparty%2Flxc.git tree-wide: fix list_entry() Signed-off-by: Christian Brauner --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index a7565fc71..86ad68b52 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -3569,7 +3569,7 @@ int lxc_map_ids(struct list_head *idmap, pid_t pid) /* Check if we really need to use newuidmap and newgidmap. * If the user is only remapping their own {g,u}id, we don't need it. */ - if (use_shadow && list_len(idmap) == 2) { + if (use_shadow && list_len(map, idmap, head) == 2) { use_shadow = false; list_for_each_entry(map, idmap, head) { if (map->idtype == ID_TYPE_UID && map->range == 1 && diff --git a/src/lxc/confile.c b/src/lxc/confile.c index bb7c3dbfe..a5f7249b7 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -4029,7 +4029,7 @@ static int get_config_idmaps(const char *key, char *retv, int inlen, else memset(retv, 0, inlen); - listlen = list_len(&c->id_map); + listlen = list_len(map, &c->id_map, head); list_for_each_entry(map, &c->id_map, head) { ret = strnprintf(buf, sizeof(buf), "%c %lu %lu %lu", (map->idtype == ID_TYPE_UID) ? 'u' : 'g', @@ -6293,7 +6293,7 @@ static int get_config_net_ipv4_address(const char *key, char *retv, int inlen, else memset(retv, 0, inlen); - listlen = list_len(&netdev->ipv4_addresses); + listlen = list_len(inetdev, &netdev->ipv4_addresses, head); list_for_each_entry(inetdev, &netdev->ipv4_addresses, head) { if (!inet_ntop(AF_INET, &inetdev->addr, buf, sizeof(buf))) @@ -6326,7 +6326,7 @@ static int get_config_net_veth_ipv4_route(const char *key, char *retv, int inlen else memset(retv, 0, inlen); - listlen = list_len(&netdev->priv.veth_attr.ipv4_routes); + listlen = list_len(inetdev, &netdev->priv.veth_attr.ipv4_routes, head); list_for_each_entry(inetdev, &netdev->priv.veth_attr.ipv4_routes, head) { if (!inet_ntop(AF_INET, &inetdev->addr, buf, sizeof(buf))) return -errno; @@ -6384,7 +6384,7 @@ static int get_config_net_ipv6_address(const char *key, char *retv, int inlen, else memset(retv, 0, inlen); - listlen = list_len(&netdev->ipv6_addresses); + listlen = list_len(inet6dev, &netdev->ipv6_addresses, head); list_for_each_entry(inet6dev, &netdev->ipv6_addresses, head) { if (!inet_ntop(AF_INET6, &inet6dev->addr, buf, sizeof(buf))) return -errno; @@ -6416,7 +6416,7 @@ static int get_config_net_veth_ipv6_route(const char *key, char *retv, int inlen else memset(retv, 0, inlen); - listlen = list_len(&netdev->priv.veth_attr.ipv6_routes); + listlen = list_len(inet6dev, &netdev->priv.veth_attr.ipv6_routes, head); list_for_each_entry(inet6dev, &netdev->priv.veth_attr.ipv6_routes, head) { if (!inet_ntop(AF_INET6, &inet6dev->addr, buf, sizeof(buf))) return -errno; diff --git a/src/lxc/criu.c b/src/lxc/criu.c index 569940b4d..4452d0b0c 100644 --- a/src/lxc/criu.c +++ b/src/lxc/criu.c @@ -169,6 +169,8 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf, int static_args = 23, ret; int netnr = 0; struct mntent mntent; + struct lxc_netdev *netdev; + struct string_entry *strentry; char buf[4096], ttys[32]; @@ -232,7 +234,7 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf, if (ttys[0]) static_args += 2; - static_args += list_len(&opts->c->lxc_conf->netdevs) * 2; + static_args += list_len(netdev, &opts->c->lxc_conf->netdevs, head) * 2; } else { return log_error_errno(-EINVAL, EINVAL, "Invalid criu operation specified"); } @@ -246,7 +248,7 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf, if (opts->user->action_script) static_args += 2; - static_args += 2 * list_len(&opts->c->lxc_conf->mount_entries); + static_args += 2 * list_len(strentry, &opts->c->lxc_conf->mount_entries, head); ret = strnprintf(log, sizeof(log), "%s/%s.log", opts->user->directory, opts->action); if (ret < 0) @@ -453,7 +455,6 @@ static int exec_criu(struct cgroup_ops *cgroup_ops, struct lxc_conf *conf, DECLARE_ARG("--leave-running"); } else if (strequal(opts->action, "restore")) { struct lxc_conf *lxc_conf = opts->c->lxc_conf; - struct lxc_netdev *netdev; DECLARE_ARG("--root"); DECLARE_ARG(opts->c->lxc_conf->rootfs.mount); diff --git a/src/lxc/hlist.h b/src/lxc/hlist.h index 9a088f0d4..c3c16f373 100644 --- a/src/lxc/hlist.h +++ b/src/lxc/hlist.h @@ -961,15 +961,15 @@ static inline void hlist_move_list(struct hlist_head *old, pos && ({ n = pos->member.next; 1; }); \ pos = hlist_entry_safe(n, typeof(*pos), member)) -static inline size_t list_len(struct list_head *list) -{ - size_t i = 0; - - list_for_each(list, list) { - i++; - } - - return i; -} +#define list_len(pos, head, member) \ + ({ \ + size_t __list_len__ = 0; \ + \ + list_for_each_entry(pos, head, member) { \ + (__list_len__)++; \ + } \ + \ + __list_len__; \ + }) #endif /* __LXC_HLIST_H */