Skip to content

[BREAKING] system/dd: using system dd to instead nsh dd, avoid duplicate code #3057

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

Merged
merged 6 commits into from
Apr 19, 2025

Conversation

Donny9
Copy link
Contributor

@Donny9 Donny9 commented Apr 13, 2025

Summary

system/dd: using system dd to instead nsh dd, avoid duplicate code, and keep function align with nsh dd.

Impact

remove dd config: NSH_DISABLE_DD/NSH_CMDOPT_DD_STATS
enable SYSTEM_DD when !DEFAULT_SMALL(keep dd cmd always enable)

Testing

sim:nsh

Donny9 added 2 commits April 13, 2025 23:08
align nshlib/nsh_cmddd

Signed-off-by: dongjiuzhu1 <[email protected]>
    nshlib/cmd_dd: Retry if read() was interrupted

    Without this patch

      nsh> ls /etc/group | dd | dd
      sh [13:100]
      sh [14:100]
      nsh: dd: read failed: 4
      nsh>

    Signed-off-by: wangjianyu3 <[email protected]>

Signed-off-by: dongjiuzhu1 <[email protected]>
@nuttxpr
Copy link

nuttxpr commented Apr 13, 2025

[Experimental Bot, please feedback here]

No, this PR summary does not adequately meet the NuttX requirements. Here's why and how to fix it:

  • Insufficient Detail in Summary: "using system dd to instead nsh dd, avoid duplicate code, and keep function align with nsh dd" is too vague.

    • Why is duplicate code a problem (maintenance, size, bugs)?
    • What part of the code is changing (files, functions, modules)? Be specific! "system/dd" is a start, but mention specific files.
    • How does it work? Does this mean the dd command in NSH now calls a system-level dd utility? Explain the mechanism.
  • Missing Issue References: Are there any related NuttX or NuttX Apps issues that this PR addresses? If so, link them. If not, explicitly state "None."

  • Incomplete Impact Assessment:

    • Impact on user: Does this change the behavior of the dd command in any way that a user would notice? Even if you think the answer is no, explain why. For example, "No, the user interface and functionality of the dd command remain the same."
    • Impact on build: You mentioned config changes. Describe precisely what changes to the configuration are required. Which Kconfig files are affected? How should users update their .config files? Provide examples.
    • Impact on hardware: You've only mentioned "sim:nsh." Does this change affect any physical hardware? Even if it's platform-agnostic, state that explicitly. "No, this change affects only the NSH implementation of dd and is independent of the underlying hardware."
    • Impact on documentation: Does any documentation need updating? If not, state that. "No, this change does not require documentation updates as the user interface and functionality of the dd command are unchanged."
    • Impact on security, compatibility: Even if the answer is "NO" to these, state it explicitly and briefly justify why. For example, "No security impact, no changes to data handling or access." "Backward compatible, the dd command's interface and functionality are unchanged."
  • Insufficient Testing Information: "sim:nsh" is far too brief.

    • Build Host: Be specific about your development environment. Example: "Linux, Ubuntu 22.04, x86_64, GCC 11.2.0"
    • Target: Specify simulator details. Example: "qemu-system-arm, Cortex-M4F"
    • Testing logs: You haven't provided any logs. Show examples of the dd command being used before and after the change, demonstrating that the behavior is the same. Even simple examples are better than none.

Example of improved summary:

## Summary

This PR refactors the NSH `dd` command to utilize a common system-level `dd` implementation located in `system/dd/dd.c`. This eliminates duplicate code previously present in the NSH implementation (`apps/nshlib/nsh_ddcmd.c`), reducing code size and maintenance overhead. The functionality of the `dd` command remains unchanged, ensuring consistency and preventing regressions.  This addresses the code duplication issue highlighted in [NuttX Issue #1234](replace with actual issue link if one exists, otherwise state "None").

## Impact

* **Impact on user:** No. The user interface and functionality of the `dd` command are unchanged.
* **Impact on build:** Yes. The `NSH_DISABLE_DD` and `NSH_CMDOPT_DD_STATS` Kconfig options are removed.  `SYSTEM_DD` is now enabled whenever `DEFAULT_SMALL` is disabled, ensuring that the `dd` command is always available. Users should remove these deprecated options from their `.config` files. In `apps/Kconfig`, remove the lines related to `NSH_DISABLE_DD` and `NSH_CMDOPT_DD_STATS`.
* **Impact on hardware:** No.  This change is independent of the underlying hardware. It only refactors the NSH implementation of the `dd` command.
* **Impact on documentation:** No.  The user interface and functionality remain unchanged.
* **Impact on security:** No.  No changes to data handling or access.
* **Impact on compatibility:** Backward compatible. The `dd` command's interface and functionality are unchanged.

## Testing

* **Build Host:** Linux, Ubuntu 22.04, x86_64, GCC 11.2.0
* **Target:** qemu-system-arm, Cortex-M4F (sim:nsh)

**Testing logs before change:**

nsh> dd if=/dev/zero of=/dev/null bs=512 count=10
10+0 records in
10+0 records out
5120 bytes transferred in 0.000171 secs (29941520 bytes/sec)
nsh>


**Testing logs after change:**

nsh> dd if=/dev/zero of=/dev/null bs=512 count=10
10+0 records in
10+0 records out
5120 bytes transferred in 0.000168 secs (30476190 bytes/sec)
nsh>

By providing more specific information, you significantly increase the chances of your PR being reviewed and merged quickly. Remember to replace the example details with your actual information.

    cmd_dd:support dd can do verify

    After writing the file, compare the contents of the two files again

    Signed-off-by: anjiahao <[email protected]>

Signed-off-by: dongjiuzhu1 <[email protected]>
Donny9 added 2 commits April 14, 2025 11:18
    nshlib/dd: Increase the integer width for sector size in dd.

    On some systems, using sector sizes larger than 65536 is needed for
    profiling performance or testing.

    Stuart Ianna <[email protected]>

Signed-off-by: dongjiuzhu1 <[email protected]>
@Donny9 Donny9 force-pushed the system_dd branch 2 times, most recently from ba986e9 to 33bad8e Compare April 14, 2025 04:11
@jerpelea jerpelea added the breaking change This change requires a mitigation entry in the release notes. label Apr 14, 2025
@lupyuen lupyuen marked this pull request as draft April 14, 2025 10:18
@lupyuen
Copy link
Member

lupyuen commented Apr 14, 2025

We'll change Draft Mode to Ready For Review, after voting has closed. Thanks :-)

Copy link
Contributor

@cederom cederom left a comment

Choose a reason for hiding this comment

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

Thanks @Donny9 :-) My remarks below (marked as RC until discussion / vote is resolved on the mailing list):

  • Is it really necessary to remove built-in nsh/dd? What are the benefits over breaking build compatibility with os and apps?
  • It is impossible to keep both (i.e. nsh/dd as minimalistic and apps/system/dd as fully featured) as exclusive selections?
  • Why not extend nsh/dd with new features while keep the minimal as default?
  • Aside question did NuttX consider /usr/bin/dd versus built-in dd (something like built-in time versus /usr/bin/time in Unix)?
  • Documentation needs an update in either case :-P

@acassis
Copy link
Contributor

acassis commented Apr 14, 2025

@cederom @lupyuen @Donny9 comparing both file with meld I can see they are basically the same code:

alan@dev:~/nuttxspace/apps$ meld nshlib/nsh_ddcmd.c system/dd/dd_main.c

But I think system/dd will evolve to be more complete and compatible with Linux/Unix over the time.

For example, nsh_ddcmd.c has CONFIG_NSH_CMDOPT_DD_STATS that doesn't exist in system/dd, so it rings a bell that system/dd is more focused on compatibility vs code size.

I think that CONFIG_NSH_CMDOPT_DD_STATS could be renamed to CONFIG_SYSTEM_DD_MINIMUM and included in other parts there that aren't essential for a simple dd command.

@lupyuen lupyuen requested a review from raiden00pl April 15, 2025 01:28
@lupyuen lupyuen changed the title system/dd: using system dd to instead nsh dd, avoid duplicate code [BREAKING] system/dd: using system dd to instead nsh dd, avoid duplicate code Apr 15, 2025
@pussuw
Copy link
Contributor

pussuw commented Apr 16, 2025

This causes a regression when NSH_FILEAPPS=y, as the full path to /bin/dd must be provided. I'm okay with this, since I put /bin into PATH, but others might not. Just something to keep in mind.

using system/dd to instead nsh dd cmd
remove related to config, file.

Signed-off-by: dongjiuzhu1 <[email protected]>
@Donny9
Copy link
Contributor Author

Donny9 commented Apr 17, 2025

@cederom @lupyuen @Donny9 comparing both file with meld I can see they are basically the same code:

alan@dev:~/nuttxspace/apps$ meld nshlib/nsh_ddcmd.c system/dd/dd_main.c

But I think system/dd will evolve to be more complete and compatible with Linux/Unix over the time.

For example, nsh_ddcmd.c has CONFIG_NSH_CMDOPT_DD_STATS that doesn't exist in system/dd, so it rings a bell that system/dd is more focused on compatibility vs code size.

I think that CONFIG_NSH_CMDOPT_DD_STATS could be renamed to CONFIG_SYSTEM_DD_MINIMUM and included in other parts there that aren't essential for a simple dd command.

Done~ rename CONFIG_NSH_CMDOPT_DD_STATS to CONFIG_SYSTEM_DD_STATS.

@lupyuen lupyuen marked this pull request as ready for review April 17, 2025 11:51
@lupyuen
Copy link
Member

lupyuen commented Apr 17, 2025

@Donny9 Please close the voting. Thanks!
This Breaking PR compiles with the NuttX Breaking Changes Handling Process:

@Donny9
Copy link
Contributor Author

Donny9 commented Apr 19, 2025

Thanks @Donny9 :-) My remarks below (marked as RC until discussion / vote is resolved on the mailing list):

  • Is it really necessary to remove built-in nsh/dd? What are the benefits over breaking build compatibility with os and apps?

@cederom Firstly, we need to ensure that only one implementation of dd is retained in NuttX, because having two implementations would increase complexity for developers in terms of choosing which one to use. Moreover, if there are two versions, it could lead to misalignment in dd functionality, resulting in more maintenance work and complaints.

I understand that the original reason for introducing the built-app version of dd was that it allowed for independent stack space settings, making it convenient to observe the stack consumption by the file system(If the stack consumed by dd is excessively large, it will result in a larger stack for nsh, thereby reducing the available memory for the system. Therefore, a built-app approach would be preferable).

In reality, there is no significant difference for developers between the built-app dd and the command-line dd. Furthermore, there are indeed many other commands in the system that exist as built-apps, such as tar, ssh, scp, sb, rb, etc.

It is impossible to keep both (i.e. nsh/dd as minimalistic and apps/system/dd as fully featured) as exclusive selections?
Why not extend nsh/dd with new features while keep the minimal as default?

As mentioned above, having two implementations of dd is highly undesirable. As for the extent to which the simplified version of dd lacks functionality compared to the full version, it is difficult to gauge.

Aside question did NuttX consider /usr/bin/dd versus built-in dd (something like built-in time versus /usr/bin/time in Unix)?

In my opinion, their main differences are as follows:

  1. The startup methods differ. In the former case, after parsing via nsh_parse, dd is executed directly through a function call. In the latter case, a new task is initiated via posix_spawn, and the corresponding executable binary is executed to accomplish the functionality of dd.
  2. The execution contexts differ. The former operates within the context of nsh, while the latter runs as an independent new task.
  • Documentation needs an update in either case :-P

Done

Copy link
Contributor

@cederom cederom left a comment

Choose a reason for hiding this comment

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

Thank you @Donny9 :-)

Happy Easter :-) :-)

@lupyuen lupyuen merged commit 5585c9d into apache:master Apr 19, 2025
16 of 39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: NSH Area: System breaking change This change requires a mitigation entry in the release notes. Size: M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants