Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753214AbbGWBA0 (ORCPT ); Wed, 22 Jul 2015 21:00:26 -0400 Received: from mail-pd0-f173.google.com ([209.85.192.173]:33810 "EHLO mail-pd0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750779AbbGWBAZ (ORCPT ); Wed, 22 Jul 2015 21:00:25 -0400 Subject: Re: [PATCH v2 2/5] bpf: Add function map->ops->map_traverse_elem() to traverse map elems To: Kaixu Xia , davem@davemloft.net, acme@kernel.org, mingo@redhat.com, a.p.zijlstra@chello.nl, masami.hiramatsu.pt@hitachi.com, jolsa@kernel.org References: <1437552572-84748-1-git-send-email-xiakaixu@huawei.com> <1437552572-84748-3-git-send-email-xiakaixu@huawei.com> Cc: wangnan0@huawei.com, linux-kernel@vger.kernel.org, pi3orama@163.com, hekuang@huawei.com From: Alexei Starovoitov Message-ID: <55B03CA6.3070406@plumgrid.com> Date: Wed, 22 Jul 2015 18:00:22 -0700 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 MIME-Version: 1.0 In-Reply-To: <1437552572-84748-3-git-send-email-xiakaixu@huawei.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1422 Lines: 30 On 7/22/15 1:09 AM, Kaixu Xia wrote: > We want to traverse the map elements and make use > of the map value one by one. So add new function > map->ops->map_traverse_elem() to traverse map elements. ... > @@ -26,6 +28,7 @@ struct bpf_map_ops { > void *(*map_lookup_elem)(struct bpf_map *map, void *key); > int (*map_update_elem)(struct bpf_map *map, void *key, void *value, u64 flags); > int (*map_delete_elem)(struct bpf_map *map, void *key); > + int (*map_traverse_elem)(bpf_map_traverse_callback func, struct bpf_map *map); I think 'traverse' is too error prone. Better to add 'map_delete_all_elem' callback. Then convert bpf_prog_array_map_clear() into such callback and similar callback from perf_event_array. Then call it with from bpf_map_release() and drop if (map->map_type == PROG_ARRAY) there. Just unconditionally map->ops->map_delete_all_elem(). Though looking at patch 3. I don't see why you need that. prog_array has to do it due to potential circular dependency between prog_fd of a program that uses a prog_array_fd and stores prog_fd inside that prog_array. In case of perf_event_array no such thing possible. Just release them as part of map_free. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/