]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
tree-wide: fix list_entry()
authorChristian Brauner <christian.brauner@ubuntu.com>
Mon, 30 Aug 2021 11:52:51 +0000 (13:52 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 30 Aug 2021 12:44:37 +0000 (14:44 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/conf.c
src/lxc/confile.c
src/lxc/criu.c
src/lxc/hlist.h

index a7565fc71462a7604b15e4d3749eddaea7bc0d2e..86ad68b52b0a1ce766e0ef71abac67e6a61de211 100644 (file)
@@ -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 &&
index bb7c3dbfe13702f94a37f30e283cb8c002244450..a5f7249b7ddce491c934ce61b073b550a62a0573 100644 (file)
@@ -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;
index 569940b4db06ea6d89e5125e7643016f71a30781..4452d0b0c385029656feb7be9c41aa5eb04df305 100644 (file)
@@ -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);
index 9a088f0d478fed341b1b463894342faea5503579..c3c16f3733878ccde1a115ddec167599219f57c1 100644 (file)
@@ -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 */