[PATCH] loop: fix a race when a free loop device is snatched

2022-10-21 Thread Xiaoming Ni
a799 ("mount,losetup: use /dev/loop-control is it exists") Signed-off-by: Xiaoming Ni --- libbb/loop.c | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libbb/loop.c b/libbb/loop.c index cb8fa2442..845565d7b 100644 --- a/libbb/loop.c +++ b/libbb/loop.c @@ -218,8 +

ping //Re: [PATCH] loop: fix a race when a free loop device is snatched

2022-10-29 Thread Xiaoming Ni
ping On 2022/10/21 15:10, Xiaoming Ni wrote: When /dev/loop-control exists and *device is empty, the mounting fails due to concurrent contention. Code Execution Flow: try = xasprintf(LOOP_FORMAT, i); for (i = 0; i <= 0xf; i++) { // The value of "try" i

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

2022-11-17 Thread Xiaoming Ni
-- (add/remove: 0/0 grow/shrink: 1/0 up/down: 3/0) Total: 3 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 41 - 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/libbb/loop.c b/libbb/loop.c index

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 open_file

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

2022-11-17 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 7/9] loop:refactor: Extract subfunction do_stat_and_mknod()

2022-11-17 Thread Xiaoming Ni
-- (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-20) Total: -20 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 39 +-- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/libbb/loop.c b/libbb/loop.c index 2200ccb9a

[PATCH 9/9] loop: Add LOOP_CONFIGURE ioctl

2022-11-17 Thread Xiaoming Ni
oop 703 626 -77 -- (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-77) Total: -77 bytes else: add/remove: 0/0 grow/shrink: 0/0 up/down: 0/0 (0) Signed-off-by: Xiaoming

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

2022-11-17 Thread Xiaoming Ni
-- (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-2) Total: -2 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 25 + 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/libbb/loop.c b/libbb/loop.c index 750642ade..c517ceb13

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

2022-11-17 Thread Xiaoming Ni
758 734 -24 -- (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-24) Total: -24 bytes Fixes: 3448914e8cc5 ("mount,losetup: use /dev/loop-control is it exists") Signed-off-by: Xiaoming Ni --- li

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

2022-11-17 Thread Xiaoming Ni
-- (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-34) Total: -34 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 91 +++- 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/libbb/loop.c b

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

2022-11-17 Thread Xiaoming Ni
720 +12 -- (add/remove: 0/0 grow/shrink: 1/0 up/down: 12/0) Total: 12 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 54 +--- 1 file changed, 30

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

2022-11-17 Thread Xiaoming Ni
-- (add/remove: 0/0 grow/shrink: 1/0 up/down: 8/0) Total: 8 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 63 ++-- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/libbb/loop.c b/libbb/loop.c

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

2022-11-17 Thread Xiaoming Ni
: 0/-57) Total: -57 bytes ---- Xiaoming Ni (9): loop:refactor: extract subfunction open_file() loop:refactor: extract subfunction get_next_free_loop() loop:refactor: del close_and_try_next_loopN loop:refactor: extract subfunction set_loop_info() loop:refactor: extract subfunct

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

2022-11-18 Thread Xiaoming Ni
-- (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-34) Total: -34 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 91 +++- 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/libbb/loop.c b

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

2022-11-18 Thread Xiaoming Ni
720 +12 -- (add/remove: 0/0 grow/shrink: 1/0 up/down: 12/0) Total: 12 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 54 +--- 1 file changed, 30

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

2022-11-18 Thread Xiaoming Ni
Builders can use config to choose which algorithm to build into their busybox binary --- v2: add config for builder to select v1: http://lists.busybox.net/pipermail/busybox/2022-November/089969.html --- Xiaoming Ni (9): loop:refactor: extract subfunction open_file() loop:refactor: extract

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

2022-11-18 Thread Xiaoming Ni
758 734 -24 -- (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-24) Total: -24 bytes Fixes: 3448914e8cc5 ("mount,losetup: use /dev/loop-control is it exists") Signed-off-by: Xiaoming Ni --- li

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

2022-11-18 Thread Xiaoming Ni
ill send patch v3 later Thanks Von: busybox im Auftrag von Xiaoming Ni Gesendet: Freitag, 18. November 2022 02:01:51 An: busybox@busybox.net; vda.li...@googlemail.com Cc: wang...@huawei.com Betreff: [PATCH 2/9] loop:refactor: extract subfunction get_n

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

2022-11-18 Thread Xiaoming Ni
patch 5 by extracting functions Von: busybox im Auftrag von Xiaoming Ni Gesendet: Freitag, 18. November 2022 13:14:43 An: busybox@busybox.net; vda.li...@googlemail.com; c...@gmx.com; explore...@gmail.com Cc: wang...@huawei.com Betreff: [PATCH v2 4/9] loop:

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

2022-11-18 Thread Xiaoming Ni
-- (add/remove: 0/0 grow/shrink: 1/0 up/down: 16/0) Total: 16 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 39 --- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/libbb/loop.c b/libbb/loop.c index

[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
n: 0/0) Total: 0 bytes Signed-off-by: Xiaoming Ni --- libbb/Config.src | 22 ++ libbb/loop.c | 47 ++- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/libbb/Config.src b/libbb/Config.src index 66a3ffa23..b7f9ddab4

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

2022-11-18 Thread Xiaoming Ni
-- (add/remove: 0/0 grow/shrink: 1/0 up/down: 8/0) Total: 8 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 63 ++-- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/libbb/loop.c b/libbb/loop.c

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

2022-11-18 Thread Xiaoming Ni
-- (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-20) Total: -20 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 39 +-- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/libbb/loop.c b/libbb/loop.c index 2200ccb9a

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.

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

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

2022-11-18 Thread Xiaoming Ni
-- (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-2) Total: -2 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 25 + 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/libbb/loop.c b/libbb/loop.c index 750642ade..c517ceb13

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

2022-11-20 Thread Xiaoming Ni
if (rc == 0) { + return lfd; + } In this case, duplicate "if(rc==0)" occurs. Is that worse? Thanks Xiaoming Ni Von: busybox im Auftrag von Xiaoming Ni Gesendet: Freitag, 18. November 2022 13:14:44 An: busybox@busybox.net; v

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

2022-11-20 Thread Xiaoming Ni
On 2022/11/19 1:40, Kang-Che Sung wrote: On Friday, November 18, 2022, Xiaoming Ni <mailto:nixiaom...@huawei.com>> wrote: > Step 2 of micro-refactoring the set_loop function () >         Extract subfunction get_next_free_loop() from set_loop() > > Also fix miss fr

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

2022-11-20 Thread Xiaoming Ni
720 +12 -- (add/remove: 0/0 grow/shrink: 1/0 up/down: 12/0) Total: 12 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 54 +--- 1 file changed, 30

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

2022-11-20 Thread Xiaoming Ni
On 2022/11/19 2:06, Kang-Che Sung wrote: On Friday, November 18, 2022, Xiaoming Ni <mailto:nixiaom...@huawei.com>> wrote: > Step 6 of micro-refactoring the set_loop(): >         Use structs to avoid transferring a large number of parameters >         in

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

2022-11-20 Thread Xiaoming Ni
-- (add/remove: 0/0 grow/shrink: 1/0 up/down: 16/0) Total: 16 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 39 --- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/libbb/loop.c b/libbb/loop.c index

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

2022-11-20 Thread Xiaoming Ni
758 734 -24 -- (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-24) Total: -24 bytes Fixes: 3448914e8cc5 ("mount,losetup: use /dev/loop-control is it exists") Signed-off-by: Xiaoming Ni --- li

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

2022-11-20 Thread Xiaoming Ni
+116 -- (add/remove: 0/0 grow/shrink: 1/0 up/down: 116/0) Total: 116 bytes Signed-off-by: Xiaoming Ni --- libbb/Config.src | 22 ++ libbb/loop.c | 47 ++- 2 files changed, 68 insertions(+), 1 de

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

2022-11-20 Thread Xiaoming Ni
-- (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-20) Total: -20 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 38 -- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/libbb/loop.c b/libbb/loop.c index 0b1336a02

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

2022-11-20 Thread Xiaoming Ni
-- (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-34) Total: -34 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 91 +++- 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/libbb/loop.c b

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

2022-11-20 Thread Xiaoming Ni
-- (add/remove: 0/0 grow/shrink: 1/0 up/down: 8/0) Total: 8 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 63 ++-- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/libbb/loop.c b/libbb/loop.c

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

2022-11-20 Thread Xiaoming Ni
On 2022/11/19 2:22, Kang-Che Sung wrote: On Friday, November 18, 2022, Xiaoming Ni <mailto:nixiaom...@huawei.com>> wrote: > LOOP_CONFIGURE is added to Linux 5.8 > > This allows userspace to completely setup a loop device with a single > ioctl, removing the i

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

2022-11-20 Thread Xiaoming Ni
nd_mknod(). patch9: Rename set_loop_configure_old() to set_loop_fd_and_status() v2: http://lists.busybox.net/pipermail/busybox/2022-November/089990.html changes in patch9: add config for builder to select v1: http://lists.busybox.net/pipermail/busybox/2022-November/089969.html --- *** BLURB H

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

2022-11-20 Thread Xiaoming Ni
-- (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-2) Total: -2 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 25 + 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/libbb/loop.c b/libbb/loop.c index 750642ade..c517ceb13

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

2022-11-20 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 v4 4/9] loop:refactor: extract subfunction set_loop_info()

2022-11-21 Thread Xiaoming Ni
-- (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-34) Total: -34 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 91 +++- 1 file changed, 47 insertions(+), 44 deletions(-) diff --git a/libbb/loop.c b

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

2022-11-21 Thread Xiaoming Ni
-- (add/remove: 0/0 grow/shrink: 1/0 up/down: 16/0) Total: 16 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 39 --- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/libbb/loop.c b/libbb/loop.c index

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

2022-11-21 Thread Xiaoming Ni
h9: Rename set_loop_configure_old() to set_loop_fd_and_status() v2: http://lists.busybox.net/pipermail/busybox/2022-November/089990.html changes in patch9: add config for builder to select v1: http://lists.busybox.net/pipermail/busybox/2022-November/089969.html --- Xiaoming Ni (9): l

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

2022-11-21 Thread Xiaoming Ni
-- (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-2) Total: -2 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 25 + 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/libbb/loop.c b/libbb/loop.c index 750642ade..c517ceb13

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

2022-11-21 Thread Xiaoming Ni
On 2022/11/21 15:50, Kang-Che Sung wrote: On Mon, Nov 21, 2022 at 9:19 AM Xiaoming Ni wrote: static int get_next_free_loop(char *dev, size_t dev_size, int id) { int loopdevno = get_free_loop(); if (loopdevno >= 0) { snprintf(dev, dev_size, LOOP_FOR

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

2022-11-21 Thread Xiaoming Ni
758 734 -24 -- (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-24) Total: -24 bytes Fixes: 3448914e8cc5 ("mount,losetup: use /dev/loop-control is it exists") Signed-off-by: Xiaoming Ni --- li

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

2022-11-21 Thread Xiaoming Ni
720 +12 -- (add/remove: 0/0 grow/shrink: 1/0 up/down: 12/0) Total: 12 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 54 +--- 1 file changed, 30

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

2022-11-21 Thread Xiaoming Ni
-- (add/remove: 0/0 grow/shrink: 1/0 up/down: 8/0) Total: 8 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 63 ++-- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/libbb/loop.c b/libbb/loop.c

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

2022-11-21 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 v4 7/9] loop:refactor: Extract subfunction do_stat_and_mknod()

2022-11-21 Thread Xiaoming Ni
-- (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-20) Total: -20 bytes Signed-off-by: Xiaoming Ni --- libbb/loop.c | 38 -- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/libbb/loop.c b/libbb/loop.c index 5f0db4b18

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

2022-11-21 Thread Xiaoming Ni
+116 -- (add/remove: 0/0 grow/shrink: 1/0 up/down: 116/0) Total: 116 bytes Signed-off-by: Xiaoming Ni --- libbb/Config.src | 22 ++ libbb/loop.c | 45 + 2 files changed, 67 insertions(+) diff

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

2022-11-20 Thread Xiaoming Ni
On 2022/11/21 12:28, Kang-Che Sung wrote: On Mon, Nov 21, 2022 at 9:31 AM Xiaoming Ni wrote: Also, it is unclear why there is the need to clone the loopinfo buffer. > /* Old kernel, does not support LO_FLAGS_AUTOCLEAR? */ > /* (this code path is not