Commit c0cef30e authored by Jeff Layton's avatar Jeff Layton Committed by Linus Torvalds

iversion: make inode_cmp_iversion{+raw} return bool instead of s64

As Linus points out:

    The inode_cmp_iversion{+raw}() functions are pure and utter crap.

    Why?

    You say that they return 0/negative/positive, but they do so in a
    completely broken manner. They return that ternary value as the
    sequence number difference in a 's64', which means that if you
    actually care about that ternary value, and do the *sane* thing that
    the kernel-doc of the function implies is the right thing, you would
    do

        int cmp = inode_cmp_iversion(inode, old);
        if (cmp < 0 ...

    and as a result you get code that looks sane, but that doesn't
    actually *WORK* right.

Since none of the callers actually care about the ternary value here,
convert the inode_cmp_iversion{+raw} functions to just return a boolean
value (false for matching, true for non-matching).

This matches the existing use of these functions just fine, and makes it
simple to convert them to return a ternary value in the future if we
grow callers that need it.

With this change we can also reimplement inode_cmp_iversion in a simpler
way using inode_peek_iversion.
Signed-off-by: default avatarJeff Layton <jlayton@redhat.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 3da90b15
...@@ -309,13 +309,13 @@ inode_query_iversion(struct inode *inode) ...@@ -309,13 +309,13 @@ inode_query_iversion(struct inode *inode)
* @inode: inode to check * @inode: inode to check
* @old: old value to check against its i_version * @old: old value to check against its i_version
* *
* Compare the current raw i_version counter with a previous one. Returns 0 if * Compare the current raw i_version counter with a previous one. Returns false
* they are the same or non-zero if they are different. * if they are the same or true if they are different.
*/ */
static inline s64 static inline bool
inode_cmp_iversion_raw(const struct inode *inode, u64 old) inode_cmp_iversion_raw(const struct inode *inode, u64 old)
{ {
return (s64)inode_peek_iversion_raw(inode) - (s64)old; return inode_peek_iversion_raw(inode) != old;
} }
/** /**
...@@ -323,19 +323,15 @@ inode_cmp_iversion_raw(const struct inode *inode, u64 old) ...@@ -323,19 +323,15 @@ inode_cmp_iversion_raw(const struct inode *inode, u64 old)
* @inode: inode to check * @inode: inode to check
* @old: old value to check against its i_version * @old: old value to check against its i_version
* *
* Compare an i_version counter with a previous one. Returns 0 if they are * Compare an i_version counter with a previous one. Returns false if they are
* the same, a positive value if the one in the inode appears newer than @old, * the same, and true if they are different.
* and a negative value if @old appears to be newer than the one in the
* inode.
* *
* Note that we don't need to set the QUERIED flag in this case, as the value * Note that we don't need to set the QUERIED flag in this case, as the value
* in the inode is not being recorded for later use. * in the inode is not being recorded for later use.
*/ */
static inline bool
static inline s64
inode_cmp_iversion(const struct inode *inode, u64 old) inode_cmp_iversion(const struct inode *inode, u64 old)
{ {
return (s64)(inode_peek_iversion_raw(inode) & ~I_VERSION_QUERIED) - return inode_peek_iversion(inode) != old;
(s64)(old << I_VERSION_QUERIED_SHIFT);
} }
#endif #endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment