[ft-lib/bcache] Make warn and raise variadic

This commit is contained in:
Joe Thornber 2017-11-24 11:06:45 +00:00
parent 09fa32a423
commit 80d8a5b684

View File

@ -13,21 +13,34 @@
#include <unistd.h>
#include <linux/fs.h>
#include <sys/ioctl.h>
#include <stdarg.h>
#include "list.h"
#include "bcache.h"
//----------------------------------------------------------------
static void warn(const char *msg)
static void warn(const char *fmt, ...)
{
fprintf(stderr, "%s\n", msg);
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, "\n");
}
// FIXME: raise a condition somehow?
static void raise(const char *msg)
static void raise(const char *fmt, ...)
{
warn(msg);
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fprintf(stderr, "\n");
exit(1);
}
@ -608,7 +621,7 @@ static struct block *new_block(struct bcache *cache, block_address index)
struct block *b;
b = alloc_block(cache);
while (!b && cache->nr_locked < cache->nr_cache_blocks) {
while (!b && (cache->nr_locked < cache->nr_cache_blocks)) {
b = find_unused_clean_block(cache);
if (!b) {
if (list_empty(&cache->io_pending))
@ -720,7 +733,7 @@ struct bcache *bcache_simple(const char *path, unsigned nr_cache_blocks)
void bcache_destroy(struct bcache *cache)
{
if (cache->nr_locked)
warn("some blocks are still locked\n");
warn("%u blocks are still locked\n", cache->nr_locked);
flush_cache(cache);
wait_all(cache);
@ -736,7 +749,9 @@ void bcache_destroy(struct bcache *cache)
static void check_index(struct bcache *cache, block_address index)
{
if (index >= cache->nr_data_blocks)
raise("block out of bounds");
raise("block out of bounds (%llu >= %llu)",
(unsigned long long) index,
(unsigned long long) cache->nr_data_blocks);
}
uint64_t get_nr_blocks(struct bcache *cache)