Skip to content
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

Endless loop in zpool_do_remove() on platforms with unsigned char #8789

Merged
merged 1 commit into from
May 28, 2019

Conversation

loli10K
Copy link
Contributor

@loli10K loli10K commented May 21, 2019

Motivation and Context

On systems where "char" is an unsigned type the value returned by getopt() will never be negative (-1), leading to an endlees loop.

root@linux:~# uname -m
armv7l
root@linux:~# truncate -s 1024m /var/tmp/1
root@linux:~# truncate -s 1024m /var/tmp/2
root@linux:~# zpool create testpool /var/tmp/1 cache /var/tmp/2
root@linux:~# modinfo -F version zfs
0.8.0-rc5
root@linux:~# zpool remove testpool /var/tmp/2
<hang>

zpool is now just wasting CPU cycles:

top - 17:59:31 up 12:22,  4 users,  load average: 1.68, 1.30, 1.42           
Tasks: 355 total,   3 running, 351 sleeping,   0 stopped,   1 zombie       
%Cpu(s): 28.7 us,  4.6 sy,  0.0 ni, 66.6 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st    
KiB Mem :  2024340 total,   633692 free,  1167016 used,   223632 buff/cache     
KiB Swap:        0 total,        0 free,        0 used.   803384 avail Mem 
                                                                            
  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                                                        
  483 root      20   0    7328   1536   1236 R 100.0  0.1   0:27.60 zpool        

Description

Change char c to int c

How Has This Been Tested?

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Performance enhancement (non-breaking change which improves efficiency)
  • Code cleanup (non-breaking change which makes code smaller or more readable)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (a change to man pages or other documentation)

Checklist:

@loli10K loli10K force-pushed the zpool_remove_endless_loop branch from 8903882 to beee51e Compare May 21, 2019 18:08
@loli10K loli10K changed the title Endlees loop in zpool_do_remove() on platforms with unsigned char Endless loop in zpool_do_remove() on platforms with unsigned char May 21, 2019
@loli10K loli10K added the Status: Code Review Needed Ready for review and testing label May 21, 2019
@codecov
Copy link

codecov bot commented May 22, 2019

Codecov Report

Merging #8789 into master will decrease coverage by 0.06%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8789      +/-   ##
==========================================
- Coverage   78.75%   78.68%   -0.07%     
==========================================
  Files         382      381       -1     
  Lines      117809   117797      -12     
==========================================
- Hits        92776    92691      -85     
- Misses      25033    25106      +73
Flag Coverage Δ
#kernel 79.32% <ø> (+0.01%) ⬆️
#user 67.08% <ø> (-0.42%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c3e5907...c7b2812. Read the comment docs.

@chrisrd
Copy link
Contributor

chrisrd commented May 22, 2019

Whilst you're there, may as well fix up the other places where we don't have getopt() returning an int? E.g.:

$ grep -rEn '(int|char).*[[:space:]]c[;,]|getopt\(' cmd | grep -B1 getopt | less +/char
cmd/zstreamdump/zstreamdump.c:240:      char c;
cmd/zstreamdump/zstreamdump.c:254:      while ((c = getopt(argc, argv, ":vCd")) != -1) {
--
cmd/zpool/zpool_main.c:975:     char c;
cmd/zpool/zpool_main.c:980:     while ((c = getopt(argc, argv, "nps")) != -1) {
--
cmd/zfs/zfs_main.c:2241:        signed char c;
cmd/zfs/zfs_main.c:2245:        while ((c = getopt(argc, argv, "rvV:a")) != -1) {
--
cmd/zfs/zfs_main.c:3935:        signed char c;
cmd/zfs/zfs_main.c:3946:        while ((c = getopt(argc, argv, "ro:")) != -1) {

@loli10K loli10K force-pushed the zpool_remove_endless_loop branch from beee51e to 1774ae8 Compare May 23, 2019 04:24
@@ -3932,7 +3932,7 @@ static int
zfs_do_snapshot(int argc, char **argv)
{
int ret = 0;
signed char c;
int char c;
Copy link
Contributor

Choose a reason for hiding this comment

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

A typo here caused the build failures.

On systems where "char" is an unsigned type the value returned by
getopt() will never be negative (-1), leading to an endless loop:
this issue prevents both 'zpool remove' and 'zstreamdump' for
working on some systems.

Signed-off-by: loli10K <ezomori.nozomu@gmail.com>
@loli10K loli10K force-pushed the zpool_remove_endless_loop branch from 1774ae8 to c7b2812 Compare May 25, 2019 04:54
@behlendorf behlendorf requested a review from ikozhukhov May 25, 2019 21:24
@behlendorf
Copy link
Contributor

@chrisrd would you mind reviewing this again.

@ikozhukhov
Copy link
Contributor

i have tested int c; and it is working as well, thanks for this work.

@behlendorf behlendorf added Status: Accepted Ready to integrate (reviewed, tested) and removed Status: Code Review Needed Ready for review and testing labels May 28, 2019
@behlendorf behlendorf merged commit 0869b74 into openzfs:master May 28, 2019
behlendorf pushed a commit that referenced this pull request Jun 7, 2019
On systems where "char" is an unsigned type the value returned by
getopt() will never be negative (-1), leading to an endless loop:
this issue prevents both 'zpool remove' and 'zstreamdump' for
working on some systems.

Reviewed-by: Igor Kozhukhov <igor@dilos.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Chris Dunlop <chris@onthe.net.au>
Signed-off-by: loli10K <ezomori.nozomu@gmail.com>
Closes #8789
allanjude pushed a commit to allanjude/zfs that referenced this pull request Jun 7, 2019
On systems where "char" is an unsigned type the value returned by
getopt() will never be negative (-1), leading to an endless loop:
this issue prevents both 'zpool remove' and 'zstreamdump' for
working on some systems.

Reviewed-by: Igor Kozhukhov <igor@dilos.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Chris Dunlop <chris@onthe.net.au>
Signed-off-by: loli10K <ezomori.nozomu@gmail.com>
Closes openzfs#8789
allanjude pushed a commit to allanjude/zfs that referenced this pull request Jun 15, 2019
On systems where "char" is an unsigned type the value returned by
getopt() will never be negative (-1), leading to an endless loop:
this issue prevents both 'zpool remove' and 'zstreamdump' for
working on some systems.

Reviewed-by: Igor Kozhukhov <igor@dilos.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Chris Dunlop <chris@onthe.net.au>
Signed-off-by: loli10K <ezomori.nozomu@gmail.com>
Closes openzfs#8789
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Accepted Ready to integrate (reviewed, tested)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants