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

ceph-disk: fix signed integer is greater than maximum when call major #19196

Merged
merged 1 commit into from Dec 3, 2017

Conversation

shun-s
Copy link
Contributor

@shun-s shun-s commented Nov 28, 2017

fix signed integer is greater than maximum when call os.major
using python 2.7.5 in Centos 7

when calling os.major in block_path, it may broken due to already exist bugs in python 2.7.5 [1].

As you see, this bug has been fixed in python after 2.7.14 (also teseted in my enviroment), just upgradeing python is Ok.
but when i think 2.7.5 is largely used in Centos 7, upgrading could have influenced to other applications.

so i think implementing os.major and os.minor like major and minor in glibc [2] mayb be a good idea.

but i'm not sure that if there is any other problems? please take a review, thanks

[1] Dan MacDonald told me that "os.mknod()" should accept devices >32 bits.
https://bugs.python.org/issue23098
[2] https://github.com/lattera/glibc/blob/master/sysdeps/unix/sysv/linux/sys/sysmacros.h

Signed-off-by: Song Shun song.shun3@zte.com.cn

@shun-s
Copy link
Contributor Author

shun-s commented Nov 28, 2017

[root@Ceph-141 ~]# python
Python 2.7.5 (default, Jun 17 2014, 18:11:42) 
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.stat('/dev/sdx').st_rdev
2147494656
>>> os.major(os.stat('/dev/sdx').st_rdev)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: signed integer is greater than maximum
>>> devid = os.stat('/dev/sdx').st_rdev
>>> major = ((devid >> 8) & 0xfff) | ((devid >> 32) & ~0xfff)
>>> major
43
>>> minor = (devid & 0xff) | ((devid >> 12) & ~0xff)
>>> minor
524288

@tchaikov tchaikov self-requested a review November 28, 2017 07:44
@@ -603,7 +603,8 @@ def block_path(dev):
return dev
path = os.path.realpath(dev)
rdev = os.stat(path).st_rdev
(M, m) = (os.major(rdev), os.minor(rdev))
M = ((rdev >> 8) & 0xfff) | ((rdev >> 32) & ~0xfff)
Copy link
Contributor

Choose a reason for hiding this comment

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

i'd suggest monkey patching os.major() and os.minor(). in other words, add following code snippet at the beginning of main.py, right before class Ptype(object)

try:
    # see https://bugs.python.org/issue23098
    os.major(0x80002b00)
except OverflowError:
    os.major = lambda devid: ((devid >> 8) & 0xfff) | ((devid >> 32) & ~0xfff)
    os.minor = lambda devid: (devid & 0xff) | ((devid >> 12) & ~0xff)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tchaikov , thanks your detailed instruction. ^^
i've done with above monkey patch, please review again.

Copy link
Contributor

Choose a reason for hiding this comment

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

please drop this change. as it is not necessary anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. done.

Copy link
Contributor

Choose a reason for hiding this comment

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

no, you reverted the change i suggested.

@@ -603,7 +603,8 @@ def block_path(dev):
return dev
path = os.path.realpath(dev)
rdev = os.stat(path).st_rdev
(M, m) = (os.major(rdev), os.minor(rdev))
M = ((rdev >> 8) & 0xfff) | ((rdev >> 32) & ~0xfff)
Copy link
Contributor

Choose a reason for hiding this comment

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

please drop this change. as it is not necessary anymore.

@shun-s shun-s force-pushed the wip-cephdisk-fix-major-error branch 3 times, most recently from 35775eb to f77934b Compare November 30, 2017 05:51
  fix signed integer is greater than maximum when call os.major
  using python 2.7.5 in Centos 7

Signed-off-by: Song Shun <song.shun3@zte.com.cn>
@shun-s
Copy link
Contributor Author

shun-s commented Nov 30, 2017

@tchaikov , i think this time i totally get what you mean, please review.

@tchaikov
Copy link
Contributor

tchaikov commented Dec 2, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants