public inbox for libc-help@sourceware.org
 help / color / mirror / Atom feed
* Question about fcntl64
@ 2018-09-12 14:20 Hongzhi, Song
  2018-09-12 17:32 ` Florian Weimer
  0 siblings, 1 reply; 6+ messages in thread
From: Hongzhi, Song @ 2018-09-12 14:20 UTC (permalink / raw)
  To: libc-help

Hi all,

I met a problem with one of ltp testcase, fcntl34, on qemux86.


Testcase source code: ltp/testcases/kernel/syscalls/fcntl/fcntl34.c


In function 'thread_fn_01', struct flock64 lck.l_len is set '1'.

thread_fn_01 ---> SAFE_FCNTL(fd, F_OFD_SETLKW, &lck) ---> fcntl64


But I used 'strace -f ./fcntl34' to trace 'fcntl64' syscall, I found 
that 'lck.l_len'

is set '0'.


The result of strace: note "---> <---"

fcntl64(6, F_OFD_SETLKW, {l_type=F_WRLCK, l_whence=SEEK_SET, l_start=0, 
--- > l_len=0 <---}


I can't find that where dose l_len is set '0'.

So, can someone tell me than why l_len is change to '0' which is set '1' 
previously.


Thanks,

--Hongzhi

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about fcntl64
  2018-09-12 14:20 Question about fcntl64 Hongzhi, Song
@ 2018-09-12 17:32 ` Florian Weimer
  2018-09-13  1:08   ` Hongzhi, Song
  0 siblings, 1 reply; 6+ messages in thread
From: Florian Weimer @ 2018-09-12 17:32 UTC (permalink / raw)
  To: Hongzhi, Song, libc-help

On 09/12/2018 04:23 PM, Hongzhi, Song wrote:
> Testcase source code: ltp/testcases/kernel/syscalls/fcntl/fcntl34.c
> 
> 
> In function 'thread_fn_01', struct flock64 lck.l_len is set '1'.
> 
> thread_fn_01 ---> SAFE_FCNTL(fd, F_OFD_SETLKW, &lck) ---> fcntl64

Please quote the relevant parts of the source code.  What is SAFE_FNCTL?

Thanks,
Florian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about fcntl64
  2018-09-12 17:32 ` Florian Weimer
@ 2018-09-13  1:08   ` Hongzhi, Song
  2018-09-13  2:26     ` Hongzhi, Song
  2018-09-13  8:10     ` Florian Weimer
  0 siblings, 2 replies; 6+ messages in thread
From: Hongzhi, Song @ 2018-09-13  1:08 UTC (permalink / raw)
  To: Florian Weimer, libc-help



On 2018年09月13日 01:32, Florian Weimer wrote:
> On 09/12/2018 04:23 PM, Hongzhi, Song wrote:
>> Testcase source code: ltp/testcases/kernel/syscalls/fcntl/fcntl34.c
>>
>>
>> In function 'thread_fn_01', struct flock64 lck.l_len is set '1'.
>>
>> thread_fn_01 ---> SAFE_FCNTL(fd, F_OFD_SETLKW, &lck) ---> fcntl64
>
> Please quote the relevant parts of the source code.  What is SAFE_FNCTL?
>

OK,

1.part of source code: ltp/testcases/kernel/syscalls/fcntl/fcntl34.c
---
struct flock64 lck = {
           .l_whence = SEEK_SET,
           .l_start  = 0,
--->    .l_len    = 1, <---
};
lck.l_type = F_WRLCK
SAFE_FCNTL(fd, F_OFD_SETLKW, &lck);
---

2.SAFE_FCNTL is defined as a macro:
---
#define SAFE_FCNTL(fd, cmd, ...)                            \
    ---> ({int tst_ret_ = fcntl(fd, cmd, ##__VA_ARGS__);     \ <---
       tst_ret_ == -1 ?                                  \
        tst_brk(TBROK | TERRNO,                          \
                 "fcntl(%i,%s,...) failed", fd, #cmd), 0 \
      : tst_ret_;})
---

3. I used "strace -f ./fcntl34" found that: l_len was changed to '0'.

fcntl64(6, F_OFD_SETLKW, {l_type=F_WRLCK, l_whence=SEEK_SET, l_start=0, 
---> l_len=0 <---}

4. The question is that l_len was set '1', but why it is changed to '0' 
when it is passed to fcntl64.

Thanks,
--Hongzhi

> Thanks,
> Florian
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about fcntl64
  2018-09-13  1:08   ` Hongzhi, Song
@ 2018-09-13  2:26     ` Hongzhi, Song
  2018-09-13  8:10     ` Florian Weimer
  1 sibling, 0 replies; 6+ messages in thread
From: Hongzhi, Song @ 2018-09-13  2:26 UTC (permalink / raw)
  To: Florian Weimer, libc-help

Append source code link:

https://github.com/linux-test-project/ltp/blob/7599ff232b98b4f8440e1410e8721822995877e2/testcases/kernel/syscalls/fcntl/fcntl34.c#L79

The problem is prompt on qemux86.


Thanks,
Hongzhi


On 2018年09月13日 09:10, Hongzhi, Song wrote:
>
>
> On 2018年09月13日 01:32, Florian Weimer wrote:
>> On 09/12/2018 04:23 PM, Hongzhi, Song wrote:
>>> Testcase source code: ltp/testcases/kernel/syscalls/fcntl/fcntl34.c
>>>
>>>
>>> In function 'thread_fn_01', struct flock64 lck.l_len is set '1'.
>>>
>>> thread_fn_01 ---> SAFE_FCNTL(fd, F_OFD_SETLKW, &lck) ---> fcntl64
>>
>> Please quote the relevant parts of the source code.  What is SAFE_FNCTL?
>>
>
> OK,
>
> 1.part of source code: ltp/testcases/kernel/syscalls/fcntl/fcntl34.c
> ---
> struct flock64 lck = {
>           .l_whence = SEEK_SET,
>           .l_start  = 0,
> --->    .l_len    = 1, <---
> };
> lck.l_type = F_WRLCK
> SAFE_FCNTL(fd, F_OFD_SETLKW, &lck);
> ---
>
> 2.SAFE_FCNTL is defined as a macro:
> ---
> #define SAFE_FCNTL(fd, cmd, ...)                            \
>    ---> ({int tst_ret_ = fcntl(fd, cmd, ##__VA_ARGS__);     \ <---
>       tst_ret_ == -1 ?                                  \
>        tst_brk(TBROK | TERRNO,                          \
>                 "fcntl(%i,%s,...) failed", fd, #cmd), 0 \
>      : tst_ret_;})
> ---
>
> 3. I used "strace -f ./fcntl34" found that: l_len was changed to '0'.
>
> fcntl64(6, F_OFD_SETLKW, {l_type=F_WRLCK, l_whence=SEEK_SET, 
> l_start=0, ---> l_len=0 <---}
>
> 4. The question is that l_len was set '1', but why it is changed to 
> '0' when it is passed to fcntl64.
>
> Thanks,
> --Hongzhi
>
>> Thanks,
>> Florian
>>
>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about fcntl64
  2018-09-13  1:08   ` Hongzhi, Song
  2018-09-13  2:26     ` Hongzhi, Song
@ 2018-09-13  8:10     ` Florian Weimer
  2018-09-13 12:50       ` Adhemerval Zanella
  1 sibling, 1 reply; 6+ messages in thread
From: Florian Weimer @ 2018-09-13  8:10 UTC (permalink / raw)
  To: Hongzhi, Song, libc-help

On 09/13/2018 03:10 AM, Hongzhi, Song wrote:
> 1.part of source code: ltp/testcases/kernel/syscalls/fcntl/fcntl34.c
> ---
> struct flock64 lck = {
>            .l_whence = SEEK_SET,
>            .l_start  = 0,
> --->    .l_len    = 1, <---
> };
> lck.l_type = F_WRLCK
> SAFE_FCNTL(fd, F_OFD_SETLKW, &lck);
> ---
> 
> 2.SAFE_FCNTL is defined as a macro:
> ---
> #define SAFE_FCNTL(fd, cmd, ...)                            \
>     ---> ({int tst_ret_ = fcntl(fd, cmd, ##__VA_ARGS__);     \ <---
>        tst_ret_ == -1 ?                                  \
>         tst_brk(TBROK | TERRNO,                          \
>                  "fcntl(%i,%s,...) failed", fd, #cmd), 0 \
>       : tst_ret_;})
> ---

The expectation in glibc 2.28 is that you use fcntl64 with struct 
flock64, just as you would use struct stat64 with fstat64.  (Without 
-D_FILE_OFFSET_BITS=64, of course.)

Thanks,
Florian

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Question about fcntl64
  2018-09-13  8:10     ` Florian Weimer
@ 2018-09-13 12:50       ` Adhemerval Zanella
  0 siblings, 0 replies; 6+ messages in thread
From: Adhemerval Zanella @ 2018-09-13 12:50 UTC (permalink / raw)
  To: libc-help



On 13/09/2018 05:09, Florian Weimer wrote:
> On 09/13/2018 03:10 AM, Hongzhi, Song wrote:
>> 1.part of source code: ltp/testcases/kernel/syscalls/fcntl/fcntl34.c
>> ---
>> struct flock64 lck = {
>>            .l_whence = SEEK_SET,
>>            .l_start  = 0,
>> --->    .l_len    = 1, <---
>> };
>> lck.l_type = F_WRLCK
>> SAFE_FCNTL(fd, F_OFD_SETLKW, &lck);
>> ---
>>
>> 2.SAFE_FCNTL is defined as a macro:
>> ---
>> #define SAFE_FCNTL(fd, cmd, ...)                            \
>>     ---> ({int tst_ret_ = fcntl(fd, cmd, ##__VA_ARGS__);     \ <---
>>        tst_ret_ == -1 ?                                  \
>>         tst_brk(TBROK | TERRNO,                          \
>>                  "fcntl(%i,%s,...) failed", fd, #cmd), 0 \
>>       : tst_ret_;})
>> ---
> 
> The expectation in glibc 2.28 is that you use fcntl64 with struct flock64, just as you would use struct stat64 with fstat64.  (Without -D_FILE_OFFSET_BITS=64, of course.)
> 
> Thanks,
> Florian

To give more context to Florian's answer, it was indeed changed on 2.28
to fix BZ#20251 "Fix Linux fcntl OFD locks for non-LFS architectures"
(commit id 06ab719d30b01da401150068054d3b8ea93dd12f).

The issue was 32 bits programs without _FILE_OFFSET_BITS=64 or 
_LARGEFILE64_SOURCE interfaces, the struct flock members for OFD flags
were treated as 32-bits along fcntl64 syscall and it ended up passing
garbage to kernel.

We decided to explicit requite fcntl64 with flock64 mainly because 

  1. The fnctl variadic interface forces us to chose which combination 
     we support (because we can't guess which type in the incoming
     OFD lock structure and flock used is also used on old flock
     interface).

  1. when OFD was included in Linux it explicitly disabled 32-bits 
     offset support. So to actually use OFD locks you need to use
     fcntl64 syscalls.

  2. consistency with other LFS interfaces where *64 interfaces expects
     *64 inputs (pread and off_t for instance).

So the combination of OFD locks/fcntl and OFD locks64/fcntl64 will both
work (for locks/fcntl glibc will internally convert to locks64 and handle
overflow if the case), however flock64/fcntl or flock/fcntl64 are both not 
supported. 


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-09-13 12:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-12 14:20 Question about fcntl64 Hongzhi, Song
2018-09-12 17:32 ` Florian Weimer
2018-09-13  1:08   ` Hongzhi, Song
2018-09-13  2:26     ` Hongzhi, Song
2018-09-13  8:10     ` Florian Weimer
2018-09-13 12:50       ` Adhemerval Zanella

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).