From 37ecda5884adb0eeb0883ef1387d9377abf366bc Mon Sep 17 00:00:00 2001 From: Yang Hanlin Date: Tue, 26 Sep 2023 00:44:50 +0800 Subject: [PATCH] Opt out "skip existing BTF" for openEuler kernels --- pkg/pkg/centos.go | 4 ++++ pkg/pkg/fedora.go | 4 ++++ pkg/pkg/openeuler.go | 6 ++++++ pkg/pkg/package.go | 1 + pkg/pkg/rhel.go | 4 ++++ pkg/pkg/ubuntu.go | 4 ++++ pkg/repo/utils.go | 18 ++++++++++-------- 7 files changed, 33 insertions(+), 8 deletions(-) diff --git a/pkg/pkg/centos.go b/pkg/pkg/centos.go index 5609563..9b9970a 100644 --- a/pkg/pkg/centos.go +++ b/pkg/pkg/centos.go @@ -26,6 +26,10 @@ func (pkg *CentOSPackage) Version() kernel.Version { return pkg.KernelVersion } +func (pkg *CentOSPackage) SkipExistingBTF() bool { + return true +} + func (pkg *CentOSPackage) String() string { return pkg.Name } diff --git a/pkg/pkg/fedora.go b/pkg/pkg/fedora.go index 23532a3..a857d5b 100644 --- a/pkg/pkg/fedora.go +++ b/pkg/pkg/fedora.go @@ -26,6 +26,10 @@ func (pkg *FedoraPackage) Version() kernel.Version { return pkg.KernelVersion } +func (pkg *FedoraPackage) SkipExistingBTF() bool { + return true +} + func (pkg *FedoraPackage) String() string { return pkg.Name } diff --git a/pkg/pkg/openeuler.go b/pkg/pkg/openeuler.go index 7181df6..1b01994 100644 --- a/pkg/pkg/openeuler.go +++ b/pkg/pkg/openeuler.go @@ -30,6 +30,12 @@ func (pkg *OpenEulerPackage) Version() kernel.Version { return pkg.KernelVersion } +func (pkg *OpenEulerPackage) SkipExistingBTF() bool { + // It is supposed to build BTF for every kernel present in openEuler YUM repository, + // regardless of whether BTF information already exists in the kernel + return false +} + func (pkg *OpenEulerPackage) Download(ctx context.Context, dir string) (string, error) { localFile := fmt.Sprintf("%s.rpm", pkg.NameOfFile) rpmpath := filepath.Join(dir, localFile) diff --git a/pkg/pkg/package.go b/pkg/pkg/package.go index 3ee3f24..448a63e 100644 --- a/pkg/pkg/package.go +++ b/pkg/pkg/package.go @@ -13,6 +13,7 @@ type Package interface { String() string Filename() string Version() kernel.Version + SkipExistingBTF() bool Download(ctx context.Context, dir string) (string, error) ExtractKernel(ctx context.Context, pkgpath string, vmlinuxPath string) error } diff --git a/pkg/pkg/rhel.go b/pkg/pkg/rhel.go index 89f8efe..d928d93 100644 --- a/pkg/pkg/rhel.go +++ b/pkg/pkg/rhel.go @@ -26,6 +26,10 @@ func (pkg *RHELPackage) Version() kernel.Version { return pkg.KernelVersion } +func (pkg *RHELPackage) SkipExistingBTF() bool { + return true +} + func (pkg *RHELPackage) String() string { return pkg.Name } diff --git a/pkg/pkg/ubuntu.go b/pkg/pkg/ubuntu.go index d9631de..03070db 100644 --- a/pkg/pkg/ubuntu.go +++ b/pkg/pkg/ubuntu.go @@ -41,6 +41,10 @@ func (pkg *UbuntuPackage) Version() kernel.Version { return pkg.KernelVersion } +func (pkg *UbuntuPackage) SkipExistingBTF() bool { + return true +} + func (pkg *UbuntuPackage) String() string { return fmt.Sprintf("%s %s", pkg.Name, pkg.Architecture) } diff --git a/pkg/repo/utils.go b/pkg/repo/utils.go index 4b9a4fa..3b98cd4 100644 --- a/pkg/repo/utils.go +++ b/pkg/repo/utils.go @@ -117,14 +117,16 @@ func processPackage( // Check if BTF is already present in vmlinux (will skip further packages) - hasBTF, err := utils.HasBTFSection(vmlinuxPath) - if err != nil { - return fmt.Errorf("BTF check: %s", err) - } - if hasBTF { - // Removing here is bad for re-runs (it has to re-download) - os.Remove(vmlinuxPath) - return utils.ErrHasBTF + if pkg.SkipExistingBTF() { + hasBTF, err := utils.HasBTFSection(vmlinuxPath) + if err != nil { + return fmt.Errorf("BTF check: %s", err) + } + if hasBTF { + // Removing here is bad for re-runs (it has to re-download) + os.Remove(vmlinuxPath) + return utils.ErrHasBTF + } } // 2nd job: Generate BTF file from vmlinux file -- Gitee