Skip to contentSkip to conversation

btrfs-progs: fix btrfs quota rescan failed on PPC64 arch

PATCH In review [email protected] 4 participants 6 messages Apr 20, 2015 – Apr 24, 2015 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs-progs: fix btrfs quota rescan failed on PPC64 arch

From: George Wang <[email protected]>

PPC64 arch use such following IOC values "

\#define _IOC_NONE       1U
\#define _IOC_READ       2U
\#define _IOC_WRITE      4U
" comparing to the default IOC values "
\#define _IOC_NONE       0U
\#define _IOC_READ       2U
\#define _IOC_WRITE      1U"

This means the value "_IOW*" will be negative when we store it in the int variables. Such as the "BTRFS_IOC_QGROUP_CREATE", it will be "0x4010942e" on X86_64, but "0x8010942e" on PPC64.
Notice that the IOC values are the "unsigned long" type, so we use the "unsigned long" to store it, and this can insure the comparison between the variable and BTRFS_IOC_* valid.

---
 cmds-quota.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
cmds-quota.c +1 -1
index 89cc89c..f6a1cfa 100644
@@ -109,7 +109,7 @@ static int cmd_quota_rescan(int argc, char **argv)
 	int e;
 	char *path = NULL;
 	struct btrfs_ioctl_quota_rescan_args args;
-	int ioctlnum = BTRFS_IOC_QUOTA_RESCAN;
+	unsigned long ioctlnum = BTRFS_IOC_QUOTA_RESCAN;
 	DIR *dirstream = NULL;
 	int wait_for_completion = 0;
 
Signature · 1 line
1.9.3
#1 lore raw
Quoted 11 lines · On 4/20/15 12:33 AM, [email protected] wrote:

From: George Wang <[email protected]>

PPC64 arch use such following IOC values "

\#define _IOC_NONE       1U
\#define _IOC_READ       2U
\#define _IOC_WRITE      4U
" comparing to the default IOC values "
\#define _IOC_NONE       0U
\#define _IOC_READ       2U
\#define _IOC_WRITE      1U"
Quoted 6 lines

This means the value "_IOW*" will be negative when we store it in the int variables. Such as the "BTRFS_IOC_QGROUP_CREATE", it will be "0x4010942e" on X86_64, but "0x8010942e" on PPC64.
Notice that the IOC values are the "unsigned long" type, so we use the "unsigned long" to store it, and this can insure the comparison between the variable and BTRFS_IOC_* valid.

Looks good - very strange that the manpage states that the interface takes an int. :(

But - an "unsigned int" would be enough, right? I don't think it needs to be an unsigned long. *shrug*

Thanks,
-Eric

Quoted 19 lines
---
 cmds-quota.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
cmds-quota.c +1 -1
index 89cc89c..f6a1cfa 100644
@@ -109,7 +109,7 @@ static int cmd_quota_rescan(int argc, char **argv)
 	int e;
 	char *path = NULL;
 	struct btrfs_ioctl_quota_rescan_args args;
-	int ioctlnum = BTRFS_IOC_QUOTA_RESCAN;
+	unsigned long ioctlnum = BTRFS_IOC_QUOTA_RESCAN;
 	DIR *dirstream = NULL;
 	int wait_for_completion = 0;
 
author
#2 lore raw

Thanks for review.

Quoted 2 lines · Eric Sandeen
Quoted 1 line · On 4/20/15 12:33 AM, [email protected] wrote:

From: George Wang <[email protected]>

<snip>

Quoted 9 lines
Quoted 6 lines

This means the value "_IOW*" will be negative when we store it in the int variables. Such as the "BTRFS_IOC_QGROUP_CREATE", it will be "0x4010942e" on X86_64, but "0x8010942e" on PPC64.
Notice that the IOC values are the "unsigned long" type, so we use the "unsigned long" to store it, and this can insure the comparison between the variable and BTRFS_IOC_* valid.

Looks good - very strange that the manpage states that the interface takes an int. :(

I think maybe the manpage of ioctl is stale. But int can also work except for comparison.
And fortunately the kernel interface is unsigned int, such as btrfs:

5217 long btrfs_ioctl(struct file *file, unsigned int
5218 cmd, unsigned long arg)

Quoted 3 lines

But - an "unsigned int" would be enough, right? I don't think it needs to be an unsigned long. *shrug*

unsigned int will be OK. But the btrfs-progs is user space, so the ioctl I think it should be
consistent with the glibc:
/usr/include/sys/ioctl.h:extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;
unsigned long int is same with unsigned long. So maybe the unsigned long will be better?

Thanks,
George

#3 lore raw
Quoted 24 lines · 王旭
Quoted 2 lines · On 4/20/15 12:33 AM, [email protected] wrote:
Quoted 1 line

From: George Wang <[email protected]>

<snip>

Quoted 9 lines
Quoted 6 lines

This means the value "_IOW*" will be negative when we store it in the int variables. Such as the "BTRFS_IOC_QGROUP_CREATE", it will be "0x4010942e" on X86_64, but "0x8010942e" on PPC64.
Notice that the IOC values are the "unsigned long" type, so we use the "unsigned long" to store it, and this can insure the comparison between the variable and BTRFS_IOC_* valid.

Looks good - very strange that the manpage states that the interface takes an int. :(

I think maybe the manpage of ioctl is stale. But int can also work except for comparison.
And fortunately the kernel interface is unsigned int, such as btrfs:

5217 long btrfs_ioctl(struct file *file, unsigned int
5218 cmd, unsigned long arg)

Quoted 3 lines

But - an "unsigned int" would be enough, right? I don't think it needs to be an unsigned long. *shrug*

Quoted 7 lines

unsigned int will be OK. But the btrfs-progs is user space, so the ioctl I think it should be
consistent with the glibc:
/usr/include/sys/ioctl.h:extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;
unsigned long int is same with unsigned long. So maybe the unsigned long will be better?

I think we should stick to the glibc interface as it's the closest one, although kernel uses usigned int in the end. Thanks.

Tested-by on v1 1/1
#4 lore raw
In reply to [email protected]
Quoted 11 lines · On Monday 20 Apr 2015 13:33:16 [email protected] wrote:

From: George Wang <[email protected]>

PPC64 arch use such following IOC values "

\#define _IOC_NONE       1U
\#define _IOC_READ       2U
\#define _IOC_WRITE      4U
" comparing to the default IOC values "
\#define _IOC_NONE       0U
\#define _IOC_READ       2U
\#define _IOC_WRITE      1U"
Quoted 8 lines

This means the value "_IOW*" will be negative when we store it in the int variables. Such as the "BTRFS_IOC_QGROUP_CREATE", it will be "0x4010942e" on X86_64, but "0x8010942e" on PPC64.
Notice that the IOC values are the "unsigned long" type, so we use the "unsigned long" to store it, and this can insure the comparison between the variable and BTRFS_IOC_* valid.

Signature · 1 line
chandan
#5 lore raw
Quoted 19 lines · Chandan Rajendra
Quoted 18 lines · On Monday 20 Apr 2015 13:33:16 [email protected] wrote:

From: George Wang <[email protected]>

PPC64 arch use such following IOC values "

\#define _IOC_NONE       1U
\#define _IOC_READ       2U
\#define _IOC_WRITE      4U
" comparing to the default IOC values "
\#define _IOC_NONE       0U
\#define _IOC_READ       2U
\#define _IOC_WRITE      1U"

This means the value "_IOW*" will be negative when we store it in the int variables. Such as the "BTRFS_IOC_QGROUP_CREATE", it will be "0x4010942e" on X86_64, but "0x8010942e" on PPC64.
Notice that the IOC values are the "unsigned long" type, so we use the "unsigned long" to store it, and this can insure the comparison between the variable and BTRFS_IOC_* valid.

Quoted 3 lines
Quoted 1 line

Thanks for testing, commit updated.