Re: [PULL v2 02/16] block/file-posix: introduce helper functions for sysfs attributes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 6/2/23 2:18 PM, Sam Li wrote:
> Matthew Rosato <mjrosato@xxxxxxxxxxxxx> 于2023年6月1日周四 02:21写道:
>>
>> On 5/15/23 12:04 PM, Stefan Hajnoczi wrote:
>>> From: Sam Li <faithilikerun@xxxxxxxxx>
>>>
>>> Use get_sysfs_str_val() to get the string value of device
>>> zoned model. Then get_sysfs_zoned_model() can convert it to
>>> BlockZoneModel type of QEMU.
>>>
>>> Use get_sysfs_long_val() to get the long value of zoned device
>>> information.
>>
>> Hi Stefan, Sam,
>>
>> I am having an issue on s390x using virtio-blk-{pci,ccw} backed by an NVMe partition, and I've bisected the root cause to this commit.
>>
>> I noticed that tests which use the partition e.g. /dev/nvme0n1p1 as a backing device would fail, but those that use the namespace e.g. /dev/nvme0n1 would still succeed.  The root issue appears to be that the block device associated with the partition does not have a "max_segments" attribute, and prior to this patch hdev_get_max_segment() would return -ENOENT in this case.  After this patch, however, QEMU is instead crashing.  It looks like g_file_get_contents is returning 0 with a len == 0 if the specified sysfs path does not exist.  The following diff on top seems to resolve the issue for me:
>>
>>
>> diff --git a/block/file-posix.c b/block/file-posix.c
>> index 0ab158efba2..eeb0247c74e 100644
>> --- a/block/file-posix.c
>> +++ b/block/file-posix.c
>> @@ -1243,7 +1243,7 @@ static int get_sysfs_str_val(struct stat *st, const char *attribute,
>>                                  major(st->st_rdev), minor(st->st_rdev),
>>                                  attribute);
>>      ret = g_file_get_contents(sysfspath, val, &len, NULL);
>> -    if (ret == -1) {
>> +    if (ret == -1 || len == 0) {
>>          return -ENOENT;
>>      }
>>
> 
> Hi Matthew,
> 
> Thanks for the information. After some checking, I think the bug here
> is that g_file_get_contens returns g_boolean value and the error case
> will return 0 instead of -1 in my previous code. Can the following
> line fix your issue on the s390x device?
> 
> + if (ret == FALSE) {
> 
> https://docs.gtk.org/glib/func.file_get_contents.html

Hi Sam,

Ah, good point, I didn't notice file_get_contents was meant to be a bool return and wondered why I was getting a return of 0 in the failing case, hence the check for len == 0.

Anyway, yes, I verified that checking for ret == FALSE fixes the issue.  FWIW, along the same line I also checked that this works:

    if (!g_file_get_contents(sysfspath, val, &len, NULL)) {
        return -ENOENT;
    }

which I personally think looks cleaner and matches the other uses of g_file_get_contents in QEMU.  Could also get rid of ret and just return 0 at the bottom of the function.

Thanks,
Matt





[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux