diff options
author | Jeff Layton <jlayton@redhat.com> | 2018-01-30 15:32:21 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2018-01-31 11:43:35 -0500 |
commit | c0cef30e4ff0dc025f4a1660b8f0ba43ed58426e (patch) | |
tree | 8be4d90a4eb4f64bf0569e7b9e9bf88112722776 | |
parent | 3da90b159b146672f830bcd2489dd3a1f4e9e089 (diff) |
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: Jeff Layton <jlayton@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/iversion.h | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/include/linux/iversion.h b/include/linux/iversion.h index 858463fca249..3d2fd06495ec 100644 --- a/include/linux/iversion.h +++ b/include/linux/iversion.h | |||
@@ -309,13 +309,13 @@ inode_query_iversion(struct inode *inode) | |||
309 | * @inode: inode to check | 309 | * @inode: inode to check |
310 | * @old: old value to check against its i_version | 310 | * @old: old value to check against its i_version |
311 | * | 311 | * |
312 | * Compare the current raw i_version counter with a previous one. Returns 0 if | 312 | * Compare the current raw i_version counter with a previous one. Returns false |
313 | * they are the same or non-zero if they are different. | 313 | * if they are the same or true if they are different. |
314 | */ | 314 | */ |
315 | static inline s64 | 315 | static inline bool |
316 | inode_cmp_iversion_raw(const struct inode *inode, u64 old) | 316 | inode_cmp_iversion_raw(const struct inode *inode, u64 old) |
317 | { | 317 | { |
318 | return (s64)inode_peek_iversion_raw(inode) - (s64)old; | 318 | return inode_peek_iversion_raw(inode) != old; |
319 | } | 319 | } |
320 | 320 | ||
321 | /** | 321 | /** |
@@ -323,19 +323,15 @@ inode_cmp_iversion_raw(const struct inode *inode, u64 old) | |||
323 | * @inode: inode to check | 323 | * @inode: inode to check |
324 | * @old: old value to check against its i_version | 324 | * @old: old value to check against its i_version |
325 | * | 325 | * |
326 | * Compare an i_version counter with a previous one. Returns 0 if they are | 326 | * Compare an i_version counter with a previous one. Returns false if they are |
327 | * the same, a positive value if the one in the inode appears newer than @old, | 327 | * the same, and true if they are different. |
328 | * and a negative value if @old appears to be newer than the one in the | ||
329 | * inode. | ||
330 | * | 328 | * |
331 | * Note that we don't need to set the QUERIED flag in this case, as the value | 329 | * Note that we don't need to set the QUERIED flag in this case, as the value |
332 | * in the inode is not being recorded for later use. | 330 | * in the inode is not being recorded for later use. |
333 | */ | 331 | */ |
334 | 332 | static inline bool | |
335 | static inline s64 | ||
336 | inode_cmp_iversion(const struct inode *inode, u64 old) | 333 | inode_cmp_iversion(const struct inode *inode, u64 old) |
337 | { | 334 | { |
338 | return (s64)(inode_peek_iversion_raw(inode) & ~I_VERSION_QUERIED) - | 335 | return inode_peek_iversion(inode) != old; |
339 | (s64)(old << I_VERSION_QUERIED_SHIFT); | ||
340 | } | 336 | } |
341 | #endif | 337 | #endif |