For the condition "file->f_mode", when it failed, it should return EACCES rather than EBADF.
Hi all,
When I wanted to do discard operations,but i set the openflag was O_RDONLY,it returned a EBADF rather than EACCES or EPERM.
I searched the code and found:
Quoted 6 lines
case BLKDISCARD:
case BLKSECDISCARD: { uint64_t range[2]; if (!(mode & FMODE_WRITE)) return -EBADF;
Initial i thought there was error.But i searched all code of kernel and found some places like this.
The description of EBADF is "Bad file numbe". There are some places where returned EBADF like,
Quoted 2 lines
if (!f.file)
return -EBADF;
So i think for checking file->f_mode when failed, it should return EACCESS.
Jianpeng Ma
Thanks!
Quoted 9 lines · majianpeng
Hi all,
When I wanted to do discard operations,but i set the openflag was O_RDONLY,it returned a EBADF rather than EACCES or EPERM.
I searched the code and found:Quoted 6 lines
case BLKDISCARD:
case BLKSECDISCARD: { uint64_t range[2]; if (!(mode & FMODE_WRITE)) return -EBADF;
Quoted 7 lines
Initial i thought there was error.But i searched all code of kernel and found some places like this.
The description of EBADF is "Bad file numbe". There are some places where returned EBADF like,
Quoted 2 lines
if (!f.file)
return -EBADF;So i think for checking
file->f_modewhen failed, it should return EACCESS.
But that would break the ABI at this point. I agree with you, though, EBADF is not the right error for this case.
Signature · 1 line
Jens Axboe
Quoted 12 lines · majianpeng
Quoted 11 lines
Hi all,
When I wanted to do discard operations,but i set the openflag was O_RDONLY,it returned a EBADF rather than EACCES or EPERM.
I searched the code and found:Quoted 6 lines
case BLKDISCARD:
case BLKSECDISCARD: { uint64_t range[2]; if (!(mode & FMODE_WRITE)) return -EBADF;Initial i thought there was error.But i searched all code of kernel and found some places like this.
Quoted 12 lines
Quoted 5 lines
The description of EBADF is "Bad file numbe". There are some places where returned EBADF like,
Quoted 2 lines
if (!f.file)
return -EBADF;So i think for checking
file->f_modewhen failed, it should return EACCESS.But that would break the ABI at this point. I agree with you, though, EBADF is not the right error for this case.
Signature · 1 line
Jens Axboe
Sorry, can you explain in detail? Why can it break the ABI ?
Thanks!
Jianpeng Ma
Quoted 18 lines · majianpeng
Quoted 18 lines · majianpeng
Quoted 16 lines
Hi all,
When I wanted to do discard operations,but i set the openflag was O_RDONLY,it returned a EBADF rather than EACCES or EPERM.
I searched the code and found:Quoted 6 lines
case BLKDISCARD:
case BLKSECDISCARD: { uint64_t range[2]; if (!(mode & FMODE_WRITE)) return -EBADF;Initial i thought there was error.But i searched all code of kernel and found some places like this.
The description of EBADF is "Bad file numbe". There are some places where returned EBADF like,
Quoted 2 lines
if (!f.file)
return -EBADF;So i think for checking
file->f_modewhen failed, it should return EACCESS.
Quoted 7 lines
Quoted 6 lines
But that would break the ABI at this point. I agree with you, though, EBADF is not the right error for this case.
Signature · 1 line
Jens AxboeSorry, can you explain in detail? Why can it break the ABI ?
Applications already depending on EBADF being returned for attempt to discard on a file descriptor not opened for write. Granted it's a slim possiblity, but it exists.
Signature · 1 line
Jens Axboe