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:
Zach Brown
2016-12-29 16:01:51 -08:00
parent b8d7e04262
commit 3dfe8e10df
2 changed files with 14 additions and 7 deletions

11
kmod/src/cmp.h Normal file
View 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

View File

@@ -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) {