Skip to content

Finish the work to stop hardcoding paths at build time - #11

Closed
berrange wants to merge 20 commits into
masterfrom
paths
Closed

berrange wants to merge 20 commits into
masterfrom
paths

Conversation

@berrange

@berrange berrange commented Apr 29, 2025 •

Copy link
Copy Markdown
Owner

Over the years we've made various changes to stop hardcoding paths at
build time, but the work is incomplete.

This bit us significantly in Fedora 42 where they have merged the 'sbin'
and 'bin' dirs together. In the build environment we have a clean
install where '/sbin' and '/usr/sbin' are simply symlinks to '/usr/bin'.

Our meson.build logic preferentially looks in '/sbin' and '/usr/sbin'
to find programs, and thus it finds all binaries in '/sbin' and then
hardcodes this path. This happens even for binaries that have always
been in '/usr/bin' and NEVER '/sbin' or '/usr/sbin'

On fresh Fedora installs this is fine as the symlinks match the build
environment.

On upgraded Fedora installs, however, '/sbin' and '/usr/sbin' remain
separate directories and inside they symlink individual binaries,
if-and-only-if the binary was in '/sbin' in Fedora 41.

Thus many of the binaries we found in /sbin don't actually exist and
libvirt thus breaks.

There is really no reason why we should be harcoding any paths at
build time. virCommand happily uses virFindFileInPath for any paths
which are not already absolute. $PATH includes '/sbin' and '/usr/sbin'
when we're running privileged, and when unprivileged we shouldn't need
to run binaries from there.

Summary by Sourcery

Remove hardcoded paths for system binaries in the libvirt build system, improving portability and compatibility across different Linux distributions

Enhancements:

  • Modify meson build configuration to use generic binary names instead of hardcoded full paths
  • Replace hardcoded path macros with direct binary names in source code
  • Improve flexibility of binary detection across different system configurations

Chores:

  • Remove unnecessary path configurations in build scripts
  • Simplify binary detection logic
  • Update test and source files to use generic binary names

Summary by CodeRabbit

  • Refactor
    • Replaced macro-based or absolute-path command invocations with plain string command names across multiple modules and tests, simplifying command execution logic and improving consistency.
    • Updated build configuration scripts to streamline program checks, remove redundant variable exports, and enforce stricter platform requirements for certain features.
    • Adjusted logic for verifying executable presence by searching system PATH instead of using hardcoded paths.
  • New Features
    • Added support for referencing the Perl interpreter path in build configuration.
    • Included the tc utility in recognized firewall tools.
  • Style
    • Improved clarity and maintainability by standardizing command invocation strings throughout the codebase and tests.

berrange added 20 commits April 28, 2025 11:42
This was always undesirable but now causes problems on Fedora 42
where at build time we detect a /sbin path but at runtime this
will only exist on upgraded machines, not fresh installs.

Signed-off-by: Daniel P. Berrangé <[email protected]>
This is redundant since the tests will strip any path component from the
binary name before comparison.

Signed-off-by: Daniel P. Berrangé <[email protected]>
Change the meson rules to always enable numad if on a Linux host, unless
the meson options say not to.

Signed-off-by: Daniel P. Berrangé <[email protected]>
Change the meson rules to always enable numad if on a FreeBSD host,
unless the meson options say not to.

Signed-off-by: Daniel P. Berrangé <[email protected]>
Change the source to assume use of 'ifconfig' on FreeBSD builds,
allowing virCommand to report missing commands at runtime.

Signed-off-by: Daniel P. Berrangé <[email protected]>
Nothing in the tree references RST2MAN or RST2HTML5 variables, only
rst2man_prog & rst2html5_prog, so the former can be removed.

Signed-off-by: Daniel P. Berrangé <[email protected]>
Currently $(PERL) is expanding to nothing, but the spacing-check.pl test
luckily still works via the shebang.

Signed-off-by: Daniel P. Berrangé <[email protected]>
There is no reference to PERL, PYTHON3, XMLLINT or XSLTPROC conf
variables anywhere, only the ${name}_prog meson variables are
used.

Signed-off-by: Daniel P. Berrangé <[email protected]>
Allow virCommand to find 'dmidecode' in $PATH. This command is only
usable when running privileged since it relies on reading from a
privileged kernel file. Thus we can assume both 'bin' and 'sbin' dirs
will be in $PATH and virFindFileInPath will do the right thing to
find it when called by virCommand.

Signed-off-by: Daniel P. Berrangé <[email protected]>
There are no references to an "IP" conf variable nor a meson
'ip_prog' variable so the check serves no purpose.

Signed-off-by: Daniel P. Berrangé <[email protected]>
Gating the iscsi driver backend on a isciadm probe is likely to do
more harm than good as it needlessly disables the code if the dev
forgot to install iscsiadm at build time. As a Linux only command
it is simpler to gate the feature based on the platform choice and
allow missing binaries to be diagnose at runtime.

Signed-off-by: Daniel P. Berrangé <[email protected]>
Allow virCommand to find 'mdevctl' in $PATH. This command is only used
when running privileged in which case both 'bin' and 'sbin' dirs will
be in $PATH, so virFindFileInPath will do the right thing to find it.

Signed-off-by: Daniel P. Berrangé <[email protected]>
Allow virCommand to find 'mm-ctl' in $PATH. This command is only used
when running privileged in which case both 'bin' and 'sbin' dirs will
be in $PATH, so virFindFileInPath will do the right thing to find it.

Signed-off-by: Daniel P. Berrangé <[email protected]>
Allow virCommand to find 'modprobe' & 'rmmod' in $PATH. These commands
are only used when running privileged in which case both 'bin' and
'sbin' dirs will be in $PATH, so virFindFileInPath will do the right
thing to find them.

Signed-off-by: Daniel P. Berrangé <[email protected]>
Allow virCommand to find 'ovs-vsctl' in $PATH. This command is only used
when running privileged in which case both 'bin' and 'sbin' dirs will
be in $PATH, so virFindFileInPath will do the right thing to find it.

Signed-off-by: Daniel P. Berrangé <[email protected]>
Allow virCommand to find 'tc' in $PATH. This command is only used
when running privileged in which case both 'bin' and 'sbin' dirs will
be in $PATH, so virFindFileInPath will do the right thing to find it.

Signed-off-by: Daniel P. Berrangé <[email protected]>
There is no reference to AUGPARSE, BLACK, FLAKE8, PDWTAGS or PYTEST conf
variables anywhere, only the ${name}_prog meson variables are used.

Signed-off-by: Daniel P. Berrangé <[email protected]>
Change the mesonm rules to always enable the LVM driver if on a
Linux host, unless the meson options say not to.

The virCommand APIs will return suitable runtime errors if the
tools are not installed.

Signed-off-by: Daniel P. Berrangé <[email protected]>
Allow virCommand to find it in $PATH

Signed-off-by: Daniel P. Berrangé <[email protected]>
Allow virCommand to find them in $PATH, which will always include 'sbin'
since the openvz driver only operates in system mode.

Signed-off-by: Daniel P. Berrangé <[email protected]>
@sourcery-ai

sourcery-ai Bot commented Apr 29, 2025 •

Copy link
Copy Markdown

Reviewer's Guide

This pull request modifies the build system (meson.build) to remove the detection and hardcoding of absolute paths for external helper programs at build time. C code is updated to invoke these programs directly by name, relying on runtime $PATH lookups, and test expectations are adjusted accordingly.

File-Level Changes

Change Details Files
Removed build-time path detection and hardcoding for external programs.
  • Removed find_program calls for external commands like tc, iscsiadm, ovs-vsctl, lvm tools, mount, bhyve, etc.
  • Removed conf.set_quoted calls that stored these hardcoded paths in config.h.
  • Adjusted some feature enablement checks to rely on system properties or dependencies instead of program presence at build time.
meson.build
docs/meson.build
Updated C code to use program names directly instead of hardcoded path macros.
  • Replaced macros like TC, ISCSIADM, OVS_VSCTL, MOUNT, UMOUNT, MKFS, PVCREATE, LVS, MDEVCTL, DMIDECODE, MODPROBE, RMMOD, MM_CTL, NUMAD, IFCONFIG, IP, BHYVE, BHYVECTL, BHYVELOAD with their corresponding string literals (e.g., "tc", "iscsiadm", "ovs-vsctl").
src/util/viriscsi.c
src/util/virnetdevbandwidth.c
src/storage/storage_backend_logical.c
src/storage/storage_backend_fs.c
src/node_device/node_device_driver.c
src/util/virnetdevip.c
src/util/virpolkit.c
src/bhyve/bhyve_command.c
src/locking/lock_driver_lockd.c
src/util/virkmod.c
src/util/virnetdevmidonet.c
src/util/virnetdevopenvswitch.c
src/util/virsysinfo.c
src/util/virnuma.c
Updated test code expectations to use program names instead of hardcoded path macros.
  • Replaced macros like TC, OVS_VSCTL, ISCSIADM with string literals in expected command strings within tests.
tests/virnetdevbandwidthtest.c
tests/virnetdevopenvswitchtest.c
tests/viriscsitest.c
tests/storagepoolxml2argvtest.c
tests/virkmodtest.c
Removed hardcoded paths/macros from header files.
  • Removed definitions for VZLIST, VZCTL, VZMIGRATE.
  • Removed definition for PKTTYAGENT.
src/openvz/openvz_conf.h
src/util/virpolkit.h
Added Perl path configuration for build auxiliary tools.
  • Added PERL = @PERL@ to Makefile.in.
  • Added PERL variable derived from perl_prog to meson.build configuration data.
build-aux/Makefile.in
build-aux/meson.build

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Apr 29, 2025 •

Copy link
Copy Markdown

Walkthrough

This set of changes systematically replaces macro-based or hardcoded absolute paths for system utilities and commands with direct use of string literals representing the command names throughout the codebase. The build system scripts are updated to simplify and standardize how external tools are detected and referenced, often removing redundant checks and consolidating logic for platform-specific features. Several macros defining command paths are eliminated, and their usage in both production and test code is replaced with explicit string literals. Some build configuration logic is also streamlined, particularly regarding platform requirements and driver enablement. A new macro for the tc command is added, and Perl interpreter path handling is introduced in the build configuration.

Changes

File(s) / Path(s) Change Summary
build-aux/Makefile.in, build-aux/meson.build Added Perl interpreter path handling for build configuration.
docs/meson.build, meson.build Simplified and refactored build configuration: removed some program presence checks, merged optional programs, and tightened platform requirements for certain drivers. Removed exporting of some variables.
src/bhyve/bhyve_command.c, src/locking/lock_driver_lockd.c, src/node_device/node_device_driver.c, src/storage/storage_backend_fs.c, src/storage/storage_backend_logical.c, src/util/viriscsi.c, src/util/virkmod.c, src/util/virnetdevbandwidth.c, src/util/virnetdevip.c, src/util/virnetdevmidonet.c, src/util/virnetdevopenvswitch.c, src/util/virnuma.c, src/util/virpolkit.c, src/util/virsysinfo.c Replaced macros or absolute paths for external commands with string literals (e.g., "bhyve", "lvs", "iscsiadm", "modprobe", "tc", etc.) in command invocation code. In some cases, platform-specific logic was updated to use string literals.
src/openvz/openvz_conf.h Changed command path macros for OpenVZ utilities to use command names instead of absolute paths.
src/util/virfirewall.h Added macro definition for TC as "tc".
src/util/virpolkit.h Removed macro definition for PKTTYAGENT.
tests/storagepoolxml2argvtest.c, tests/viriscsitest.c, tests/virkmodtest.c, tests/virnetdevbandwidthtest.c, tests/virnetdevopenvswitchtest.c Updated tests to use string literals for command names instead of macros. Adjusted test assertions and command construction accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant BuildSystem
    participant Environment
    participant ExternalTool

    BuildSystem->>Environment: Detect tool (e.g., "perl", "tc", "lvs", etc.)
    Environment-->>BuildSystem: Return tool path or default to command name
    BuildSystem->>ExternalTool: Invoke tool using string literal name
    ExternalTool-->>BuildSystem: Execute and return result
Loading

Poem

A bunny hopped through code so wide,
Swapping macros for names with pride.
"No more paths!" the rabbit cheered,
"Just call the tool, it's as I feared!"
With each command now clear and bright,
The build and tests all run just right.
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@berrange

Copy link
Copy Markdown
Owner Author

@CodiumAI-Agent /review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @berrange - I've reviewed your changes - here's some feedback:

  • The build now assumes presence of tools like 'iscsiadm' or LVM commands at runtime on Linux instead of checking at build time; confirm this change in verification strategy.
  • Review the new OS-specific conditions in meson.build and C code to ensure they correctly handle all supported platforms.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@QodoAI-Agent

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Missing Error Handling

Calls to virCommandNew("tc") assume the command is found and the returned pointer is valid. Consider checking for NULL or handling errors if the binary is absent in PATH.

g_autoptr(virCommand) cmd = virCommandNew("tc");
int cmd_ret = 0;
Program Detection

The Meson logic for finding external programs was simplified and may no longer cover newly invoked binaries (e.g., tc, ip, iscsiadm). Verify that all required tools are detected or that the build fails cleanly.

optional_programs = [
  'augparse',
  'black',
  'flake8',
  'pdwtags',
  'pytest',
]
FreeBSD Command Lookup

In the FreeBSD branch, virCommandNew("ifconfig") is invoked directly without resolving its path via virFindFileInPath or checking availability. Add a lookup and error handling to avoid silent failures.

# ifdef __FreeBSD__
    cmd = virCommandNew("ifconfig");
    virCommandAddArg(cmd, ifname);
    if (VIR_SOCKET_ADDR_IS_FAMILY(addr, AF_INET6))

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (10)
src/storage/storage_backend_logical.c (10)

73-76: pvremove literal – same observation as above
Same reasoning as for the previous block; nothing further to address.


103-105: pvcreate literal – same observation


383-392: lvs literal – same observation


487-489: vgscan literal – same observation


490-497: pvs literal – same observation


662-663: vgcreate literal – same observation


723-731: vgs literal – same observation


772-776: vgremove literal – same observation


798-800: lvchange/lvremove literals – same observation


828-839: lvcreate literal – same observation

🧹 Nitpick comments (3)
meson.build (3)

1478-1481: Bhyve driver now enabled solely by host OS

Dropping the explicit search for bhyve* binaries means a FreeBSD build will succeed even if the hypervisor tools are absent, deferring any failure to runtime.
Please consider:

-  conf.set('WITH_BHYVE', 1)
+  # Ensure bhyve tooling is present at build-time to fail early
+  if find_program('bhyve', required: false).found() and
+     find_program('bhyvectl', required: false).found()
+    conf.set('WITH_BHYVE', 1)
+  elif get_option('driver_bhyve').enabled()
+    error('bhyve tools (bhyve, bhyvectl) not found')
+  endif

Fail-early avoids surprising runtime errors on mis-configured builders.


1815-1820: iSCSI driver check may mis-lead

The compile-time check for iscsiadm was removed, but the error still says “using iscsiadm”. This can confuse users.

-    error('Linux host needed for iSCSI storage driver using iscsiadm')
+    error('Linux host needed for iSCSI storage driver; ensure iscsiadm is available at runtime')

1829-1835: LVM driver build-time check removed

Same concern as with iSCSI: the driver now builds on any Linux system, even if LVM utilities are missing. A short hint in the error (or summary) that the tools must exist at runtime would help packagers diagnose failures.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b415773 and 71e9718.

📒 Files selected for processing (26)
  • build-aux/Makefile.in (1 hunks)
  • build-aux/meson.build (1 hunks)
  • docs/meson.build (0 hunks)
  • meson.build (6 hunks)
  • src/bhyve/bhyve_command.c (3 hunks)
  • src/locking/lock_driver_lockd.c (2 hunks)
  • src/node_device/node_device_driver.c (5 hunks)
  • src/openvz/openvz_conf.h (1 hunks)
  • src/storage/storage_backend_fs.c (3 hunks)
  • src/storage/storage_backend_logical.c (10 hunks)
  • src/util/virfirewall.h (1 hunks)
  • src/util/viriscsi.c (12 hunks)
  • src/util/virkmod.c (2 hunks)
  • src/util/virnetdevbandwidth.c (16 hunks)
  • src/util/virnetdevip.c (5 hunks)
  • src/util/virnetdevmidonet.c (2 hunks)
  • src/util/virnetdevopenvswitch.c (2 hunks)
  • src/util/virnuma.c (1 hunks)
  • src/util/virpolkit.c (2 hunks)
  • src/util/virpolkit.h (0 hunks)
  • src/util/virsysinfo.c (2 hunks)
  • tests/storagepoolxml2argvtest.c (1 hunks)
  • tests/viriscsitest.c (6 hunks)
  • tests/virkmodtest.c (2 hunks)
  • tests/virnetdevbandwidthtest.c (1 hunks)
  • tests/virnetdevopenvswitchtest.c (3 hunks)
💤 Files with no reviewable changes (2)
  • src/util/virpolkit.h
  • docs/meson.build
🔇 Additional comments (60)
src/openvz/openvz_conf.h (1)

32-34: Rely on PATH for locating OpenVZ utilities
Removing the hardcoded /usr/sbin/ prefix correctly defers command resolution to the runtime PATH. Please verify that any execution context (daemons, tests, wrappers) includes /sbin and /usr/sbin in PATH so these invocations of vzlist, vzctl, and vzmigrate will resolve reliably.

src/util/virfirewall.h (1)

33-33: Addition of TC macro is appropriate
Defining #define TC "tc" extends the set of firewall tools to include the traffic control utility. This mirrors the existing pattern for other tools and correctly integrates the new layer.

src/util/virsysinfo.c (2)

896-898: Consistent replacement of DMIDECODE macro
Switching from the DMIDECODE constant to the literal "dmidecode" in virSysinfoDMIDecodeOEMString maintains identical behavior and aligns with the PR’s goal to standardize command names.


1202-1202: Standardizing DMI command invocation
Replacing the DMIDECODE macro with "dmidecode" in virSysinfoReadDMI is consistent and preserves functionality.

src/util/virnetdevmidonet.c (2)

46-46: Literal replacement for MM_CTL is correct
Using "mm-ctl" directly in virNetDevMidonetBindPort improves clarity and fits the refactoring pattern.


76-76: Consistent use of literal command name
The "mm-ctl" string in virNetDevMidonetUnbindPort mirrors the bind-port change, ensuring uniformity.

build-aux/Makefile.in (1)

9-9: Add PERL variable for Makefile substitutions
Defining PERL = @PERL@ complements the Meson configuration and ensures the Makefile can reference the Perl interpreter path at build time.

src/util/virkmod.c (2)

32-32: Replaced hardcoded binary path with command name

Command string literals are used now instead of macros, allowing the system to find commands through standard PATH lookup at runtime.


51-51: Replaced hardcoded binary path with command name

Using string literal "rmmod" instead of a macro is consistent with the project's goal to stop hardcoding paths at build time.

src/bhyve/bhyve_command.c (3)

714-714: Replaced hardcoded binary path with command name

Using "bhyve" string directly instead of the BHYVE macro aligns with the goal of stopping path hardcoding at build time.


887-887: Replaced hardcoded binary path with command name

The string literal "bhyvectl" now directly replaces the BHYVECTL macro, allowing for PATH-based command resolution.


910-910: Replaced hardcoded binary path with command name

Changed from macro BHYVELOAD to string literal "bhyveload", consistent with other similar changes in this file.

src/node_device/node_device_driver.c (6)

747-747: Replaced hardcoded binary path with command name

Using "mdevctl" string literal instead of MDEVCTL macro for command creation.


754-755: Replaced hardcoded binary path with command name

Consistent change to use string literal for the mdevctl command.


904-911: Replaced hardcoded binary path with command name

Using string literal "mdevctl" for command creation with multiple arguments.


1133-1137: Replaced hardcoded binary path with command name

Using string literal instead of macro for mdevctl command creation in autorestart settings.


1179-1182: Replaced hardcoded binary path with command name

Using string literal instead of macro for mdevctl list command creation.


1897-1898: Replaced hardcoded binary path with command name

Updated error message to use string literal "mdevctl" instead of the MDEVCTL macro.

src/storage/storage_backend_fs.c (3)

307-307: Replaced hardcoded binary path with command name

Using "mount" string directly instead of MOUNT macro, which simplifies command invocation and allows for PATH-based resolution.


365-365: Replaced hardcoded binary path with command name

Changed from UMOUNT macro to explicit "umount" string literal for command creation.


405-405: Replaced hardcoded binary path with command name

Using "mkfs" string literal directly instead of a macro or path lookup. This simplifies the code and allows the system to find the command through the standard PATH.

src/util/virpolkit.c (2)

192-192: Good change for PATH-based command lookup.

This change from using a macro PKTTYAGENT to a direct string literal "pkttyagent" aligns with the PR objective of eliminating hardcoded binary paths at build time.


237-244: Proper implementation of dynamic binary discovery.

The changes to virPolkitAgentAvailable() properly implement dynamic binary resolution using virFindFileInPath() instead of relying on a hardcoded path. This improves compatibility with systems where /sbin and /usr/bin are merged, like in Fedora 42.

src/util/virnuma.c (1)

64-64: Good replacement of macro with string literal command name.

Replacing the NUMAD macro with the direct string literal "numad" ensures the command is found using PATH lookup at runtime rather than using hardcoded paths from build time.

src/locking/lock_driver_lockd.c (2)

436-436: Improved platform specificity with Linux check.

Changing from #ifdef LVS to #ifdef __linux__ makes the platform requirement more explicit and clear, which is a better practice than using a feature-based macro that might be confusing.


449-453: Good change for PATH-based command lookup.

Replacing the LVS macro with the string literal "lvs" follows the pattern of eliminating hardcoded paths. This improves compatibility across different Linux distributions with varying filesystem layouts.

tests/viriscsitest.c (1)

85-85: Test code properly updated to match implementation changes.

All instances where ISCSIADM macro was used in string comparisons have been replaced with the direct string literal "iscsiadm", ensuring the test code remains in sync with the implementation changes that eliminate hardcoded paths.

Also applies to: 93-93, 104-104, 124-124, 131-131, 145-145, 163-163, 175-175

src/util/viriscsi.c (5)

91-92: Refactor uses direct command name instead of macro

This change replaces the ISCSIADM macro with the literal string "iscsiadm". The virCommand API will now search for the command in the system's PATH instead of using a hardcoded path.


126-127: Consistent approach using non-absolute command paths

Using the command name directly rather than a macro with a hardcoded path improves compatibility with systems where binary locations may vary.


196-197: Updated error messages to use direct command name

Error messages now reference the command directly as iscsiadm rather than using a macro that might expand to an absolute path.

Also applies to: 228-229, 246-247, 530-531


274-275: String literal replaces macro in command array

Replaced ISCSIADM macro with the string literal "iscsiadm" in the command array for consistency.


345-349: Command instantiation using string literal instead of macro

These additional instances follow the same pattern of replacing ISCSIADM macro with the string literal "iscsiadm".

Also applies to: 398-402, 514-514, 548-548

src/util/virnetdevbandwidth.c (5)

129-129: Replaced TC macro with direct command name

Multiple instances of virCommandNew(TC) have been changed to virCommandNew("tc") to use PATH-based command resolution rather than hardcoded paths.

Also applies to: 141-141, 337-337, 346-346, 362-362, 372-372, 400-400, 408-408


451-451: Direct command name for qdisc operations

Using string literals for the command name facilitates proper command resolution across different system configurations.

Also applies to: 457-457


596-596: Replaced macro with command name for bandwidth plug/unplug operations

Consistent replacement of the TC macro with the string literal "tc" across bandwidth management functions.

Also applies to: 605-605, 647-647, 660-660, 701-701


775-776: ArgList version of command with string literal

Using a direct string literal in virCommandNewArgList is consistent with the pattern used throughout the file.


814-814: Updated test and root qdisc commands with direct string literals

Command creation for testing and adding root qdisc now uses the command name directly rather than a macro.

Also applies to: 829-829

src/util/virnetdevopenvswitch.c (2)

59-59: OVS command creation uses direct command name

Replaced OVS_VSCTL macro with the string literal "ovs-vsctl" for command creation.


555-555: Path lookup uses command name instead of macro

virFindFileInPath now searches for "ovs-vsctl" directly in PATH rather than using a potentially hardcoded macro value.

tests/virkmodtest.c (2)

66-66: Test expectation updated to use direct command name

Changed test output verification to check for "modprobe" instead of using the MODPROBE macro, which matches the implementation changes.


88-88: Unload test uses direct command name

Updated expected output check to use string literal "rmmod" instead of the RMMOD macro for consistency with implementation changes.

tests/storagepoolxml2argvtest.c (2)

41-41: Command path hardcoding replaced with command name

The code now uses the string literal "mount" instead of a potentially hardcoded path macro (MOUNT), which aligns with the PR objective of eliminating hardcoded binary paths at build time.


46-46: Command path hardcoding replaced with command name

The code now uses the string literal "vgchange" instead of a potentially hardcoded path macro (VGCHANGE), which aligns with the PR objective of eliminating hardcoded binary paths at build time.

tests/virnetdevopenvswitchtest.c (4)

262-277: Replaced OVS_VSCTL macro with literal string "ovs-vsctl"

This change removes the dependency on a hardcoded path macro and instead uses the command name directly, allowing the system to locate the binary through PATH at runtime. This aligns with the PR objective to stop hardcoding paths at build time.


286-292: Replaced OVS_VSCTL macro with literal string "ovs-vsctl"

Consistent with the previous change, using the command name directly instead of a path macro.


298-304: Replaced OVS_VSCTL macro with literal string "ovs-vsctl"

Consistent with previous changes, this removes hardcoded path dependencies.


319-325: Replaced OVS_VSCTL macro with literal string "ovs-vsctl"

Final instance of replacing the OVS_VSCTL macro with a direct command name. This makes the test code consistent with the implementation code.

src/util/virnetdevip.c (5)

393-394: Platform-specific command name instead of IFCONFIG macro

Changed from using the IFCONFIG macro to explicit string "ifconfig" for FreeBSD systems. This fits with the PR objective of relying on PATH for binary resolution instead of hardcoded paths.


407-407: Direct command name instead of IP macro

Using "ip" directly instead of a macro containing a hardcoded path, for non-FreeBSD systems.


434-435: Platform-specific command name instead of IFCONFIG macro

Consistent with earlier change, using "ifconfig" directly for FreeBSD.


444-444: Direct command name instead of IP macro

Using "ip" directly for non-FreeBSD systems, consistent with other changes.


472-472: Direct command name instead of IP macro

Final instance of using "ip" directly instead of a macro with hardcoded path.

tests/virnetdevbandwidthtest.c (4)

148-161: Replaced TC and OVS_VSCTL macros with literal command strings

The test commands now use "tc" and "ovs-vsctl" directly instead of macros containing hardcoded paths. This makes the test expectations consistent with the implementation code changes and supports the PR objective of eliminating hardcoded binary paths.


166-173: Replaced TC and OVS_VSCTL macros with literal command strings

Consistent with previous changes, the test now uses direct command names for command expectations.


179-196: Replaced TC and OVS_VSCTL macros with literal command strings

Another instance of test commands using direct names instead of macro-based paths.


202-220: Replaced TC and OVS_VSCTL macros with literal command strings

Final set of test command expectations updated to use direct command names.

src/storage/storage_backend_logical.c (1)

52-53: Runtime-resolved vgchange – double-check PATH handling

Replacing the compile-time absolute path with the plain command name is in line with the PR goal and keeps the call site simple.

Please confirm that virCommand will fall back to execvp()/virFindFileInPath() when the binary does not contain a /, so that vgchange is still located even when libvirtd sanitises $PATH for non-interactive sessions.
If that is already the case, no further action is required.

meson.build (3)

848-855: Optional dev-tools list clarified

The move to a simple literal list for optional tools (augparse, black, flake8, pdwtags, pytest) reads clearer and avoids build-time path-hard-coding. Looks good.


865-865: missing_optional_programs bookkeeping extended – ok


1982-1986: NUMAD support now Linux-only

Good tightening of the platform guard. Message is precise; no issues.

Comment thread build-aux/meson.build
'black_path': black_path,
'runutf8': ' '.join(runutf8),
'PYTHON3': python3_prog.full_path(),
'PERL': perl_prog.full_path(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Undefined perl_prog variable
The line 'PERL': perl_prog.full_path(), references perl_prog which is not declared in this scope. This will cause a build error. Please add a find_program('perl', required: false) (or true if mandatory) assignment before using perl_prog.

Example fix:

 # ...
  awk_prog = find_program('awk')

+ perl_prog = find_program('perl', required: false)
  syntax_check_conf = configuration_data({
    'top_srcdir': meson.project_source_root(),
    'top_builddir': meson.project_build_root(),
    'flake8_path': flake8_path,
    'black_path': black_path,
    'runutf8': ' '.join(runutf8),
    'PYTHON3': python3_prog.full_path(),
    'PERL': perl_prog.full_path(),
    'GREP': grep_prog.full_path(),
    'SED': sed_prog.full_path(),
    'AWK': awk_prog.full_path(),
  })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'PERL': perl_prog.full_path(),
awk_prog = find_program('awk')
perl_prog = find_program('perl', required: false)
syntax_check_conf = configuration_data({
'top_srcdir': meson.project_source_root(),
'top_builddir': meson.project_build_root(),
'flake8_path': flake8_path,
'black_path': black_path,
'runutf8': ' '.join(runutf8),
'PYTHON3': python3_prog.full_path(),
'PERL': perl_prog.full_path(),
'GREP': grep_prog.full_path(),
'SED': sed_prog.full_path(),
'AWK': awk_prog.full_path(),
})

@berrange berrange closed this May 16, 2025
berrange pushed a commit that referenced this pull request Oct 6, 2025
Variable 'master' needs to be free because it will be reassigned in
virNetDevOpenvswitchInterfaceGetMaster().

The leaked stack:
Direct leak of 11 byte(s) in 1 object(s) allocated from:
    #0 0x7f7dad8ba6df in __interceptor_malloc (/lib64/libasan.so.8+0xba6df)
    #1 0x7f7dad715728 in g_malloc (/lib64/libglib-2.0.so.0+0x60728)
    #2 0x7f7dad72d8b2 in g_strdup (/lib64/libglib-2.0.so.0+0x788b2)
    #3 0x7f7dacb63088 in g_strdup_inline /usr/include/glib-2.0/glib/gstrfuncs.h:321
    #4 0x7f7dacb63088 in virNetDevGetName ../src/util/virnetdev.c:823
    #5 0x7f7dacb63886 in virNetDevGetMaster ../src/util/virnetdev.c:909
    #6 0x7f7dacb90288 in virNetDevTapReattachBridge ../src/util/virnetdevtap.c:527
    #7 0x7f7dacd5cd67 in virDomainNetNotifyActualDevice ../src/conf/domain_conf.c:30505
    #8 0x7f7da3a10bc3 in qemuProcessNotifyNets ../src/qemu/qemu_process.c:3290
    #9 0x7f7da3a375c6 in qemuProcessReconnect ../src/qemu/qemu_process.c:9211
    #10 0x7f7dacc0cc53 in virThreadHelper ../src/util/virthread.c:256
    #11 0x7f7dac2875d4 in start_thread (/lib64/libc.so.6+0x875d4)
    #12 0x7f7dac3091bb in __GI___clone3 (/lib64/libc.so.6+0x1091bb)

Fixes: de938b9
Signed-off-by: QiangWei Zhang <[email protected]>
Reviewed-by: Peter Krempa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants