[05/18] btrfs-progs: ctree.h: fix btrfs_inode_[amc]time
diff mbox

Message ID 1418244708-7087-6-git-send-email-mwilck@arcor.de
State Not Applicable
Headers show

Commit Message

mwilck@arcor.de Dec. 10, 2014, 8:51 p.m. UTC
From: Martin Wilck <mwilck@arcor.de>

make btrfs_inode_[amc]time work like the other btrfs_inode_xxx
functions. The current definition appears broken to me; it never
returns valid pointer unless an extent buffer address is added.

Signed-off-by: Martin Wilck <mwilck@arcor.de>
---
 ctree.h |   15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

Comments

Qu Wenruo Dec. 11, 2014, 7:59 a.m. UTC | #1
-------- Original Message --------
Subject: [PATCH 05/18] btrfs-progs: ctree.h: fix btrfs_inode_[amc]time
From: <mwilck@arcor.de>
To: <linux-btrfs@vger.kernel.org>
Date: 2014?12?11? 04:51
> From: Martin Wilck <mwilck@arcor.de>
>
> make btrfs_inode_[amc]time work like the other btrfs_inode_xxx
> functions. The current definition appears broken to me; it never
> returns valid pointer unless an extent buffer address is added.
The original method returns the ptr in the way just like 
btrfs_item_ptr(), which you should call
read_extent_buffer() to read them into a struct of btrfs_timespec.
That's the same in kernel codes.

If just want to read the timespec, you could try 
btrfs_stack_timespec_[n]spec() marco.

Thanks,
Qu
> Signed-off-by: Martin Wilck <mwilck@arcor.de>
> ---
>   ctree.h |   15 +++++++++------
>   1 files changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/ctree.h b/ctree.h
> index 89036de..1d5a5fc 100644
> --- a/ctree.h
> +++ b/ctree.h
> @@ -1414,27 +1414,30 @@ BTRFS_SETGET_STACK_FUNCS(stack_inode_flags,
>   			 struct btrfs_inode_item, flags, 64);
>   
>   static inline struct btrfs_timespec *
> -btrfs_inode_atime(struct btrfs_inode_item *inode_item)
> +btrfs_inode_atime(struct extent_buffer *eb,
> +		  struct btrfs_inode_item *inode_item)
>   {
>   	unsigned long ptr = (unsigned long)inode_item;
>   	ptr += offsetof(struct btrfs_inode_item, atime);
> -	return (struct btrfs_timespec *)ptr;
> +	return (struct btrfs_timespec *)(ptr + eb->data);
>   }
>   
>   static inline struct btrfs_timespec *
> -btrfs_inode_mtime(struct btrfs_inode_item *inode_item)
> +btrfs_inode_mtime(struct extent_buffer *eb,
> +		  struct btrfs_inode_item *inode_item)
>   {
>   	unsigned long ptr = (unsigned long)inode_item;
>   	ptr += offsetof(struct btrfs_inode_item, mtime);
> -	return (struct btrfs_timespec *)ptr;
> +	return (struct btrfs_timespec *)(ptr + eb->data);
>   }
>   
>   static inline struct btrfs_timespec *
> -btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
> +btrfs_inode_ctime(struct extent_buffer *eb,
> +		  struct btrfs_inode_item *inode_item)
>   {
>   	unsigned long ptr = (unsigned long)inode_item;
>   	ptr += offsetof(struct btrfs_inode_item, ctime);
> -	return (struct btrfs_timespec *)ptr;
> +	return (struct btrfs_timespec *)(ptr + eb->data);
>   }
>   
>   static inline struct btrfs_timespec *

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Qu Wenruo Dec. 11, 2014, 8:16 a.m. UTC | #2
-------- Original Message --------
Subject: Re: [PATCH 05/18] btrfs-progs: ctree.h: fix btrfs_inode_[amc]time
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: mwilck@arcor.de, linux-btrfs@vger.kernel.org
Date: 2014?12?11? 15:59
>
> -------- Original Message --------
> Subject: [PATCH 05/18] btrfs-progs: ctree.h: fix btrfs_inode_[amc]time
> From: <mwilck@arcor.de>
> To: <linux-btrfs@vger.kernel.org>
> Date: 2014?12?11? 04:51
>> From: Martin Wilck <mwilck@arcor.de>
>>
>> make btrfs_inode_[amc]time work like the other btrfs_inode_xxx
>> functions. The current definition appears broken to me; it never
>> returns valid pointer unless an extent buffer address is added.
> The original method returns the ptr in the way just like 
> btrfs_item_ptr(), which you should call
> read_extent_buffer() to read them into a struct of btrfs_timespec.
> That's the same in kernel codes.
>
> If just want to read the timespec, you could try 
> btrfs_stack_timespec_[n]spec() marco.
Oh, sorry, for your case, it is btrfs_timespec_[n]spec() marcro, not the 
stack ones.
And that one uses the timespec returned by btrfs_inode_[amc]time() marcor.

Thanks,
Qu
>
> Thanks,
> Qu
>> Signed-off-by: Martin Wilck <mwilck@arcor.de>
>> ---
>>   ctree.h |   15 +++++++++------
>>   1 files changed, 9 insertions(+), 6 deletions(-)
>>
>> diff --git a/ctree.h b/ctree.h
>> index 89036de..1d5a5fc 100644
>> --- a/ctree.h
>> +++ b/ctree.h
>> @@ -1414,27 +1414,30 @@ BTRFS_SETGET_STACK_FUNCS(stack_inode_flags,
>>                struct btrfs_inode_item, flags, 64);
>>     static inline struct btrfs_timespec *
>> -btrfs_inode_atime(struct btrfs_inode_item *inode_item)
>> +btrfs_inode_atime(struct extent_buffer *eb,
>> +          struct btrfs_inode_item *inode_item)
>>   {
>>       unsigned long ptr = (unsigned long)inode_item;
>>       ptr += offsetof(struct btrfs_inode_item, atime);
>> -    return (struct btrfs_timespec *)ptr;
>> +    return (struct btrfs_timespec *)(ptr + eb->data);
>>   }
>>     static inline struct btrfs_timespec *
>> -btrfs_inode_mtime(struct btrfs_inode_item *inode_item)
>> +btrfs_inode_mtime(struct extent_buffer *eb,
>> +          struct btrfs_inode_item *inode_item)
>>   {
>>       unsigned long ptr = (unsigned long)inode_item;
>>       ptr += offsetof(struct btrfs_inode_item, mtime);
>> -    return (struct btrfs_timespec *)ptr;
>> +    return (struct btrfs_timespec *)(ptr + eb->data);
>>   }
>>     static inline struct btrfs_timespec *
>> -btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
>> +btrfs_inode_ctime(struct extent_buffer *eb,
>> +          struct btrfs_inode_item *inode_item)
>>   {
>>       unsigned long ptr = (unsigned long)inode_item;
>>       ptr += offsetof(struct btrfs_inode_item, ctime);
>> -    return (struct btrfs_timespec *)ptr;
>> +    return (struct btrfs_timespec *)(ptr + eb->data);
>>   }
>>     static inline struct btrfs_timespec *
>

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/ctree.h b/ctree.h
index 89036de..1d5a5fc 100644
--- a/ctree.h
+++ b/ctree.h
@@ -1414,27 +1414,30 @@  BTRFS_SETGET_STACK_FUNCS(stack_inode_flags,
 			 struct btrfs_inode_item, flags, 64);
 
 static inline struct btrfs_timespec *
-btrfs_inode_atime(struct btrfs_inode_item *inode_item)
+btrfs_inode_atime(struct extent_buffer *eb,
+		  struct btrfs_inode_item *inode_item)
 {
 	unsigned long ptr = (unsigned long)inode_item;
 	ptr += offsetof(struct btrfs_inode_item, atime);
-	return (struct btrfs_timespec *)ptr;
+	return (struct btrfs_timespec *)(ptr + eb->data);
 }
 
 static inline struct btrfs_timespec *
-btrfs_inode_mtime(struct btrfs_inode_item *inode_item)
+btrfs_inode_mtime(struct extent_buffer *eb,
+		  struct btrfs_inode_item *inode_item)
 {
 	unsigned long ptr = (unsigned long)inode_item;
 	ptr += offsetof(struct btrfs_inode_item, mtime);
-	return (struct btrfs_timespec *)ptr;
+	return (struct btrfs_timespec *)(ptr + eb->data);
 }
 
 static inline struct btrfs_timespec *
-btrfs_inode_ctime(struct btrfs_inode_item *inode_item)
+btrfs_inode_ctime(struct extent_buffer *eb,
+		  struct btrfs_inode_item *inode_item)
 {
 	unsigned long ptr = (unsigned long)inode_item;
 	ptr += offsetof(struct btrfs_inode_item, ctime);
-	return (struct btrfs_timespec *)ptr;
+	return (struct btrfs_timespec *)(ptr + eb->data);
 }
 
 static inline struct btrfs_timespec *