Skip to content

soft-reboot: Also handle /boot#3487

Merged
cgwalters merged 2 commits intoostreedev:mainfrom
cgwalters:soft-reboot-boot-mnt
Jul 24, 2025
Merged

soft-reboot: Also handle /boot#3487
cgwalters merged 2 commits intoostreedev:mainfrom
cgwalters:soft-reboot-boot-mnt

Conversation

@cgwalters
Copy link
Member

Closes: #3486

So it can be shared with soft reboots.

Signed-off-by: Colin Walters <walters@verbum.org>
Closes: ostreedev#3486

Signed-off-by: Colin Walters <walters@verbum.org>
@github-actions github-actions bot added the area/prepare-root Issue relates to ostree-prepare-root label Jul 24, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the /boot mounting logic into a new shared function otcore_mount_boot and uses it in both ostree-prepare-root and the soft-reboot logic. This is a good improvement for code reuse. My review focuses on the new function, suggesting improvements to its error handling and consistency to make it more robust and maintainable.

Comment on lines +392 to +413
gboolean
otcore_mount_boot (const char *physical_root, const char *deployment, GError **error)
{
g_autofree char *boot_loader = g_build_filename (physical_root, "boot/loader", NULL);
struct stat stbuf;

/* If /boot is on the same partition, use a bind mount to make it visible
* at /boot inside the deployment.
*/
if (!(lstat (boot_loader, &stbuf) == 0 && S_ISLNK (stbuf.st_mode)))
return TRUE;

g_autofree char *target_boot = g_build_filename (deployment, "boot", NULL);
if (!(lstat (target_boot, &stbuf) == 0 && S_ISDIR (stbuf.st_mode)))
return TRUE;

g_autofree char *src_boot = g_build_filename (physical_root, "boot", NULL);
if (mount (src_boot, target_boot, NULL, MS_BIND | MS_SILENT, NULL) < 0)
return glnx_throw (error, "failed to bind mount /boot");

return TRUE;
}

Choose a reason for hiding this comment

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

high

This new function can be improved in a few ways for robustness and clarity:

  • Error Handling: The lstat calls don't handle errors correctly. They will silently succeed if lstat fails for reasons other than ENOENT (e.g., permission denied), which could mask underlying issues. It's better to explicitly check for ENOENT and treat other errors as fatal.
  • Error Reporting: The error message for mount failure could be more informative by including the errno string. Using glnx_throw_errno_prefix would achieve this, which is a common pattern in this file.
  • Naming Consistency: The parameter name deployment is inconsistent with the declaration in otcore.h (deploy_path). Renaming it to deploy_path would improve consistency with the header and other functions in this module.
  • Readability: The if (!(...)) expressions are a bit difficult to parse. Breaking them down into separate checks improves readability.

Here is a suggested implementation that addresses these points:

gboolean
otcore_mount_boot (const char *physical_root, const char *deploy_path, GError **error)
{
  g_autofree char *boot_loader = g_build_filename (physical_root, "boot/loader", NULL);
  struct stat stbuf;
  int r;

  /* If /boot is on the same partition, use a bind mount to make it visible
   * at /boot inside the deployment.
   */
  r = lstat (boot_loader, &stbuf);
  if (r < 0)
    {
      if (errno == ENOENT)
        return TRUE;
      return glnx_throw_errno_prefix (error, "lstat(%s)", boot_loader);
    }
  if (!S_ISLNK (stbuf.st_mode))
    return TRUE;

  g_autofree char *target_boot = g_build_filename (deploy_path, "boot", NULL);
  r = lstat (target_boot, &stbuf);
  if (r < 0)
    {
      if (errno == ENOENT)
        return TRUE;
      return glnx_throw_errno_prefix (error, "lstat(%s)", target_boot);
    }
  if (!S_ISDIR (stbuf.st_mode))
    return TRUE;

  g_autofree char *src_boot = g_build_filename (physical_root, "boot", NULL);
  if (mount (src_boot, target_boot, NULL, MS_BIND | MS_SILENT, NULL) < 0)
    return glnx_throw_errno_prefix (error, "failed to bind mount /boot");

  return TRUE;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

The lstat calls don't handle errors correctly. They will silently succeed if lstat fails for reasons other than ENOENT (e.g., permission denied),

Yes, this was true in the original code. Not fatal right now.

Copy link
Member

@jmarrero jmarrero left a comment

Choose a reason for hiding this comment

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

lgtm

@cgwalters cgwalters merged commit a660844 into ostreedev:main Jul 24, 2025
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/prepare-root Issue relates to ostree-prepare-root

Projects

None yet

Development

Successfully merging this pull request may close these issues.

soft reboot: Handle no /boot partition

2 participants