All of lore.kernel.org
 help / color / mirror / Atom feed
* [pseudo][PATCH v2 0/2] nftw, ftw: add wrappers
@ 2025-04-07 19:14 Gyorgy Sarvari
  2025-04-07 19:14 ` [pseudo][PATCH v2 1/2] nftw, ftw: add wrapper Gyorgy Sarvari
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Gyorgy Sarvari @ 2025-04-07 19:14 UTC (permalink / raw)
  To: yocto-patches; +Cc: landervanloock

This is an (attempt at the) implementation of the nftw and ftw[1] calls in pseudo.

The main motivation is a change in btrfs-tools[2], in which
they have changed from walking the filetree and calling stat
on each entries separately to using the nftw call. As a result,
btrfs filesystem generation currently happens with incorrect
ownership details, as the nftw calls go around pseudo.

See also the relevant report[3] on the Yocto mailing list.

The main idea: with a custom wrapper capture the nftw call, and switch the callback
to our own callback. When our own callback is called, fix the received
stat struct, and call the original callback, this time with the correct
stat struct.

Big thanks to Lander Van Loock, who not only reported the
original issue, but also helped testing and reviewing the first version
of the code.

Please let me know what you think.

[1]: https://linux.die.net/man/3/nftw
[2]: https://github.com/kdave/btrfs-progs/commit/c6464d3f99ed1dabceff1168eabb207492c37624
[3]: https://lists.yoctoproject.org/g/yocto/message/64889


---
v1: https://lore.kernel.org/yocto-patches/20250317113445.3855518-1-skandigraun@gmail.com/T/

changes in v2:
- Add wrapper for ftw, ftw64, nftw and nftw64 (instead of only nftw in v1). All of them
  use the same wrapper file, using macros to account for the naming differences.
- ftw64 and nftw64 depend on large file support of the system. To account for this, move
  these implementations into their own subport folder, and compile them conditionally.
- Move tests into separate commit (and add some tests for the new calls too)
- The original implementation didn't consider multiple concurrent requests
  when it was saving the original call's details (callback function pointer,
  flags), and subsequent calls could overwrite data. This version stores
  these details in an array that behaves similar to a LIFO proto-stack.
- Fix one bug in FTW_CHDIR flag behavior in conjuction with FTW_DEPTH flag (it switched
  to a folder, which didn't match glibc implementation's behavior)
- Minor change in Makefile: since the tests between ftw/ftw64 and nftw/nftw64 are exactly
  the same, they are also implemented in the same file, which however is expected to be
  included in other files, and is not a compile-unit on its own. For this, the Makefile
  looks for files with "test-" prefix in the test folder.

---

Gyorgy Sarvari (2):
  nftw, ftw: add wrapper
  nftw, ftw: add tests

 Makefile.in                            |   4 +-
 guts/README                            |   6 +-
 ports/linux/guts/ftw64.c               |  16 --
 ports/linux/nftw64/guts/ftw64.c        |  29 +++
 ports/linux/{ => nftw64}/guts/nftw64.c |   7 +-
 ports/linux/nftw64/pseudo_wrappers.c   |  45 +++++
 ports/linux/nftw64/wrapfuncs.in        |   2 +
 ports/linux/subports                   |  14 ++
 ports/linux/wrapfuncs.in               |   2 -
 ports/unix/guts/ftw.c                  |  13 +-
 ports/unix/guts/nftw.c                 |   7 +-
 ports/unix/guts/nftw_wrapper_base.c    | 211 ++++++++++++++++++++++
 ports/unix/pseudo_wrappers.c           |  45 +++++
 ports/unix/wrapfuncs.in                |   2 +-
 test/ftw-test-impl.c                   | 226 +++++++++++++++++++++++
 test/nftw-test-impl.c                  | 236 +++++++++++++++++++++++++
 test/test-ftw.c                        |   4 +
 test/test-ftw64.c                      |   4 +
 test/test-nftw.c                       |   4 +
 test/test-nftw.sh                      |  84 +++++++++
 test/test-nftw64.c                     |   4 +
 21 files changed, 937 insertions(+), 28 deletions(-)
 delete mode 100644 ports/linux/guts/ftw64.c
 create mode 100644 ports/linux/nftw64/guts/ftw64.c
 rename ports/linux/{ => nftw64}/guts/nftw64.c (57%)
 create mode 100644 ports/linux/nftw64/pseudo_wrappers.c
 create mode 100644 ports/linux/nftw64/wrapfuncs.in
 create mode 100644 ports/unix/guts/nftw_wrapper_base.c
 create mode 100644 test/ftw-test-impl.c
 create mode 100644 test/nftw-test-impl.c
 create mode 100644 test/test-ftw.c
 create mode 100644 test/test-ftw64.c
 create mode 100644 test/test-nftw.c
 create mode 100755 test/test-nftw.sh
 create mode 100644 test/test-nftw64.c



^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2025-05-02 13:44 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-07 19:14 [pseudo][PATCH v2 0/2] nftw, ftw: add wrappers Gyorgy Sarvari
2025-04-07 19:14 ` [pseudo][PATCH v2 1/2] nftw, ftw: add wrapper Gyorgy Sarvari
2025-04-07 19:14 ` [pseudo][PATCH v2 2/2] nftw, ftw: add tests Gyorgy Sarvari
2025-04-07 23:11 ` [yocto-patches] [pseudo][PATCH v2 0/2] nftw, ftw: add wrappers Mark Hatle
     [not found] ` <18341F33308F8E0B.31078@lists.yoctoproject.org>
2025-04-08 14:33   ` [yocto-patches] [pseudo][PATCH v2 2/2] nftw, ftw: add tests Gyorgy Sarvari
2025-04-08 16:06     ` Mark Hatle
2025-04-26 21:14       ` Ferry Toth
     [not found] ` <18342C3498EB800F.31078@lists.yoctoproject.org>
2025-05-02  1:08   ` [yocto-patches] [pseudo][PATCH v2 0/2] nftw, ftw: add wrappers Mark Hatle
2025-05-02  1:17   ` Mark Hatle
2025-05-02  8:53     ` Gyorgy Sarvari
2025-05-02 13:33       ` Mark Hatle
     [not found]     ` <183BA9D5657FA6B7.6015@lists.yoctoproject.org>
2025-05-02  9:53       ` Gyorgy Sarvari
2025-05-02 13:42         ` Mark Hatle

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.