]> git.ipfire.org Git - thirdparty/systemd.git/commit
mountpoint-util: rework name_to_handle_at() unique mount id handling
authorMike Yuan <me@yhndnzj.com>
Thu, 5 Feb 2026 00:32:59 +0000 (01:32 +0100)
committerMike Yuan <me@yhndnzj.com>
Thu, 5 Feb 2026 13:14:40 +0000 (14:14 +0100)
commit5817c73391b5f3599c50df2c0873b26ea426f848
tree91f1cd33a2524d00707891769d3262aa7f8c7034
parent56adac11935455e00a3127cf0d7676bae7bcc9fe
mountpoint-util: rework name_to_handle_at() unique mount id handling

name_to_handle_at_try_unique_mntid_fid() in its current form is
ill-designed for various reasons:

* AT_HANDLE_FID requires file system support, while unique mount id
  is a VFS concept hence is always available if supported. Hence
  the fallback for AT_HANDLE_MNT_ID_UNIQUE should be independent
  of fid.
* The request for AT_HANDLE_MNT_ID_UNIQUE can be identified via
  specifying ret_unique_mnt_id, no need for opening up the control
  to caller (and currently the function simply doesn't handle
  mismatch between ret params and flags).
* The caller cannot realistically differentiate whether the returned
  mount id is actually unique.
* The path_get_unique_mnt_id() fallback did not handle AT_SYMLINK_FOLLOW.

Let's instead move the statx() fallback into name_to_handle_at_loop()
directly, and revamp interaction of ret_mnt_id/ret_unique_mnt_id:
if both are set, it indicates that the caller can handle both, hence
set what we have and return 0/1 for whether we managed to acquire
the unique one.

The !ret_handle && ret_mnt_id logic is removed. Let's not rely on
undocumented bizaare behavior and it's unused anyways.
path_get_mnt_id_at() exists for a reason...
src/basic/mountpoint-util.c
src/basic/mountpoint-util.h
src/basic/stat-util.c
src/libsystemd/sd-json/json-util.c
src/shared/discover-image.c
src/shared/tar-util.c