Fix Linux fcntl OFD locks on unsupported kernels

Message ID b6312c00-48f9-a2f9-7ac0-46dcf4ec3c4e@linaro.org
State Dropped
Headers

Commit Message

Adhemerval Zanella Netto July 27, 2018, 2:24 p.m. UTC
  On 27/07/2018 10:27, Florian Weimer wrote:
> On 07/27/2018 03:12 PM, Adhemerval Zanella wrote:
>> This patch make the OFD tests return unsupported if kernel does not
>> support OFD locks (it was added on 3.15).
>>
>> Checked on a ia64-linux-gnu with Linux 3.14.
>>
>>     * sysdeps/unix/sysv/linux/tst-ofdlocks.c: Return unsupported if
>>     kernel does not support OFD locks.
>>     * sysdeps/unix/sysv/linux/tst-ofdlocks-compat.c: Likewise.
>> ---
>>   ChangeLog                                     | 6 ++++++
>>   sysdeps/unix/sysv/linux/tst-ofdlocks-compat.c | 7 ++++++-
>>   sysdeps/unix/sysv/linux/tst-ofdlocks.c        | 7 ++++++-
>>   3 files changed, 18 insertions(+), 2 deletions(-)
>>
>> diff --git a/sysdeps/unix/sysv/linux/tst-ofdlocks-compat.c b/sysdeps/unix/sysv/linux/tst-ofdlocks-compat.c
>> index 03c4abf..8da5a0b 100644
>> --- a/sysdeps/unix/sysv/linux/tst-ofdlocks-compat.c
>> +++ b/sysdeps/unix/sysv/linux/tst-ofdlocks-compat.c
>> @@ -62,7 +62,12 @@ do_test (void)
>>       .l_start  = (off64_t)INT32_MAX + 1024,
>>       .l_len    = 1024,
>>     };
>> -  TEST_VERIFY_EXIT (fcntl (temp_fd, F_OFD_SETLKW, &lck64) == 0);
>> +  int ret = fcntl (temp_fd, F_OFD_SETLKW, &lck64);
>> +  if (ret == -1 && errno == EINVAL)
>> +    /* OFD locks are only available on Linux 3.15.  */
>> +    FAIL_UNSUPPORTED ("fcntl (F_OFD_SETLKW) not supported)");
> 
> Should use %m.

This does not add much information, but it does not hurt either.

> 
>>     /* Open file description locks placed through the same open file description
>>        (either by same file descriptor or a duplicated one created by fork,
>> diff --git a/sysdeps/unix/sysv/linux/tst-ofdlocks.c b/sysdeps/unix/sysv/linux/tst-ofdlocks.c
>> index bd345e9..66c7856 100644
>> --- a/sysdeps/unix/sysv/linux/tst-ofdlocks.c
>> +++ b/sysdeps/unix/sysv/linux/tst-ofdlocks.c
>> @@ -46,7 +46,12 @@ do_test (void)
>>       .l_start  = (off64_t)INT32_MAX + 1024,
>>       .l_len    = 1024,
>>     };
>> -  TEST_VERIFY_EXIT (fcntl64 (temp_fd, F_OFD_SETLKW, &lck64) == 0);
>> +  int ret = fcntl64 (temp_fd, F_OFD_SETLKW, &lck64);
>> +  if (ret == -1 && errno == EINVAL)
>> +    /* OFD locks are only available on Linux 3.15.  */
>> +    FAIL_UNSUPPORTED ("fcntl (F_OFD_SETLKW) not supported)");
> 
> Likewise.
> 
> This could use TEST_COMPARE (twice).
> 
>> +  TEST_VERIFY_EXIT (ret == 0);
> 
> Thanks,
> Florian

Patch updated below:
  

Comments

Florian Weimer July 27, 2018, 3:22 p.m. UTC | #1
On 07/27/2018 04:24 PM, Adhemerval Zanella wrote:
> 
> 
> On 27/07/2018 10:27, Florian Weimer wrote:
>> On 07/27/2018 03:12 PM, Adhemerval Zanella wrote:
>>> This patch make the OFD tests return unsupported if kernel does not
>>> support OFD locks (it was added on 3.15).
>>>
>>> Checked on a ia64-linux-gnu with Linux 3.14.
>>>
>>>      * sysdeps/unix/sysv/linux/tst-ofdlocks.c: Return unsupported if
>>>      kernel does not support OFD locks.
>>>      * sysdeps/unix/sysv/linux/tst-ofdlocks-compat.c: Likewise.
>>> ---
>>>    ChangeLog                                     | 6 ++++++
>>>    sysdeps/unix/sysv/linux/tst-ofdlocks-compat.c | 7 ++++++-
>>>    sysdeps/unix/sysv/linux/tst-ofdlocks.c        | 7 ++++++-
>>>    3 files changed, 18 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/sysdeps/unix/sysv/linux/tst-ofdlocks-compat.c b/sysdeps/unix/sysv/linux/tst-ofdlocks-compat.c
>>> index 03c4abf..8da5a0b 100644
>>> --- a/sysdeps/unix/sysv/linux/tst-ofdlocks-compat.c
>>> +++ b/sysdeps/unix/sysv/linux/tst-ofdlocks-compat.c
>>> @@ -62,7 +62,12 @@ do_test (void)
>>>        .l_start  = (off64_t)INT32_MAX + 1024,
>>>        .l_len    = 1024,
>>>      };
>>> -  TEST_VERIFY_EXIT (fcntl (temp_fd, F_OFD_SETLKW, &lck64) == 0);
>>> +  int ret = fcntl (temp_fd, F_OFD_SETLKW, &lck64);
>>> +  if (ret == -1 && errno == EINVAL)
>>> +    /* OFD locks are only available on Linux 3.15.  */
>>> +    FAIL_UNSUPPORTED ("fcntl (F_OFD_SETLKW) not supported)");
>>
>> Should use %m.
> 
> This does not add much information, but it does not hurt either.

Ah right, it would have to be used to report other failures.  So your 
original patch is okay as-is.

Thanks,
Florian
  

Patch

diff --git a/sysdeps/unix/sysv/linux/tst-ofdlocks-compat.c b/sysdeps/unix/sysv/linux/tst-ofdlocks-compat.c
index 03c4abf..9930a50 100644
--- a/sysdeps/unix/sysv/linux/tst-ofdlocks-compat.c
+++ b/sysdeps/unix/sysv/linux/tst-ofdlocks-compat.c
@@ -62,7 +62,12 @@  do_test (void)
     .l_start  = (off64_t)INT32_MAX + 1024,
     .l_len    = 1024,
   };
-  TEST_VERIFY_EXIT (fcntl (temp_fd, F_OFD_SETLKW, &lck64) == 0);
+  int ret = fcntl (temp_fd, F_OFD_SETLKW, &lck64);
+  if (ret == -1 && errno == EINVAL)
+    /* OFD locks are only available on Linux 3.15.  */
+    FAIL_UNSUPPORTED ("fcntl (F_OFD_SETLKW) not supported): %m");
+
+  TEST_COMPARE (ret, 0);
 
   /* Open file description locks placed through the same open file description
      (either by same file descriptor or a duplicated one created by fork,
diff --git a/sysdeps/unix/sysv/linux/tst-ofdlocks.c b/sysdeps/unix/sysv/linux/tst-ofdlocks.c
index bd345e9..1aa5c2a 100644
--- a/sysdeps/unix/sysv/linux/tst-ofdlocks.c
+++ b/sysdeps/unix/sysv/linux/tst-ofdlocks.c
@@ -46,7 +46,12 @@  do_test (void)
     .l_start  = (off64_t)INT32_MAX + 1024,
     .l_len    = 1024,
   };
-  TEST_VERIFY_EXIT (fcntl64 (temp_fd, F_OFD_SETLKW, &lck64) == 0);
+  int ret = fcntl64 (temp_fd, F_OFD_SETLKW, &lck64);
+  if (ret == -1 && errno == EINVAL)
+    /* OFD locks are only available on Linux 3.15.  */
+    FAIL_UNSUPPORTED ("fcntl (F_OFD_SETLKW) not supported): %m");
+
+  TEST_COMPARE (ret, 0);
 
   /* Open file description locks placed through the same open file description
      (either by same file descriptor or a duplicated one created by fork,