Bug 29472 - Support querying the debuginfod-server for metadata
Summary: Support querying the debuginfod-server for metadata
Status: RESOLVED FIXED
Alias: None
Product: elfutils
Classification: Unclassified
Component: debuginfod (show other bugs)
Version: unspecified
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-08-11 14:43 UTC by Ryan Goldberg
Modified: 2024-06-03 15:27 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
Submit A Patch for 29472 (15.88 KB, patch)
2022-08-22 18:24 UTC, Ryan Goldberg
Details | Diff
Submit A Patch for 29472, bug fix (565 bytes, patch)
2022-08-31 14:52 UTC, Ryan Goldberg
Details | Diff
Submit A Patch for 29472, revised (15.77 KB, patch)
2022-09-02 17:25 UTC, Ryan Goldberg
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryan Goldberg 2022-08-11 14:43:48 UTC
It would be beneficial to be able to query a debuginfod-server for its metadata matching certain conditions. This would allow for operations like seeing what executable files are available without attempting to download them or seeing which files are larger than a certain size, which could be used to prefetch+cache large required files, before the user needs them.

The proposed format is as follows:
debuginfod-find [OPTION]... metadata CONDITION QUERYFMT

Query all of the metadata matching the given CONDITION and return it as described by QUERYFMT

The supported debuginfod-fields are:
    BUILDID, FILENAME, MODIFIED_TIME, SIZE, TYPE, SOURCE_TYPE, SOURCE
and should be referenced using {...}, noting that field names are case insensitive.

CONDITION is a boolean expression composed of debuginfod-fields, constants (strings and integers)
and the: `( ) = != < > <= >= && ||` operators, following the standard conditional precedence order

QUERYFMT is a modified version of the standard printf(3) formatting.
The format is made up of static strings (which may include standard C character escapes for new‐
lines, tabs, and other special characters (not including \0)) and printf(3) type formatters. In 
place of the type specifier in the format string, use the debuginfod-field you wish to query.

For example:

debuginfod-find metadata "{FILENAME}=/usr/bin/grep && {TYPE}=E" "{FILENAME}({BUILDID})\t{SOURCE_TYPE}\n"
Will query all executables with the name /usr/bin/grep and might return the following

/usr/bin/grep(90e7d8894b94f47ad17722ff8658f833f329b035)    R
/usr/bin/grep(e81e4e6e322030178260ae4f6055f781cd4997e1)    F

debuginfod-find metadata "{FILENAME}=/bin/bash" "{FILENAME}-{TYPE}\n"
Might return
/bin/bash-E
/bin/bash-S
/bin/bash-D
Comment 1 Martin Liska 2022-08-12 09:05:02 UTC
I think it's very similar to PR 28284.
Comment 2 Ryan Goldberg 2022-08-22 18:24:57 UTC
Created attachment 14289 [details]
Submit A Patch for 29472

Here is patch which is simpler than the above proposal. It allows for querying by source path and will return a JSON array of metadata (where the metadata for each file is its own JSON object).

The patch was tested using the elfutils try-buildbots on branch users/rgoldber/try-metadata_query

There is a need for this patch as currently, even with work like PR 28284, a user is unable to check what files are accessible with debuginfod, they can only at most try and query by buildid and see if they can get a result. This feature will be used in systemtap PR 27410
Comment 3 Ryan Goldberg 2022-08-31 14:52:10 UTC
Created attachment 14306 [details]
Submit A Patch for 29472, bug fix

Minor bug fix to be applied to the previous patch
Comment 4 Ryan Goldberg 2022-09-02 17:25:49 UTC
Created attachment 14310 [details]
Submit A Patch for 29472, revised

I've revised the previous patch to include the suggestions from elfutils-devel [debuginfod metadata patch review]
Comment 6 Frank Ch. Eigler 2024-06-03 15:27:17 UTC
merged as:

commit d47d93b1049ecfad2f9bb9db30dc630c3d6131ca (HEAD -> master, origin/main)
gpg: Signature made Mon 03 Jun 2024 11:22:56 AM EDT
gpg:                using RSA key 4DD136490411C0A42B28844F258B6EFA0F209D24
gpg: Good signature from "Frank Ch. Eigler <fche@elastic.org>" [ultimate]
Author: Frank Ch. Eigler <fche@redhat.com>
Date:   Mon Oct 31 17:40:01 2022 -0400

    PR29472: debuginfod: add metadata query webapi, C api, client
    
    This patch extends the debuginfod API with a "metadata query"
    operation.  It allows clients to request an enumeration of file names
    known to debuginfod servers, returning a JSON response including the
    matching buildids.  This lets clients later download debuginfo for a
    range of versions of the same named binaries, in case they need to to
    prospective work (like systemtap-based live-patching).  It also lets
    server operators implement prefetch triggering operations for popular
    but slow debuginfo slivers like kernel vdso.debug files on fedora.
    
    Implementation requires a modern enough json-c library, namely 0.11,
    which dates from 2014.  Without that, debuginfod client/server bits
    will refuse to build.
    
    % debuginfod-find metadata file /bin/ls
    % debuginfod-find metadata glob "/usr/local/bin/c*"
    
    Refactored several functions in debuginfod-client.c, because the
    metadata search logic is different for multiple servers (merge all
    responses instead of first responder wins).
    
    Documentation and testing are included.
    
    Signed-off-by: Ryan Goldberg <rgoldber@redhat.com>
    Signed-off-by: Frank Ch. Eigler <fche@redhat.com>