Commit a1ac4bc1 authored by yonghong-song's avatar yonghong-song Committed by GitHub

Merge pull request #1561 from joelagnel/bcc-misc-1

Miscellaneous BCC patches
parents df55284e 8e099585
......@@ -10,3 +10,4 @@ if(DEFINED BCC_BACKUP_COMPILE)
endif()
add_library(clang_frontend STATIC loader.cc b_frontend_action.cc tp_frontend_action.cc kbuild_helper.cc ../../common.cc)
target_link_libraries(clang_frontend bcc-static)
......@@ -205,6 +205,11 @@ class TableBase(MutableMapping):
errstr = os.strerror(ct.get_errno())
raise Exception("Could not update table: %s" % errstr)
def __delitem__(self, key):
res = lib.bpf_delete_elem(self.map_fd, ct.byref(key))
if res < 0:
raise KeyError
# override the MutableMapping's implementation of these since they
# don't handle KeyError nicely
def itervalues(self):
......@@ -391,11 +396,6 @@ class HashTable(TableBase):
for k in self: i += 1
return i
def __delitem__(self, key):
res = lib.bpf_delete_elem(self.map_fd, ct.byref(key))
if res < 0:
raise KeyError
class LruHash(HashTable):
def __init__(self, *args, **kwargs):
super(LruHash, self).__init__(*args, **kwargs)
......@@ -430,11 +430,12 @@ class ArrayBase(TableBase):
def __delitem__(self, key):
key = self._normalize_key(key)
# Deleting from array type maps does not have an effect, so
# zero out the entry instead.
super(ArrayBase, self).__delitem__(key)
def clearitem(self, key):
key = self._normalize_key(key)
leaf = self.Leaf()
res = lib.bpf_update_elem(self.map_fd, ct.byref(key), ct.byref(leaf),
0)
res = lib.bpf_update_elem(self.map_fd, ct.byref(key), ct.byref(leaf), 0)
if res < 0:
raise Exception("Could not clear item")
......@@ -461,6 +462,9 @@ class Array(ArrayBase):
def __init__(self, *args, **kwargs):
super(Array, self).__init__(*args, **kwargs)
def __delitem__(self, key):
# Delete in Array type does not have an effect, so zero out instead
self.clearitem(key)
class ProgArray(ArrayBase):
def __init__(self, *args, **kwargs):
......@@ -473,12 +477,6 @@ class ProgArray(ArrayBase):
leaf = self.Leaf(leaf.fd)
super(ProgArray, self).__setitem__(key, leaf)
def __delitem__(self, key):
key = self._normalize_key(key)
res = lib.bpf_delete_elem(self.map_fd, ct.byref(key))
if res < 0:
raise Exception("Could not delete item")
class PerfEventArray(ArrayBase):
def __init__(self, *args, **kwargs):
......@@ -494,8 +492,7 @@ class PerfEventArray(ArrayBase):
if key not in self._open_key_fds:
return
# Delete entry from the array
c_key = self._normalize_key(key)
lib.bpf_delete_elem(self.map_fd, ct.byref(c_key))
super(PerfEventArray, self).__delitem__(key)
key_id = (id(self), key)
if key_id in self.bpf.open_kprobes:
# The key is opened for perf ring buffer
......@@ -665,6 +662,10 @@ class PerCpuArray(ArrayBase):
def __setitem__(self, key, leaf):
super(PerCpuArray, self).__setitem__(key, leaf)
def __delitem__(self, key):
# Delete in this type does not have an effect, so zero out instead
self.clearitem(key)
def sum(self, key):
if isinstance(self.Leaf(), ct.Structure):
raise IndexError("Leaf must be an integer type for default sum functions")
......@@ -728,10 +729,5 @@ class StackTrace(TableBase):
for k in self: i += 1
return i
def __delitem__(self, key):
res = lib.bpf_delete_elem(self.map_fd, ct.byref(key))
if res < 0:
raise KeyError
def clear(self):
pass
......@@ -68,7 +68,7 @@ struct data_t {
BPF_HASH(infotmp, u64, struct val_t);
BPF_PERF_OUTPUT(events);
int trace_entry(struct pt_regs *ctx, const char __user *filename)
int trace_entry(struct pt_regs *ctx, int dfd, const char __user *filename)
{
struct val_t val = {};
u64 id = bpf_get_current_pid_tgid();
......@@ -124,8 +124,8 @@ if debug:
# initialize BPF
b = BPF(text=bpf_text)
b.attach_kprobe(event="sys_open", fn_name="trace_entry")
b.attach_kretprobe(event="sys_open", fn_name="trace_return")
b.attach_kprobe(event="do_sys_open", fn_name="trace_entry")
b.attach_kretprobe(event="do_sys_open", fn_name="trace_return")
TASK_COMM_LEN = 16 # linux/sched.h
NAME_MAX = 255 # linux/limits.h
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment