summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2015-03-23 17:32:48 -0700
committerKent Overstreet <kent.overstreet@gmail.com>2016-10-07 12:33:34 -0800
commitbf53814dd8a337df1bb6fab96946c14df81b372c (patch)
treec2beff2b47e5949c3c5f720827e53151167e8d21
parente7dace05f7e05bb16809c86b685b9d19807a1c01 (diff)
bcache: Move fifo stuff to fifo.h, rename some variables
Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
-rw-r--r--drivers/md/bcache/alloc.c4
-rw-r--r--drivers/md/bcache/bcache.h1
-rw-r--r--drivers/md/bcache/btree.c4
-rw-r--r--drivers/md/bcache/fifo.h126
-rw-r--r--drivers/md/bcache/gc.c4
-rw-r--r--drivers/md/bcache/journal_types.h2
-rw-r--r--drivers/md/bcache/util.h122
7 files changed, 135 insertions, 128 deletions
diff --git a/drivers/md/bcache/alloc.c b/drivers/md/bcache/alloc.c
index 9b8b068e3e56..d9bee1c25d4d 100644
--- a/drivers/md/bcache/alloc.c
+++ b/drivers/md/bcache/alloc.c
@@ -445,9 +445,9 @@ static void verify_not_on_freelist(struct cache *ca, size_t bucket)
BUG_ON(ca->prio_buckets[iter] == bucket);
for (j = 0; j < RESERVE_NR; j++)
- fifo_for_each(i, &ca->free[j], iter)
+ fifo_for_each_entry(i, &ca->free[j], iter)
BUG_ON(i == bucket);
- fifo_for_each(i, &ca->free_inc, iter)
+ fifo_for_each_entry(i, &ca->free_inc, iter)
BUG_ON(i == bucket);
}
}
diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h
index 896450f59497..8bc5be3124a6 100644
--- a/drivers/md/bcache/bcache.h
+++ b/drivers/md/bcache/bcache.h
@@ -193,6 +193,7 @@
#include <linux/workqueue.h>
#include "bset.h"
+#include "fifo.h"
#include "util.h"
#include "closure.h"
diff --git a/drivers/md/bcache/btree.c b/drivers/md/bcache/btree.c
index cc9eafb96637..2b1d4be19f23 100644
--- a/drivers/md/bcache/btree.c
+++ b/drivers/md/bcache/btree.c
@@ -740,8 +740,8 @@ void bch_btree_write_oldest(struct cache_set *c, u64 oldest_seq)
rcu_read_lock();
for_each_cached_btree(b, c, tbl, i, pos)
if (btree_current_write(b)->journal) {
- if (fifo_idx(&c->journal.pin,
- btree_current_write(b)->journal)
+ if (fifo_entry_idx(&c->journal.pin,
+ btree_current_write(b)->journal)
<= oldest_seq) {
six_lock_read(&b->lock);
if (btree_current_write(b)->journal) {
diff --git a/drivers/md/bcache/fifo.h b/drivers/md/bcache/fifo.h
new file mode 100644
index 000000000000..6ff02a09b197
--- /dev/null
+++ b/drivers/md/bcache/fifo.h
@@ -0,0 +1,126 @@
+#ifndef _BCACHE_FIFO_H
+#define _BCACHE_FIFO_H
+
+#define DECLARE_FIFO(type, name) \
+ struct { \
+ size_t front, back, size, mask; \
+ type *data; \
+ } name
+
+#define init_fifo(fifo, _size, gfp) \
+({ \
+ bool _ret = true; \
+ \
+ (fifo)->size = (_size); \
+ (fifo)->front = (fifo)->back = 0; \
+ (fifo)->data = NULL; \
+ \
+ if ((fifo)->size) { \
+ size_t _allocated_size, _bytes; \
+ \
+ _allocated_size = roundup_pow_of_two((fifo)->size + 1); \
+ _bytes = _allocated_size * sizeof(*(fifo)->data); \
+ \
+ (fifo)->mask = _allocated_size - 1; \
+ \
+ if (_bytes < KMALLOC_MAX_SIZE) \
+ (fifo)->data = kmalloc(_bytes, (gfp)); \
+ if ((!(fifo)->data) && ((gfp) & GFP_KERNEL)) \
+ (fifo)->data = vmalloc(_bytes); \
+ if ((!(fifo)->data)) \
+ _ret = false; \
+ } \
+ _ret; \
+})
+
+#define free_fifo(fifo) \
+do { \
+ kvfree((fifo)->data); \
+ (fifo)->data = NULL; \
+} while (0)
+
+#define fifo_swap(l, r) \
+do { \
+ swap((l)->front, (r)->front); \
+ swap((l)->back, (r)->back); \
+ swap((l)->size, (r)->size); \
+ swap((l)->mask, (r)->mask); \
+ swap((l)->data, (r)->data); \
+} while (0)
+
+#define fifo_move(dest, src) \
+do { \
+ typeof(*((dest)->data)) _t; \
+ while (!fifo_full(dest) && \
+ fifo_pop(src, _t)) \
+ fifo_push(dest, _t); \
+} while (0)
+
+#define fifo_used(fifo) (((fifo)->back - (fifo)->front) & (fifo)->mask)
+#define fifo_free(fifo) ((fifo)->size - fifo_used(fifo))
+
+#define fifo_empty(fifo) (!fifo_used(fifo))
+#define fifo_full(fifo) (!fifo_free(fifo))
+
+#define fifo_front(fifo) ((fifo)->data[(fifo)->front])
+#define fifo_back(fifo) \
+ ((fifo)->data[((fifo)->back - 1) & (fifo)->mask])
+
+#define fifo_entry_idx(fifo, p) (((p) - &fifo_front(fifo)) & (fifo)->mask)
+
+#define fifo_push_back(fifo, i) \
+({ \
+ bool _r = !fifo_full((fifo)); \
+ if (_r) { \
+ (fifo)->data[(fifo)->back++] = (i); \
+ (fifo)->back &= (fifo)->mask; \
+ } \
+ _r; \
+})
+
+#define fifo_pop_front(fifo, i) \
+({ \
+ bool _r = !fifo_empty((fifo)); \
+ if (_r) { \
+ (i) = (fifo)->data[(fifo)->front++]; \
+ (fifo)->front &= (fifo)->mask; \
+ } \
+ _r; \
+})
+
+#define fifo_push_front(fifo, i) \
+({ \
+ bool _r = !fifo_full((fifo)); \
+ if (_r) { \
+ --(fifo)->front; \
+ (fifo)->front &= (fifo)->mask; \
+ (fifo)->data[(fifo)->front] = (i); \
+ } \
+ _r; \
+})
+
+#define fifo_pop_back(fifo, i) \
+({ \
+ bool _r = !fifo_empty((fifo)); \
+ if (_r) { \
+ --(fifo)->back; \
+ (fifo)->back &= (fifo)->mask; \
+ (i) = (fifo)->data[(fifo)->back] \
+ } \
+ _r; \
+})
+
+#define fifo_push(fifo, i) fifo_push_back(fifo, (i))
+#define fifo_pop(fifo, i) fifo_pop_front(fifo, (i))
+
+#define fifo_peek_front(fifo) ((fifo)->data[(fifo)->front])
+#define fifo_peek(fifo) fifo_peek_front(fifo)
+
+#define fifo_for_each_entry(_entry, _fifo, _iter) \
+ for (_iter = (_fifo)->front; \
+ ((_iter != (_fifo)->back) && \
+ (_entry = (_fifo)->data[(_iter)], true)); \
+ _iter = ((_iter) + 1) & (_fifo)->mask)
+
+#endif /* _BCACHE_FIFO_H */
+
diff --git a/drivers/md/bcache/gc.c b/drivers/md/bcache/gc.c
index 341191297eb8..bcc6da832d35 100644
--- a/drivers/md/bcache/gc.c
+++ b/drivers/md/bcache/gc.c
@@ -213,11 +213,11 @@ static void bch_mark_allocator_buckets(struct cache_set *c)
for_each_cache(ca, c, ci) {
spin_lock(&ca->freelist_lock);
- fifo_for_each(i, &ca->free_inc, iter)
+ fifo_for_each_entry(i, &ca->free_inc, iter)
bch_mark_alloc_bucket(ca, &ca->buckets[i]);
for (j = 0; j < RESERVE_NR; j++)
- fifo_for_each(i, &ca->free[j], iter)
+ fifo_for_each_entry(i, &ca->free[j], iter)
bch_mark_alloc_bucket(ca, &ca->buckets[i]);
spin_unlock(&ca->freelist_lock);
diff --git a/drivers/md/bcache/journal_types.h b/drivers/md/bcache/journal_types.h
index 9be675f931c8..e7a425d4e1fe 100644
--- a/drivers/md/bcache/journal_types.h
+++ b/drivers/md/bcache/journal_types.h
@@ -1,6 +1,8 @@
#ifndef _BCACHE_JOURNAL_TYPES_H
#define _BCACHE_JOURNAL_TYPES_H
+#include "fifo.h"
+
struct journal_res;
/*
diff --git a/drivers/md/bcache/util.h b/drivers/md/bcache/util.h
index e014a8e406fc..3a829dc7b534 100644
--- a/drivers/md/bcache/util.h
+++ b/drivers/md/bcache/util.h
@@ -1,4 +1,3 @@
-
#ifndef _BCACHE_UTIL_H
#define _BCACHE_UTIL_H
@@ -139,127 +138,6 @@ do { \
heap_sift(heap, _i, cmp); \
} while (0)
-#define DECLARE_FIFO(type, name) \
- struct { \
- size_t front, back, size, mask; \
- type *data; \
- } name
-
-#define fifo_for_each(c, fifo, iter) \
- for (iter = (fifo)->front; \
- ((iter != (fifo)->back) && \
- (c = (fifo)->data[iter], 1)); \
- iter = (iter + 1) & (fifo)->mask)
-
-#define init_fifo(fifo, _size, gfp) \
-({ \
- bool _ret = true; \
- \
- (fifo)->size = (_size); \
- (fifo)->front = (fifo)->back = 0; \
- (fifo)->data = NULL; \
- \
- if ((fifo)->size) { \
- size_t _allocated_size, _bytes; \
- \
- _allocated_size = roundup_pow_of_two((fifo)->size + 1); \
- _bytes = _allocated_size * sizeof(*(fifo)->data); \
- \
- (fifo)->mask = _allocated_size - 1; \
- \
- if (_bytes < KMALLOC_MAX_SIZE) \
- (fifo)->data = kmalloc(_bytes, (gfp)); \
- if ((!(fifo)->data) && ((gfp) & GFP_KERNEL)) \
- (fifo)->data = vmalloc(_bytes); \
- if ((!(fifo)->data)) \
- _ret = false; \
- } \
- _ret; \
-})
-
-#define free_fifo(fifo) \
-do { \
- kvfree((fifo)->data); \
- (fifo)->data = NULL; \
-} while (0)
-
-#define fifo_used(fifo) (((fifo)->back - (fifo)->front) & (fifo)->mask)
-#define fifo_free(fifo) ((fifo)->size - fifo_used(fifo))
-
-#define fifo_empty(fifo) (!fifo_used(fifo))
-#define fifo_full(fifo) (!fifo_free(fifo))
-
-#define fifo_front(fifo) ((fifo)->data[(fifo)->front])
-#define fifo_back(fifo) \
- ((fifo)->data[((fifo)->back - 1) & (fifo)->mask])
-
-#define fifo_idx(fifo, p) (((p) - &fifo_front(fifo)) & (fifo)->mask)
-
-#define fifo_push_back(fifo, i) \
-({ \
- bool _r = !fifo_full((fifo)); \
- if (_r) { \
- (fifo)->data[(fifo)->back++] = (i); \
- (fifo)->back &= (fifo)->mask; \
- } \
- _r; \
-})
-
-#define fifo_pop_front(fifo, i) \
-({ \
- bool _r = !fifo_empty((fifo)); \
- if (_r) { \
- (i) = (fifo)->data[(fifo)->front++]; \
- (fifo)->front &= (fifo)->mask; \
- } \
- _r; \
-})
-
-#define fifo_push_front(fifo, i) \
-({ \
- bool _r = !fifo_full((fifo)); \
- if (_r) { \
- --(fifo)->front; \
- (fifo)->front &= (fifo)->mask; \
- (fifo)->data[(fifo)->front] = (i); \
- } \
- _r; \
-})
-
-#define fifo_pop_back(fifo, i) \
-({ \
- bool _r = !fifo_empty((fifo)); \
- if (_r) { \
- --(fifo)->back; \
- (fifo)->back &= (fifo)->mask; \
- (i) = (fifo)->data[(fifo)->back] \
- } \
- _r; \
-})
-
-#define fifo_push(fifo, i) fifo_push_back(fifo, (i))
-#define fifo_pop(fifo, i) fifo_pop_front(fifo, (i))
-
-#define fifo_peek_front(fifo) ((fifo)->data[(fifo)->front])
-#define fifo_peek(fifo) fifo_peek_front(fifo)
-
-#define fifo_swap(l, r) \
-do { \
- swap((l)->front, (r)->front); \
- swap((l)->back, (r)->back); \
- swap((l)->size, (r)->size); \
- swap((l)->mask, (r)->mask); \
- swap((l)->data, (r)->data); \
-} while (0)
-
-#define fifo_move(dest, src) \
-do { \
- typeof(*((dest)->data)) _t; \
- while (!fifo_full(dest) && \
- fifo_pop(src, _t)) \
- fifo_push(dest, _t); \
-} while (0)
-
/*
* Simple array based allocator - preallocates a number of elements and you can
* never allocate more than that, also has no locking.