ibm-s390-linux / s390-tools

Tools for use with the s390 Linux kernel and device drivers
MIT License
63 stars 59 forks source link

dasd_get_host_access_count libdasd/dasd_sys.c fails when referencing a loopback mounted device #92

Closed markkp closed 3 years ago

markkp commented 3 years ago

When using "fdasd -f /dev/loop0" the dasd_get_host_access_count routine in libdasd/dasd_sys.c tries to access the file /sys/bus/ccw/devices/"busid"/host_access_count. For DASD images mounted via a loopback device, that fails.

This results in the following message being output: WARNING: Disk /dev/loop0 is online on operating system instances in 263849296 different LPARs. Ensure that the disk is not being used by a system outside your LPAR. Note: Your installation might include z/VM systems that are configured to automatically vary on disks, regardless of whether they are subsequently used.

util_sys_get_dev_addr in libutil/util_sys.c gets a -1 return code from the call to readlink, and then itself returns -1 to dasd_get_host_access_count. The following if statement if (!util_sys_get_dev_addr(device, busid)) return 0;

fails, so instead of returning a 0, execution continues to the next statements: path = util_path_sysfs("bus/ccw/devices/%s/host_access_count", busid); util_file_read_l(&value, 10, path); free(path);

    return value;

Since the variable value is not initialized, it returns a random non-zero number to the caller.

Looking further, if I test with a real DASD volume, the dasd_get_host_access_count call to util_sys_get_dev_addr gets a zero return code, and so returns a value of 0 to the caller. That doesn't seem right, since it never tries to read the /sys/bus/ccw/devices/"busid"/host_access_count file, so it's not returning an actual value from there. If I force the execution of: path = util_path_sysfs("bus/ccw/devices/%s/host_access_count", busid); util_file_read_l(&value, 10, path); Then the call to util_file_readl happens, and in that routine, the call to file_gets(buf, sizeof(buf), path)) fails so it returns -1.

Out of curiosity, I tried to manually look at /sys/bus/ccw/devices/0.0.0100/host_access_count on my system. Everything I tried resulted in an "Operation not supported" error message.

To sum up, it looks like there's two problems here:

  1. The if (!util_sys_get_dev_addr(device, busid)) is "backward."
  2. The sysfs host_access_count file doesn't seem to be readable, at least on any of my systems.
hoeppnerj commented 3 years ago

Hi Mark,

the main issue is being fixed internally already. You're right, this check https://github.com/ibm-s390-tools/s390-tools/blob/885ff0a03f5561acb76e7201ddb2c9de30a5e123/libdasd/dasd_sys.c#L217 has to be turned over. I tested the loop back device problem with our fix and it works.

About the "Operaion not supported", I don't see this issue on our systems. If you have details on how to reproduce it and you think it is s390-tools related, please open another issue for it. If you think it might rather be Kernel related, use the usual channels to report the problem. Thanks!

This issue will be closed once the commit goes upstream. Thanks for reporting!

hoeppnerj commented 3 years ago

Fixed with https://github.com/ibm-s390-tools/s390-tools/commit/353403824b5112c254f6788bad5edbbb19b96683