Skip to content

[Deepin-Kernel-SIG] [linux 6.6-y] [Upstream] fs: backport VFS-related patches in preparation for EROFS file-backed mount #966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: linux-6.6.y
Choose a base branch
from

Conversation

Avenger-285714
Copy link
Collaborator

@Avenger-285714 Avenger-285714 commented Jul 22, 2025

This cherry picks the following VFS patches from upstream:
fs: add FS_IOC_GETFSSYSFSPATH
fs: FS_IOC_GETUUID
fs: super_set_uuid()

There are no conflicts.

Link: https://bugzilla.openanolis.cn/show_bug.cgi?id=11101
Link: https://gitee.com/anolis/cloud-kernel/pulls/4230

Summary by Sourcery

Backport upstream VFS patches to expose filesystem UUID and sysfs path via new ioctls, extend super_block with metadata fields and helpers, update filesystem code to use the new helpers, and update the ioctl documentation

New Features:

  • Add FS_IOC_GETFSUUID ioctl to retrieve the filesystem UUID via a fsuuid2 structure
  • Add FS_IOC_GETFSSYSFSPATH ioctl to retrieve the filesystem’s sysfs path via a fs_sysfs_path structure

Enhancements:

  • Introduce s_uuid_len and s_sysfs_name fields in struct super_block
  • Add super_set_uuid() and super_set_sysfs_name_* inline helpers for unified UUID and sysfs name management
  • Replace direct UUID assignments in various filesystem implementations with super_set_uuid

Documentation:

  • Update user-space API documentation to include the new FS_IOC_GETFSUUID and FS_IOC_GETFSSYSFSPATH ioctls

@Avenger-285714 Avenger-285714 requested review from opsiff and Copilot July 22, 2025 03:16
Copy link

sourcery-ai bot commented Jul 22, 2025

Reviewer's Guide

This PR backports upstream VFS patches to introduce filesystem UUID and sysfs‐path support by extending super_block, adding new ioctls, and updating existing filesystems to use a unified super_set_uuid interface.

Sequence diagram for FS_IOC_GETFSUUID ioctl handling

sequenceDiagram
    actor User
    participant Kernel as Kernel (do_vfs_ioctl)
    participant File as file
    participant SB as super_block
    User->>Kernel: ioctl(fd, FS_IOC_GETFSUUID, ...)
    Kernel->>File: get file_inode(file)
    File->>SB: access s_uuid, s_uuid_len
    Kernel-->>User: copy fsuuid2 struct to user
Loading

Sequence diagram for FS_IOC_GETFSSYSFSPATH ioctl handling

sequenceDiagram
    actor User
    participant Kernel as Kernel (do_vfs_ioctl)
    participant File as file
    participant SB as super_block
    User->>Kernel: ioctl(fd, FS_IOC_GETFSSYSFSPATH, ...)
    Kernel->>File: get file_inode(file)
    File->>SB: access s_sysfs_name
    Kernel-->>User: copy fs_sysfs_path struct to user
Loading

Class diagram for updated struct super_block and new helpers

classDiagram
    class super_block {
        char s_id[32]
        uuid_t s_uuid
        u8 s_uuid_len
        char s_sysfs_name[UUID_STRING_LEN + 1]
        ...
    }
    class super_set_uuid {
        +void super_set_uuid(super_block *sb, const u8 *uuid, unsigned len)
    }
    class super_set_sysfs_name_bdev {
        +void super_set_sysfs_name_bdev(super_block *sb)
    }
    class super_set_sysfs_name_uuid {
        +void super_set_sysfs_name_uuid(super_block *sb)
    }
    class super_set_sysfs_name_id {
        +void super_set_sysfs_name_id(super_block *sb)
    }
    class super_set_sysfs_name_generic {
        +void super_set_sysfs_name_generic(super_block *sb, const char *fmt, ...)
    }
    super_set_uuid --|> super_block : modifies
    super_set_sysfs_name_bdev --|> super_block : modifies
    super_set_sysfs_name_uuid --|> super_block : modifies
    super_set_sysfs_name_id --|> super_block : modifies
    super_set_sysfs_name_generic --|> super_block : modifies
Loading

Class diagram for new ioctl data structures

classDiagram
    class fsuuid2 {
        __u8 len
        __u8 uuid[16]
    }
    class fs_sysfs_path {
        __u8 len
        __u8 name[128]
    }
Loading

File-Level Changes

Change Details Files
Extend super_block with UUID length and sysfs name fields plus helpers
  • Add s_uuid_len and s_sysfs_name fields to struct super_block
  • Implement super_set_uuid and sysfs naming inline functions
include/linux/fs.h
Introduce new ioctls for exposing filesystem UUID and sysfs mount path
  • Define fsuuid2 and fs_sysfs_path structs in uapi
  • Implement ioctl_getfsuuid and ioctl_get_fs_sysfs_path handlers
  • Register FS_IOC_GETFSUUID and FS_IOC_GETFSSYSFSPATH commands
include/uapi/linux/fs.h
fs/ioctl.c
Integrate super_set_uuid across multiple filesystem drivers
  • Replace direct uuid_gen/import/memcpy calls with super_set_uuid
fs/kernfs/mount.c
fs/ocfs2/super.c
mm/shmem.c
fs/ext4/super.c
fs/f2fs/super.c
fs/gfs2/ops_fstype.c
fs/ubifs/super.c
fs/xfs/xfs_mount.c
Document new ioctls in userspace API reference
  • Add entries for FS_IOC_GETFSUUID and FS_IOC_GETFSSYSFSPATH
Documentation/userspace-api/ioctl/ioctl-number.rst

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

@deepin-ci-robot deepin-ci-robot requested a review from myml July 22, 2025 03:16
@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from avenger-285714. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR backports VFS-related patches from upstream to prepare for EROFS file-backed mount support. The changes introduce new filesystem ioctl operations and standardize UUID handling across filesystems.

  • Adds new FS_IOC_GETFSUUID and FS_IOC_GETFSSYSFSPATH ioctl operations for filesystem introspection
  • Introduces super_set_uuid() helper function and updates all filesystem drivers to use it consistently
  • Extends super_block structure with s_uuid_len and s_sysfs_name fields for better filesystem identification

Reviewed Changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
include/uapi/linux/fs.h Defines new ioctl structures and command constants
include/linux/fs.h Adds new super_block fields and UUID helper functions
fs/ioctl.c Implements the new ioctl handlers
mm/shmem.c Updates to use new super_set_uuid() helper
fs/kernfs/mount.c Updates to use new super_set_uuid() helper
fs/xfs/xfs_mount.c Updates to use new super_set_uuid() helper
fs/ubifs/super.c Updates to use new super_set_uuid() helper
fs/ocfs2/super.c Updates to use new super_set_uuid() helper
fs/gfs2/ops_fstype.c Updates to use new super_set_uuid() helper
fs/f2fs/super.c Updates to use new super_set_uuid() helper
fs/ext4/super.c Updates to use new super_set_uuid() helper
Documentation/userspace-api/ioctl/ioctl-number.rst Updates ioctl number documentation

* We include a length field because some filesystems (vfat) have an identifier
* that we do want to expose as a UUID, but doesn't have the standard length.
*
* We use a fixed size buffer beacuse this interface will, by fiat, never
Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

Spelling error: 'beacuse' should be 'because'.

Suggested change
* We use a fixed size buffer beacuse this interface will, by fiat, never
* We use a fixed size buffer because this interface will, by fiat, never

Copilot uses AI. Check for mistakes.

Comment on lines +782 to +787

if (!strlen(sb->s_sysfs_name))
return -ENOIOCTLCMD;

struct fs_sysfs_path u = {};

Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

Variable declaration should be at the beginning of the function scope for C89 compatibility, not in the middle of the function after other statements.

Suggested change
if (!strlen(sb->s_sysfs_name))
return -ENOIOCTLCMD;
struct fs_sysfs_path u = {};
struct fs_sysfs_path u = {};
if (!strlen(sb->s_sysfs_name))
return -ENOIOCTLCMD;

Copilot uses AI. Check for mistakes.

Kent Overstreet added 3 commits July 22, 2025 11:17
commit a4af51c upstream.

Some weird old filesytems have UUID-like things that we wish to expose
as UUIDs, but are smaller; add a length field so that the new
FS_IOC_(GET|SET)UUID ioctls can handle them in generic code.

And add a helper super_set_uuid(), for setting nonstandard length uuids.

Helper is now required for the new FS_IOC_GETUUID ioctl; if
super_set_uuid() hasn't been called, the ioctl won't be supported.

Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Link: https://lore.kernel.org/r/20240207025624.1019754-2-kent.overstreet@linux.dev
Signed-off-by: Christian Brauner <brauner@kernel.org>
[ Backport from v6.9 ]
Signed-off-by: Hongzhen Luo <hongzhen@linux.alibaba.com>
Signed-off-by: WangYuli <wangyuli@uniontech.com>
commit 41bcbe5 upstream.

Add a new generic ioctls for querying the filesystem UUID.

These are lifted versions of the ext4 ioctls, with one change: we're not
using a flexible array member, because UUIDs will never be more than 16
bytes.

This patch adds a generic implementation of FS_IOC_GETFSUUID, which
reads from super_block->s_uuid. We're not lifting SETFSUUID from ext4 -
that can be done on offline filesystems by the people who need it,
trying to do it online is just asking for too much trouble.

Cc: Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>
Cc: Dave Chinner <dchinner@redhat.com>
Cc: Darrick J. Wong <djwong@kernel.org>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: linux-fsdevel@vger.kernel.org
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Link: https://lore.kernel.org/r/20240207025624.1019754-4-kent.overstreet@linux.dev
Signed-off-by: Christian Brauner <brauner@kernel.org>
[ Backport from v6.9 ]
Signed-off-by: Hongzhen Luo <hongzhen@linux.alibaba.com>
Signed-off-by: WangYuli <wangyuli@uniontech.com>
commit ae8c511 upstream.

Add a new ioctl for getting the sysfs name of a filesystem - the path
under /sys/fs.

This is going to let us standardize exporting data from sysfs across
filesystems, e.g. time stats.

The returned path will always be of the form "$FSTYP/$SYSFS_IDENTIFIER",
where the sysfs identifier may be a UUID (for bcachefs) or a device name
(xfs).

Cc: Christian Brauner <brauner@kernel.org>
Cc: Jan Kara <jack@suse.cz>
Cc: Dave Chinner <dchinner@redhat.com>
Cc: Darrick J. Wong <djwong@kernel.org>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Link: https://lore.kernel.org/r/20240207025624.1019754-6-kent.overstreet@linux.dev
Signed-off-by: Christian Brauner <brauner@kernel.org>
[ Backport from v6.9 ]
Signed-off-by: Hongzhen Luo <hongzhen@linux.alibaba.com>
Signed-off-by: WangYuli <wangyuli@uniontech.com>
@deepin-ci-robot
Copy link

deepin pr auto review

代码审查意见:

  1. Documentation/userspace-api/ioctl/ioctl-number.rst文件中,新增的注释BLK* ioctlsFS_IOC_* ioctls有助于理解每个代码块的用途,但应确保注释的准确性和完整性。

  2. fs/ext4/super.cfs/f2fs/super.cfs/gfs2/ops_fstype.cfs/ioctl.cfs/kernfs/mount.cfs/ocfs2/super.cfs/ubifs/super.cfs/xfs/xfs_mount.cinclude/linux/fs.h文件中,新增的super_set_uuid函数有助于统一设置UUID,提高了代码的可读性和可维护性。但是,应确保所有调用super_set_uuid的地方都正确处理了UUID长度超过sizeof(sb->s_uuid)的情况。

  3. fs/ioctl.c文件中,新增的ioctl_getfsuuidioctl_get_fs_sysfs_path函数提供了新的ioctl命令来获取文件系统的UUID和sysfs路径,这是一个有用的扩展。但是,应确保这些函数的错误处理和用户空间接口的一致性。

  4. include/linux/fs.h文件中,新增的super_set_uuidsuper_set_sysfs_name_bdevsuper_set_sysfs_name_uuidsuper_set_sysfs_name_idsuper_set_sysfs_name_generic函数有助于简化UUID和sysfs名称的设置,但应确保这些函数的调用者正确处理了返回值和错误情况。

  5. include/uapi/linux/fs.h文件中,新增的struct fsuuid2struct fs_sysfs_path结构体定义了新的ioctl命令的参数结构,这有助于提供更灵活的文件系统UUID和sysfs路径获取方式。但是,应确保这些结构体的定义与用户空间的实现保持一致。

  6. mm/shmem.c文件中,新增的super_set_uuid函数调用有助于设置共享内存文件系统的UUID,这是一个合理的改动。但是,应确保共享内存文件系统的UUID生成逻辑与uuid_gen函数的调用保持一致。

总体来说,这些改动提高了代码的可读性、可维护性和功能性,但应进一步确保所有新增函数和结构体的正确性和一致性。

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

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

  • The new IOCTL FS_IOC_GETFSSYSFSPATH exposes internal sysfs paths without any capability checks; consider adding a permission check (e.g. CAP_SYS_ADMIN) to avoid leaking kernel internals to unprivileged users.
  • The Q/A style comment block added above the super_block fields deviates from kernel coding style—please convert it into a concise explanatory comment or remove the ‘q:/a:’ lines.
  • In ioctl_get_fs_sysfs_path, replace strlen(sb->s_sysfs_name) with a simple sb->s_sysfs_name[0] check to avoid scanning the entire buffer for emptiness.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The new IOCTL FS_IOC_GETFSSYSFSPATH exposes internal sysfs paths without any capability checks; consider adding a permission check (e.g. CAP_SYS_ADMIN) to avoid leaking kernel internals to unprivileged users.
- The Q/A style comment block added above the super_block fields deviates from kernel coding style—please convert it into a concise explanatory comment or remove the ‘q:/a:’ lines.
- In ioctl_get_fs_sysfs_path, replace strlen(sb->s_sysfs_name) with a simple sb->s_sysfs_name[0] check to avoid scanning the entire buffer for emptiness.

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.

@Avenger-285714 Avenger-285714 requested a review from winnscode July 22, 2025 03:21
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