Skip to content

Conversation

@electricface
Copy link
Contributor

@electricface electricface commented Dec 15, 2025

Change the enable/disable control for error notifications from
the sysctl interface to the Generic Netlink command interface,
and extend the attribute information for error notifications.

Major changes:

  • Remove the sysctl interface (/proc/sys/fs/deepin-err-notify-enable)
  • Add new Netlink commands: ENABLE, DISABLE, GET_STATUS
  • Add new error notification attributes: inode, ppid, uid, gid,
    status, etc.
  • Implement command handler functions to support dynamic
    enabling/disabling of the notification feature
  • Add Netlink attribute policies and operation tables

Signed-off-by: electricface [email protected]

Summary by Sourcery

Replace the Deepin filesystem error notification control path with a Generic Netlink–based interface and extend the notification metadata.

Enhancements:

  • Extend error notification attributes to include inode metadata, parent inode flag, parent PID, UID, GID, and enable/disable status.
  • Introduce Generic Netlink commands and ops for read-only filesystem error events and for enabling, disabling, and querying notification status.
  • Add Netlink attribute policies, multicast group naming, and reply handling for status queries while removing the legacy sysctl-based control interface.

control interface

Change the enable/disable control for error notifications from
the sysctl interface to the Generic Netlink command interface,
and extend the attribute information for error notifications.

Major changes:
- Remove the sysctl interface (/proc/sys/fs/deepin-err-notify-enable)
- Add new Netlink commands: ENABLE, DISABLE, GET_STATUS
- Add new error notification attributes: inode, ppid, uid, gid,
status, etc.
- Implement command handler functions to support dynamic
enabling/disabling of the notification feature
- Add Netlink attribute policies and operation tables

Signed-off-by: electricface <[email protected]>
@sourcery-ai
Copy link

sourcery-ai bot commented Dec 15, 2025

Reviewer's Guide

Switches Deepin filesystem error notification runtime control from a sysctl-based boolean in /proc/sys/fs/deepin-err-notify-enable to a Generic Netlink command interface, while extending the Netlink attributes and wiring them into the existing notification path.

Sequence diagram for Netlink-based enable/disable/status control

sequenceDiagram
    actor UserSpaceTool
    participant GenericNetlinkCore
    participant DeepinErrNotifyModule

    UserSpaceTool->>GenericNetlinkCore: NLMSG(DEEPIN_ERR_NOTIFY_CMD_ENABLE)
    GenericNetlinkCore->>DeepinErrNotifyModule: deepin_err_notify_cmd_enable
    DeepinErrNotifyModule->>DeepinErrNotifyModule: deepin_err_notify_enable = 1
    DeepinErrNotifyModule-->>GenericNetlinkCore: return 0
    GenericNetlinkCore-->>UserSpaceTool: NLMSG(ack)

    UserSpaceTool->>GenericNetlinkCore: NLMSG(DEEPIN_ERR_NOTIFY_CMD_DISABLE)
    GenericNetlinkCore->>DeepinErrNotifyModule: deepin_err_notify_cmd_disable
    DeepinErrNotifyModule->>DeepinErrNotifyModule: deepin_err_notify_enable = 0
    DeepinErrNotifyModule-->>GenericNetlinkCore: return 0
    GenericNetlinkCore-->>UserSpaceTool: NLMSG(ack)

    UserSpaceTool->>GenericNetlinkCore: NLMSG(DEEPIN_ERR_NOTIFY_CMD_GET_STATUS)
    GenericNetlinkCore->>DeepinErrNotifyModule: deepin_err_notify_cmd_get_status
    DeepinErrNotifyModule->>DeepinErrNotifyModule: nlmsg_new + genlmsg_put
    DeepinErrNotifyModule->>DeepinErrNotifyModule: nla_put_u8(STATUS, deepin_err_notify_enable)
    DeepinErrNotifyModule-->>GenericNetlinkCore: genlmsg_reply
    GenericNetlinkCore-->>UserSpaceTool: NLMSG(STATUS=u8)
Loading

Flow diagram for read-only filesystem error notification via Netlink

flowchart LR
    A[FilesystemError in Deepin filesystem] --> B[deepin_check_and_notify_ro_fs_err]
    B --> C{deepin_err_notify_enabled}
    C -- false --> D[Return without notification]
    C -- true --> E[deepin_send_ro_fs_err_notification]

    subgraph DeepinErrNotifyModule
        E --> F[genlmsg_put with DEEPIN_ERR_NOTIFY_CMD_ERR_ROFS]
        F --> G[nla_put attributes<br>- FILENAME<br>- INODE<br>- INODE_PARENT<br>- PID<br>- PPID<br>- COMM<br>- UID<br>- GID]
        G --> H[genlmsg_multicast to MULTICAST_GROUP_ERR_EVENTS]
    end

    H --> I[UserSpaceListeners with Netlink sockets]
Loading

File-Level Changes

Change Details Files
Extend Generic Netlink API for Deepin error notification with richer attributes and explicit commands, and wire existing notifications to the new command enum.
  • Refine the module header comment to describe generic filesystem error notification use, not only read-only overlayfs.
  • Redefine DEEPIN_ERR_NOTIFY attributes to start at explicit numeric values and add inode, parent inode flag, ppid, uid, gid, status, and clarify COMM and FUNC_NAME usage.
  • Replace the single NOTIFY command with specific commands for read-only filesystem errors and new control commands ENABLE, DISABLE, and GET_STATUS.
  • Update deepin_send_ro_fs_err_notification to emit DEEPIN_ERR_NOTIFY_CMD_ERR_ROFS instead of the removed NOTIFY command.
fs/deepin_err_notify.c
Introduce Netlink-based runtime control of the notification feature via new commands and policies, replacing the previous sysctl interface.
  • Declare the Generic Netlink family forward so it can be referenced from command handlers.
  • Add a Netlink multicast group name constant and use it in the multicast group definition, retaining GENL_UNS_ADMIN_PERM requirements.
  • Define an nla_policy array covering the new attributes, including STATUS as NLA_U8.
  • Implement command handlers deepin_err_notify_cmd_enable/disable that flip deepin_err_notify_enable and log via pr_debug.
  • Implement deepin_err_notify_cmd_get_status to reply with a unicast Generic Netlink message containing the STATUS attribute reflecting deepin_err_notify_enable.
  • Register these handlers in a genl_ops array with appropriate GENL_ADMIN_PERM flags for mutating commands and no capability requirement for GET_STATUS, and hook them into the genl_family via .ops and .n_ops.
  • Remove the sysctl table and initialization code that previously exposed deepin_err_notify_enable under fs/deepin-err-notify-enable and stop calling it from module init.
  • Adjust deepin_err_notify_enabled to be inline and continue to gate notifications on both initialization and the runtime enable flag.
  • Keep Generic Netlink family registration in module init, add an explanatory comment, and downgrade the success log from pr_info to pr_debug including the family name.
fs/deepin_err_notify.c

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
Copy link

Hi @electricface. Thanks for your PR.

I'm waiting for a deepin-community member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

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 there - I've reviewed your changes and found some issues that need to be addressed.

  • The deepin_err_notify_enabled() function is now declared inline in the C file without static, which gives it external linkage and may create duplicate-definition issues at link time; consider either dropping inline or marking it static inline (and moving it to a header if it’s meant to be inlined across translation units).
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `deepin_err_notify_enabled()` function is now declared `inline` in the C file without `static`, which gives it external linkage and may create duplicate-definition issues at link time; consider either dropping `inline` or marking it `static inline` (and moving it to a header if it’s meant to be inlined across translation units).

## Individual Comments

### Comment 1
<location> `fs/deepin_err_notify.c:74-77` </location>
<code_context>
 static int deepin_err_notify_enable __read_mostly = 0;

-int deepin_err_notify_enabled(void)
+/* Forward declaration of Generic Netlink family */
+static struct genl_family deepin_err_notify_genl_family;
+
+inline int deepin_err_notify_enabled(void)
 {
 	return deepin_err_notify_initialized && deepin_err_notify_enable;
</code_context>

<issue_to_address>
**issue (bug_risk):** The `static` forward declaration of `deepin_err_notify_genl_family` conflicts with the later definition and will cause a redefinition error.

`static struct genl_family deepin_err_notify_genl_family;` at file scope is already a full definition. The later `static struct genl_family deepin_err_notify_genl_family __ro_after_init = { ... };` becomes a second, conflicting definition and should break the build. If you only need a forward declaration for `genlmsg_put`, make it `extern struct genl_family deepin_err_notify_genl_family;` (preferably in a shared header), or move the helper functions below the actual definition so no forward declaration is needed.
</issue_to_address>

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.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: opsiff

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

The pull request process is described here

Details 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

DEEPIN_ERR_NOTIFY_ATTR_FUNC_NAME, /* Function Name */
DEEPIN_ERR_NOTIFY_ATTR_FILENAME = 1, /* Filename (string) */
DEEPIN_ERR_NOTIFY_ATTR_INODE = 2, /* Inode (u64) */
DEEPIN_ERR_NOTIFY_ATTR_INODE_PARENT =
Copy link
Member

Choose a reason for hiding this comment

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

INODE_IS_PARENT或者INODE_FROM_PARENT更合适吧

@opsiff opsiff merged commit 93cecaf into deepin-community:linux-6.6.y Dec 15, 2025
11 checks passed
@electricface electricface deleted the swt/err-notify-p3 branch December 15, 2025 09:59
Copy link

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 pull request migrates the Deepin filesystem error notification control interface from sysctl to Generic Netlink commands. The change modernizes the API by replacing the /proc/sys/fs/deepin-err-notify-enable interface with netlink-based commands, enabling runtime control of error notifications through a more flexible and extensible mechanism. The PR also extends the notification attributes to include additional metadata such as inode numbers, parent process IDs, and user/group IDs.

Key Changes:

  • Replaced sysctl interface with Generic Netlink commands (ENABLE, DISABLE, GET_STATUS)
  • Extended error notification attributes to include inode, ppid, uid, gid, and status fields
  • Renamed multicast group from "ro_fs_events" to "err_events" and command from NOTIFY to ERR_ROFS

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

static int deepin_err_notify_cmd_enable(struct sk_buff *skb,
struct genl_info *info)
{
deepin_err_notify_enable = 1;
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

The direct assignment to deepin_err_notify_enable is not thread-safe. Multiple concurrent calls to enable/disable commands could result in race conditions. Consider using atomic operations (e.g., atomic_t with atomic_set()) or appropriate memory barriers to ensure visibility across CPUs, especially since this variable is marked __read_mostly and can be read from multiple contexts simultaneously.

Copilot uses AI. Check for mistakes.
static int deepin_err_notify_cmd_disable(struct sk_buff *skb,
struct genl_info *info)
{
deepin_err_notify_enable = 0;
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

The direct assignment to deepin_err_notify_enable is not thread-safe. Multiple concurrent calls to enable/disable commands could result in race conditions. Consider using atomic operations (e.g., atomic_t with atomic_set()) or appropriate memory barriers to ensure visibility across CPUs, especially since this variable is marked __read_mostly and can be read from multiple contexts simultaneously.

Copilot uses AI. Check for mistakes.
#define DEEPIN_ERR_NOTIFY_FAMILY_NAME "DEEPIN_ENOTIFY"

/* Multicast group name for error events (used in Netlink communication) */
#define MULTICAST_GROUP_ERR_EVENTS "err_events"
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

The multicast group name has changed from "ro_fs_events" to "err_events", which is a breaking change for userspace consumers. This means existing userspace tools listening to "ro_fs_events" will no longer receive notifications. Consider whether this breaking API change is intentional, and if so, ensure it's properly documented and communicated.

Copilot uses AI. Check for mistakes.
Comment on lines +143 to +154
static const struct nla_policy
deepin_err_notify_genl_policy[DEEPIN_ERR_NOTIFY_ATTR_MAX + 1] = {
[DEEPIN_ERR_NOTIFY_ATTR_FILENAME] = { .type = NLA_STRING },
[DEEPIN_ERR_NOTIFY_ATTR_INODE] = { .type = NLA_U64 },
[DEEPIN_ERR_NOTIFY_ATTR_INODE_PARENT] = { .type = NLA_U8 },
[DEEPIN_ERR_NOTIFY_ATTR_PID] = { .type = NLA_U32 },
[DEEPIN_ERR_NOTIFY_ATTR_PPID] = { .type = NLA_U32 },
[DEEPIN_ERR_NOTIFY_ATTR_COMM] = { .type = NLA_STRING },
[DEEPIN_ERR_NOTIFY_ATTR_UID] = { .type = NLA_U32 },
[DEEPIN_ERR_NOTIFY_ATTR_GID] = { .type = NLA_U32 },
[DEEPIN_ERR_NOTIFY_ATTR_STATUS] = { .type = NLA_U8 },
};
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

The netlink attribute policy is missing an entry for DEEPIN_ERR_NOTIFY_ATTR_FUNC_NAME (index 10), even though this attribute is defined in the enum and used in the code (line 309-310). This could lead to validation issues or unexpected behavior when this attribute is sent. Add the missing policy entry for completeness and proper validation.

Copilot uses AI. Check for mistakes.
/* Forward declaration of Generic Netlink family */
static struct genl_family deepin_err_notify_genl_family;

inline int deepin_err_notify_enabled(void)
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

Adding the inline keyword to a non-static function in a .c file is unnecessary and could be problematic. The compiler will ignore it since the function definition is not in a header file, and the linker needs a real symbol. Consider removing inline or making the function static inline if it should be optimized for inlining within this compilation unit only.

Copilot uses AI. Check for mistakes.
Comment on lines +39 to +50
DEEPIN_ERR_NOTIFY_ATTR_FILENAME = 1, /* Filename (string) */
DEEPIN_ERR_NOTIFY_ATTR_INODE = 2, /* Inode (u64) */
DEEPIN_ERR_NOTIFY_ATTR_INODE_PARENT =
3, /* Bool: inode from parent (u8) */
DEEPIN_ERR_NOTIFY_ATTR_PID = 4, /* Process ID (u32) */
DEEPIN_ERR_NOTIFY_ATTR_PPID = 5, /* Parent Process ID (u32) */
DEEPIN_ERR_NOTIFY_ATTR_COMM =
6, /* Process Short Name (string, 15 chars max) */
DEEPIN_ERR_NOTIFY_ATTR_UID = 7, /* User ID (u32) */
DEEPIN_ERR_NOTIFY_ATTR_GID = 8, /* Group ID (u32) */
DEEPIN_ERR_NOTIFY_ATTR_STATUS = 9, /* Enable/Disable Status (u8) */
DEEPIN_ERR_NOTIFY_ATTR_FUNC_NAME = 10, /* Function Name (string) */
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

The explicit numbering of enum values (1, 2, 3, etc.) is redundant since they follow sequential order. This adds maintenance overhead without providing value. Consider removing the explicit numbers and relying on automatic enum value assignment, which is the standard pattern in Linux kernel code, unless there's a specific ABI compatibility reason to maintain these exact values.

Copilot uses AI. Check for mistakes.
Comment on lines +58 to +62
DEEPIN_ERR_NOTIFY_CMD_ERR_ROFS =
1, /* Read Only Filesystem Error Notify Command */
DEEPIN_ERR_NOTIFY_CMD_ENABLE = 2, /* Enable error notification */
DEEPIN_ERR_NOTIFY_CMD_DISABLE = 3, /* Disable error notification */
DEEPIN_ERR_NOTIFY_CMD_GET_STATUS = 4, /* Get enable/disable status */
Copy link

Copilot AI Dec 17, 2025

Choose a reason for hiding this comment

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

The explicit numbering of enum values (1, 2, 3, 4) is redundant since they follow sequential order. This adds maintenance overhead without providing value. Consider removing the explicit numbers and relying on automatic enum value assignment, which is the standard pattern in Linux kernel code, unless there's a specific ABI compatibility reason to maintain these exact values.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants