Re: [PATCH 9/9] loop: Add LOOP_CONFIGURE ioctl

2022-11-18 Thread Xiaoming Ni
On 2022/11/18 14:34, Lauri Kasanen wrote: On Fri, 18 Nov 2022 09:01:58 +0800 Xiaoming Ni wrote: LOOP_CONFIGURE is added to Linux 5.8 ... diff --git a/libbb/loop.c b/libbb/loop.c index 9a7ca666d..d4f4906b0 100644 --- a/libbb/loop.c +++ b/libbb/loop.c @@ -126,6 +126,30 @@ static int

[PATCH v2 4/9] loop:refactor: extract subfunction set_loop_info()

2022-11-18 Thread Xiaoming Ni
Step 4 of micro-refactoring the set_loop(): Extract subfunction set_loop_info() from set_loop() function old new delta set_loop 734 700 -34

[PATCH v2 6/9] loop:refactor: Use a structure to reduce parameters

2022-11-18 Thread Xiaoming Ni
Step 6 of micro-refactoring the set_loop(): Use structs to avoid transferring a large number of parameters in set_loop_configure() and set_loop_info() function old new delta set_loop 708

[PATCH v2 0/9] loop: Micro-refactoring set_loop() and add LOOP_CONFIGURE

2022-11-18 Thread Xiaoming Ni
LOOP_CONFIGURE is added to Linux 5.8 This allows userspace to completely setup a loop device with a single ioctl, removing the in-between state where the device can be partially configured - eg the loop device has a backing file associated with it, but is reading from the wrong offset.

[PATCH v2 2/9] loop:refactor: extract subfunction get_next_free_loop()

2022-11-18 Thread Xiaoming Ni
Step 2 of micro-refactoring the set_loop function () Extract subfunction get_next_free_loop() from set_loop() Also fix miss free(try) when stat(try) and mknod fail function old new delta set_loop

Re: AW: [PATCH 2/9] loop:refactor: extract subfunction get_next_free_loop()

2022-11-18 Thread Xiaoming Ni
On 2022/11/18 20:20, Walter Harms wrote: hi, just a minor comment. do not use i as name for return value, most ppl use it as loop counter, triggers the wrong circuits in the brain. (rule of least surprise). just name it err or what you like, and please untangle the if() if (err>=0) return

Re: AW: [PATCH v2 4/9] loop:refactor: extract subfunction set_loop_info()

2022-11-18 Thread Xiaoming Ni
On 2022/11/18 20:27, Walter Harms wrote: on other minor if (rc && errno == ENXIO) turn it on its head safes one indent level if ( !rc || errno != ENXIO ) return -1; // failed to get loopinfo jm2c Here's for copy-paste consistency Simplification has been implemented in patch 5 by

Re: [PATCH 9/9] loop: Add LOOP_CONFIGURE ioctl

2022-11-18 Thread Kang-Che Sung
On Fri, Nov 18, 2022 at 9:04 AM Xiaoming Ni wrote: > > LOOP_CONFIGURE is added to Linux 5.8 > > This allows userspace to completely setup a loop device with a single > ioctl, removing the in-between state where the device can be partially > configured - eg the loop device has a backing file

AW: [PATCH v2 5/9] loop:refactor: extract subfunction set_loop_configure()

2022-11-18 Thread Walter Harms
A little tweak make it more readable (i hope) putting if (rc) direkt behind rc = ioctl(lfd, BB_LOOP_SET_STATUS, ); if (rc == 0) return lfd; // no need to check rc again if ( (loopinfo.lo_flags & BB_LO_FLAGS_AUTOCLEAR)) { // try again without BB_LO_FLAGS_AUTOCLEAR // does it realy

[PATCH v2 8/9] loop:refactor: extract subfunction set_loop_dev()

2022-11-18 Thread Xiaoming Ni
Step 8 of micro-refactoring the set_loop(): Extract subfunction open_file() from set_loop_dev() function old new delta set_loop 700 716 +16

[PATCH v2 3/9] loop:refactor: del close_and_try_next_loopN

2022-11-18 Thread Xiaoming Ni
Step 3 of micro-refactoring the set_loop() function: Delete close_and_try_next_loopN. (add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0) Total: 0 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git

[PATCH v2 9/9] loop: Add LOOP_CONFIGURE ioctl

2022-11-18 Thread Xiaoming Ni
LOOP_CONFIGURE is added to Linux 5.8 This allows userspace to completely setup a loop device with a single ioctl, removing the in-between state where the device can be partially configured - eg the loop device has a backing file associated with it, but is reading from the wrong offset.

[PATCH v2 5/9] loop:refactor: extract subfunction set_loop_configure()

2022-11-18 Thread Xiaoming Ni
Step 5 of micro-refactoring the set_loop(): Extract subfunction set_loop_configure() function old new delta set_loop 700 708 +8

[PATCH v2 7/9] loop:refactor: Extract subfunction do_stat_and_mknod()

2022-11-18 Thread Xiaoming Ni
Step 7 of micro-refactoring the set_loop(): Extract subfunction do_stat_and_mknod() function old new delta set_loop 720 700 -20

AW: [PATCH v2 7/9] loop:refactor: Extract subfunction do_stat_and_mknod()

2022-11-18 Thread Walter Harms
again try to safe indent level if (stat(dev, ) == 0 && S_ISBLK(statbuf.st_mode)) return 0; jm2c Von: busybox im Auftrag von Xiaoming Ni Gesendet: Freitag, 18. November 2022 13:14:46 An: busybox@busybox.net; vda.li...@googlemail.com; c...@gmx.com;

Re: AW: [PATCH v2 7/9] loop:refactor: Extract subfunction do_stat_and_mknod()

2022-11-18 Thread Xiaoming Ni
On 2022/11/18 20:39, Walter Harms wrote: again try to safe indent level if (stat(dev, ) == 0 && S_ISBLK(statbuf.st_mode)) return 0; jm2c Thanks, will be modified in v3 Von: busybox im Auftrag von Xiaoming Ni Gesendet: Freitag, 18. November

AW: [PATCH v2 8/9] loop:refactor: extract subfunction set_loop_dev()

2022-11-18 Thread Walter Harms
i am wondering, maybe question for the maintainer. would it hurt to open it O_RDONLY in the first place ? cm2c Von: busybox im Auftrag von Xiaoming Ni Gesendet: Freitag, 18. November 2022 13:14:47 An: busybox@busybox.net; vda.li...@googlemail.com;

AW: [PATCH v2 4/9] loop:refactor: extract subfunction set_loop_info()

2022-11-18 Thread Walter Harms
on other minor if (rc && errno == ENXIO) turn it on its head safes one indent level if ( !rc || errno != ENXIO ) return -1; // failed to get loopinfo jm2c Von: busybox im Auftrag von Xiaoming Ni Gesendet: Freitag, 18. November 2022 13:14:43 An:

Re: [PATCH 9/9] loop: Add LOOP_CONFIGURE ioctl

2022-11-18 Thread Xiaoming Ni
On 2022/11/18 17:13, Kang-Che Sung wrote: On Fri, Nov 18, 2022 at 9:04 AM Xiaoming Ni wrote: LOOP_CONFIGURE is added to Linux 5.8 This allows userspace to completely setup a loop device with a single ioctl, removing the in-between state where the device can be partially configured - eg the

Re: [PATCH 9/9] loop: Add LOOP_CONFIGURE ioctl

2022-11-18 Thread Lauri Kasanen
On Fri, 18 Nov 2022 17:11:17 +0800 Xiaoming Ni wrote: > >> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,8,0) > >> +static int set_loop_configure(int ffd, int lfd, bb_loop_info *loopinfo) > >> +#else > > > > This assumes compile-time matches runtime. Ie, if you build on a 5.8 > > system, but run

[PATCH v2 1/9] loop:refactor: extract subfunction open_file()

2022-11-18 Thread Xiaoming Ni
Step 1 of micro-refactoring the set_loop(): Extract subfunction open_file() from set_loop() function old new delta set_loop 760 758 -2

AW: [PATCH 2/9] loop:refactor: extract subfunction get_next_free_loop()

2022-11-18 Thread Walter Harms
hi, just a minor comment. do not use i as name for return value, most ppl use it as loop counter, triggers the wrong circuits in the brain. (rule of least surprise). just name it err or what you like, and please untangle the if() if (err>=0) return if (err==-2) return return -1 just my

Re: [PATCH v2 9/9] loop: Add LOOP_CONFIGURE ioctl

2022-11-18 Thread Kang-Che Sung
On Friday, November 18, 2022, Xiaoming Ni wrote: > LOOP_CONFIGURE is added to Linux 5.8 > > This allows userspace to completely setup a loop device with a single > ioctl, removing the in-between state where the device can be partially > configured - eg the loop device has a backing file

Re: [PATCH v2 2/9] loop:refactor: extract subfunction get_next_free_loop()

2022-11-18 Thread Kang-Che Sung
On Friday, November 18, 2022, Xiaoming Ni wrote: > Step 2 of micro-refactoring the set_loop function () > Extract subfunction get_next_free_loop() from set_loop() > > Also fix miss free(try) when stat(try) and mknod fail > > function old new

Re: [PATCH v2 6/9] loop:refactor: Use a structure to reduce parameters

2022-11-18 Thread Kang-Che Sung
On Friday, November 18, 2022, Xiaoming Ni wrote: > Step 6 of micro-refactoring the set_loop(): > Use structs to avoid transferring a large number of parameters > in set_loop_configure() and set_loop_info() > > function old new