mirror of
https://github.com/versity/scoutfs.git
synced 2026-04-20 21:40:29 +00:00
Add little cmp u64 helper
We have use of this little u64 comparison function in a few more places so let's make it a proper usable inline function in a header. Signed-off-by: Zach Brown <zab@versity.com>
This commit is contained in:
11
kmod/src/cmp.h
Normal file
11
kmod/src/cmp.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef _SCOUTFS_CMP_H_
|
||||
#define _SCOUTFS_CMP_H_
|
||||
|
||||
#include <linux/kernel.h>
|
||||
|
||||
static inline int scoutfs_cmp_u64s(u64 a, u64 b)
|
||||
{
|
||||
return a < b ? -1 : a > b ? 1 : 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "seg.h"
|
||||
#include "bio.h"
|
||||
#include "kvec.h"
|
||||
#include "cmp.h"
|
||||
#include "manifest.h"
|
||||
#include "alloc.h"
|
||||
|
||||
@@ -99,11 +100,6 @@ void scoutfs_seg_put(struct scoutfs_segment *seg)
|
||||
}
|
||||
}
|
||||
|
||||
static int cmp_u64s(u64 a, u64 b)
|
||||
{
|
||||
return a < b ? -1 : a > b ? 1 : 0;
|
||||
}
|
||||
|
||||
static struct scoutfs_segment *find_seg(struct rb_root *root, u64 segno)
|
||||
{
|
||||
struct rb_node *node = root->rb_node;
|
||||
@@ -115,7 +111,7 @@ static struct scoutfs_segment *find_seg(struct rb_root *root, u64 segno)
|
||||
parent = node;
|
||||
seg = container_of(node, struct scoutfs_segment, node);
|
||||
|
||||
cmp = cmp_u64s(segno, seg->segno);
|
||||
cmp = scoutfs_cmp_u64s(segno, seg->segno);
|
||||
if (cmp < 0)
|
||||
node = node->rb_left;
|
||||
else if (cmp > 0)
|
||||
@@ -146,7 +142,7 @@ static struct scoutfs_segment *replace_seg(struct rb_root *root,
|
||||
parent = *node;
|
||||
seg = container_of(*node, struct scoutfs_segment, node);
|
||||
|
||||
cmp = cmp_u64s(ins->segno, seg->segno);
|
||||
cmp = scoutfs_cmp_u64s(ins->segno, seg->segno);
|
||||
if (cmp < 0) {
|
||||
node = &(*node)->rb_left;
|
||||
} else if (cmp > 0) {
|
||||
|
||||
Reference in New Issue
Block a user