Blame SOURCES/bpftrace-0.11.1-Fix-clear-when-called-on-an-array.patch

cb3401
From ed9caea4efcffdd9f37c67b272324a87abfd20c8 Mon Sep 17 00:00:00 2001
cb3401
From: Jerome Marchand <jmarchan@redhat.com>
cb3401
Date: Thu, 5 Nov 2020 15:17:14 +0100
cb3401
Subject: [PATCH] Fix clear() when called on an array
cb3401
cb3401
Fixes the following error:
cb3401
Error looking up elem: -1
cb3401
terminate called after throwing an instance of 'std::runtime_error'
cb3401
  what():  Could not clear map with ident "@", err=-1
cb3401
Aborted (core dumped)
cb3401
---
cb3401
 src/bpftrace.cpp | 5 +++++
cb3401
 src/imap.h       | 4 ++++
cb3401
 2 files changed, 9 insertions(+)
cb3401
cb3401
diff --git a/src/bpftrace.cpp b/src/bpftrace.cpp
cb3401
index 23b65a5..fe2fb66 100644
cb3401
--- a/src/bpftrace.cpp
cb3401
+++ b/src/bpftrace.cpp
cb3401
@@ -1147,6 +1147,11 @@ int BPFtrace::print_maps()
cb3401
 int BPFtrace::clear_map(IMap &map)
cb3401
 {
cb3401
   std::vector<uint8_t> old_key;
cb3401
+  if (map.is_array_type())
cb3401
+  {
cb3401
+    return zero_map(map);
cb3401
+  }
cb3401
+
cb3401
   try
cb3401
   {
cb3401
     if (map.type_.IsHistTy() || map.type_.IsLhistTy() ||
cb3401
diff --git a/src/imap.h b/src/imap.h
cb3401
index 27d0d74..ca9f424 100644
cb3401
--- a/src/imap.h
cb3401
+++ b/src/imap.h
cb3401
@@ -27,6 +27,10 @@ class IMap
cb3401
     return map_type_ == BPF_MAP_TYPE_PERCPU_HASH ||
cb3401
            map_type_ == BPF_MAP_TYPE_PERCPU_ARRAY;
cb3401
   }
cb3401
+  bool is_array_type()
cb3401
+  {
cb3401
+    return map_type_ == BPF_MAP_TYPE_PERCPU_ARRAY;
cb3401
+  }
cb3401
 
cb3401
   // unique id of this map. Used by (bpf) runtime to reference
cb3401
   // this map
cb3401
-- 
cb3401
2.25.4
cb3401