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

[disk][linux] fix readlink error which system boot by nfs mount #1291

Merged
merged 2 commits into from May 5, 2022

Conversation

arstercz
Copy link
Contributor

Some host maybe boot the linux os with nfs mount, such as:

# cat /proc/self/mountinfo
14 1 0:14 / / rw,relatime - nfs /dev/root rw,vers=2,rsize=4096,wsize=4096,namlen=255,hard,nolock,proto=udp,port=65535,timeo=11,retrans=3,sec=sys,mountport=65535,addr=10.1.1.10
15 14 0:3 / /proc rw,relatime - proc /proc rw
16 15 0:13 / /proc/bus/usb rw,relatime - usbfs /proc/bus/usb rw
17 14 0:0 / /sys rw,relatime - sysfs /sys rw
18 14 0:15 / /dev rw,relatime - tmpfs none rw,mode=755
19 18 0:9 / /dev/pts rw,relatime - devpts devpts rw,gid=5,mode=620
20 14 8:0 / /export rw,relatime - xfs /dev/sda rw,noquota
21 15 0:16 / /proc/sys/fs/binfmt_misc rw,relatime - binfmt_misc none rw

and the device 0:14 can not found at this host:

# ls /sys/dev/block/ -hl
total 0
lrwxrwxrwx  1 root root 0 Apr 26 18:14 1:0 -> ../../block/ram0
lrwxrwxrwx  1 root root 0 Apr 26 18:14 1:1 -> ../../block/ram1
lrwxrwxrwx  1 root root 0 Apr 26 18:14 1:10 -> ../../block/ram10
......
lrwxrwxrwx  1 root root 0 Apr 26 18:14 7:7 -> ../../block/loop7
lrwxrwxrwx  1 root root 0 Apr 26 18:14 8:0 -> ../../block/sda
lrwxrwxrwx  1 root root 0 Apr 26 18:14 9:0 -> ../../block/md0

so we'll get the following error:

readlink /sys/dev/block/0:14: no such file or directory

this commit ignore the nfs type so that we can skip this error.

@shirou
Copy link
Owner

shirou commented Apr 29, 2022

According to the psutil implementation, there are other ways, but they are more complicated. Could you show us following ?

  • /proc/partitions
  • /sys/class/block/

@arstercz
Copy link
Contributor Author

arstercz commented Apr 29, 2022

Hi @shirou , because we compiled the(kernel-2.6.32) on an old system(centos 5(kernel-2.6.18)), so there is no dirs /sys/class/block,

# cat /proc/partitions
major minor  #blocks  name

   8        0 1468006400 sda


# ls -hl /sys/class/block
ls: /sys/class/block: No such file or directory


# ls -hl /sys/block/
total 0
drwxr-xr-x  6 root root 0 Apr 26 18:14 loop0
drwxr-xr-x  6 root root 0 Apr 26 18:14 loop1
drwxr-xr-x  6 root root 0 Apr 26 18:14 loop2
drwxr-xr-x  6 root root 0 Apr 26 18:14 loop3
drwxr-xr-x  6 root root 0 Apr 26 18:14 loop4
drwxr-xr-x  6 root root 0 Apr 26 18:14 loop5
drwxr-xr-x  6 root root 0 Apr 26 18:14 loop6
drwxr-xr-x  6 root root 0 Apr 26 18:14 loop7
drwxr-xr-x  7 root root 0 Apr 26 18:14 md0
drwxr-xr-x  6 root root 0 Apr 26 18:14 ram0
drwxr-xr-x  6 root root 0 Apr 26 18:14 ram1
drwxr-xr-x  6 root root 0 Apr 26 18:14 ram10
drwxr-xr-x  6 root root 0 Apr 26 18:14 ram11
drwxr-xr-x  6 root root 0 Apr 26 18:14 ram12
drwxr-xr-x  6 root root 0 Apr 26 18:14 ram13
drwxr-xr-x  6 root root 0 Apr 26 18:14 ram14
drwxr-xr-x  6 root root 0 Apr 26 18:14 ram15
drwxr-xr-x  6 root root 0 Apr 26 18:14 ram2
drwxr-xr-x  6 root root 0 Apr 26 18:14 ram3
drwxr-xr-x  6 root root 0 Apr 26 18:14 ram4
drwxr-xr-x  6 root root 0 Apr 26 18:14 ram5
drwxr-xr-x  6 root root 0 Apr 26 18:14 ram6
drwxr-xr-x  6 root root 0 Apr 26 18:14 ram7
drwxr-xr-x  6 root root 0 Apr 26 18:14 ram8
drwxr-xr-x  6 root root 0 Apr 26 18:14 ram9
drwxr-xr-x  6 root root 0 Apr 25 17:31 sda



# cat /proc/self/mountinfo
14 1 0:14 / / rw,relatime - nfs /dev/root rw,vers=2,rsize=4096,wsize=4096,namlen=255,hard,nolock,proto=udp,port=65535,timeo=11,retrans=3,sec=sys,mountport=65535,addr=10.1.1.10
15 14 0:3 / /proc rw,relatime - proc /proc rw
16 15 0:13 / /proc/bus/usb rw,relatime - usbfs /proc/bus/usb rw
17 14 0:0 / /sys rw,relatime - sysfs /sys rw
18 14 0:15 / /dev rw,relatime - tmpfs none rw,mode=755
19 18 0:9 / /dev/pts rw,relatime - devpts devpts rw,gid=5,mode=620
20 14 8:0 / /export rw,relatime - xfs /dev/sda rw,noquota
21 15 0:16 / /proc/sys/fs/binfmt_misc rw,relatime - binfmt_misc none rw


# df -hl
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda              1.4T   41G  1.4T   3% /export


# mount  -l
manager_host:/export/backup on / type nfs (rw,addr=10.1.1.10)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
usbfs on /proc/bus/usb type usbfs (rw)
/dev/sda on /export type xfs (rw) []
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)


# cat /proc/cmdline
root=/dev/nfs nfsroot=10.1.1.10:/export/backup ip=dhcp BOOT_IMAGE=pxeboot/vmlinuz.backup


# rdev
0x000e /

@shirou
Copy link
Owner

shirou commented May 1, 2022

Thank you for the report. It seems we can not get a root device from those files.

According to this psutil code, use /dev/root if we can not find a root device.

So, how about change error handling on here like this?

if err == nil {
	d.Device = strings.Replace(d.Device, "root", filepath.Base(devpath), 1)
}

@arstercz
Copy link
Contributor Author

arstercz commented May 1, 2022

Thanks @shirou , we should follow the psutil principles, and I test ok.

Copy link
Owner

@shirou shirou left a comment

Choose a reason for hiding this comment

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

Thank you for your update!

@shirou shirou merged commit 009ec50 into shirou:master May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants