Make detect zeros a runtime flag
This commit is contained in:
parent
9f9722bb26
commit
f53fb186b8
14
cbd/cbd.c
14
cbd/cbd.c
|
@ -139,6 +139,7 @@ usage(void)
|
||||||
" -s --size Logical size\n"
|
" -s --size Logical size\n"
|
||||||
" -z --compress-alg Compression algorithm [lz4]\n"
|
" -z --compress-alg Compression algorithm [lz4]\n"
|
||||||
" -Z --compress-level Compression level [1]\n"
|
" -Z --compress-level Compression level [1]\n"
|
||||||
|
" --detect-zeros Detect and free zero blocks at runtime\n"
|
||||||
" --profile Set -p -l -z -Z automatically\n"
|
" --profile Set -p -l -z -Z automatically\n"
|
||||||
" --full-init Fully init device (no lazy init)\n"
|
" --full-init Fully init device (no lazy init)\n"
|
||||||
" Note:\n"
|
" Note:\n"
|
||||||
|
@ -180,8 +181,9 @@ do_format(int argc, char** argv)
|
||||||
{ "size", required_argument, NULL, 's' },
|
{ "size", required_argument, NULL, 's' },
|
||||||
{ "compress-alg", required_argument, NULL, 'z' },
|
{ "compress-alg", required_argument, NULL, 'z' },
|
||||||
{ "compress-level", required_argument, NULL, 'Z' },
|
{ "compress-level", required_argument, NULL, 'Z' },
|
||||||
{ "profile", required_argument, NULL, 0x1 },
|
{ "detect-zeros", no_argument, NULL, 0x1 },
|
||||||
{ "full-init", no_argument, NULL, 0x2 },
|
{ "profile", required_argument, NULL, 0x2 },
|
||||||
|
{ "full-init", no_argument, NULL, 0x3 },
|
||||||
{ NULL, no_argument, NULL, 0 }
|
{ NULL, no_argument, NULL, 0 }
|
||||||
};
|
};
|
||||||
char opt;
|
char opt;
|
||||||
|
@ -191,6 +193,7 @@ do_format(int argc, char** argv)
|
||||||
uint pblksize = PAGE_SIZE;
|
uint pblksize = PAGE_SIZE;
|
||||||
uint lblksize = 16 * PAGE_SIZE;
|
uint lblksize = 16 * PAGE_SIZE;
|
||||||
uint pbatsize = 1;
|
uint pbatsize = 1;
|
||||||
|
uint16_t flags = 0;
|
||||||
enum cbd_alg alg = CBD_ALG_LZ4;
|
enum cbd_alg alg = CBD_ALG_LZ4;
|
||||||
uint level = 1;
|
uint level = 1;
|
||||||
bool full_init = false;
|
bool full_init = false;
|
||||||
|
@ -267,11 +270,14 @@ do_format(int argc, char** argv)
|
||||||
level = optval;
|
level = optval;
|
||||||
break;
|
break;
|
||||||
case 0x1:
|
case 0x1:
|
||||||
|
flags |= CBD_FLAG_DETECT_ZEROS;
|
||||||
|
break;
|
||||||
|
case 0x2:
|
||||||
if (!parse_profile(optarg, &pblksize, &lblksize, &alg, &level)) {
|
if (!parse_profile(optarg, &pblksize, &lblksize, &alg, &level)) {
|
||||||
error("Invalid profile \"%s\"\n", optarg);
|
error("Invalid profile \"%s\"\n", optarg);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 0x2:
|
case 0x3:
|
||||||
full_init = true;
|
full_init = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -295,7 +301,7 @@ do_format(int argc, char** argv)
|
||||||
}
|
}
|
||||||
dev = argv[optind++];
|
dev = argv[optind++];
|
||||||
|
|
||||||
cbd_format(dev, alg, level,
|
cbd_format(dev, flags, alg, level,
|
||||||
pshift, lshift, pbatshift, psize, lsize,
|
pshift, lshift, pbatshift, psize, lsize,
|
||||||
full_init);
|
full_init);
|
||||||
|
|
||||||
|
|
|
@ -30,10 +30,6 @@
|
||||||
|
|
||||||
#include <linux/dm-compress.h>
|
#include <linux/dm-compress.h>
|
||||||
|
|
||||||
// XXX: find a better name for this, something about storage vs. speed.
|
|
||||||
// XXX: should this be in cbd_params?
|
|
||||||
// #define CBD_DETECT_ZERO_BLOCKS
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* XXX
|
* XXX
|
||||||
* If we don't use a workqueue, pblk_read() stalls. Why?
|
* If we don't use a workqueue, pblk_read() stalls. Why?
|
||||||
|
|
|
@ -52,20 +52,19 @@ struct lbd {
|
||||||
static inline bool
|
static inline bool
|
||||||
lblk_is_zeros(struct cbd_params* params, struct lbd* lbd)
|
lblk_is_zeros(struct cbd_params* params, struct lbd* lbd)
|
||||||
{
|
{
|
||||||
#ifdef CBD_DETECT_ZERO_BLOCKS
|
|
||||||
u32 off;
|
u32 off;
|
||||||
u32 len = PBLK_SIZE * lblk_per_pblk(params);
|
u32 len = lblk_per_pblk(params) * pblk_size(params);
|
||||||
|
|
||||||
|
if (!(params->flags & CBD_FLAG_DETECT_ZEROS)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
for (off = 0; off < len; ++off) {
|
for (off = 0; off < len; ++off) {
|
||||||
if (lbd->lblk_buf[off]) {
|
if (lbd->buf[off]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
#else
|
|
||||||
return false;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct lblk_compress_state {
|
struct lblk_compress_state {
|
||||||
|
|
|
@ -66,6 +66,7 @@ typedef enum {
|
||||||
} tristate_t;
|
} tristate_t;
|
||||||
|
|
||||||
int cbd_format(const char* dev,
|
int cbd_format(const char* dev,
|
||||||
|
uint16_t flags,
|
||||||
enum cbd_alg alg, uint level,
|
enum cbd_alg alg, uint level,
|
||||||
uint8_t pshift, uint8_t lshift,
|
uint8_t pshift, uint8_t lshift,
|
||||||
uint8_t pbatshift,
|
uint8_t pbatshift,
|
||||||
|
|
|
@ -20,8 +20,9 @@ static const u8 CBD_MAGIC[] = { 'C', 'B', 'D', '\0' };
|
||||||
static const u16 CBD_VERSION_MAJOR = 1;
|
static const u16 CBD_VERSION_MAJOR = 1;
|
||||||
static const u16 CBD_VERSION_MINOR = 1;
|
static const u16 CBD_VERSION_MINOR = 1;
|
||||||
|
|
||||||
#define CBD_FLAG_DIRTY 0x01
|
#define CBD_FLAG_DIRTY 0x0001
|
||||||
#define CBD_FLAG_ERROR 0x02
|
#define CBD_FLAG_ERROR 0x0002
|
||||||
|
#define CBD_FLAG_DETECT_ZEROS 0x0100
|
||||||
|
|
||||||
enum cbd_alg {
|
enum cbd_alg {
|
||||||
CBD_ALG_NONE,
|
CBD_ALG_NONE,
|
||||||
|
|
|
@ -25,8 +25,12 @@ pblk_write(int fd, u32 pblk_size, u64 pblk, u32 count, const u8* data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define FORMAT_FLAGS_MASK \
|
||||||
|
(CBD_FLAG_DETECT_ZEROS)
|
||||||
|
|
||||||
int
|
int
|
||||||
cbd_format(const char* dev,
|
cbd_format(const char* dev,
|
||||||
|
uint16_t flags,
|
||||||
enum cbd_alg alg, uint level,
|
enum cbd_alg alg, uint level,
|
||||||
uint8_t pshift, uint8_t lshift,
|
uint8_t pshift, uint8_t lshift,
|
||||||
uint8_t pbatshift,
|
uint8_t pbatshift,
|
||||||
|
@ -45,6 +49,9 @@ cbd_format(const char* dev,
|
||||||
error("Cannot open device\n");
|
error("Cannot open device\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flags != (flags & FORMAT_FLAGS_MASK)) {
|
||||||
|
error("Bad flags 0x%04x\n", (unsigned int)flags);
|
||||||
|
}
|
||||||
if (alg <= CBD_ALG_NONE || alg >= CBD_ALG_MAX) {
|
if (alg <= CBD_ALG_NONE || alg >= CBD_ALG_MAX) {
|
||||||
error("Compression algorithm %d unknown\n", (int)alg);
|
error("Compression algorithm %d unknown\n", (int)alg);
|
||||||
}
|
}
|
||||||
|
@ -102,7 +109,7 @@ cbd_format(const char* dev,
|
||||||
memcpy(header.magic, CBD_MAGIC, sizeof(header.magic));
|
memcpy(header.magic, CBD_MAGIC, sizeof(header.magic));
|
||||||
header.version_major = CBD_VERSION_MAJOR;
|
header.version_major = CBD_VERSION_MAJOR;
|
||||||
header.version_minor = CBD_VERSION_MINOR;
|
header.version_minor = CBD_VERSION_MINOR;
|
||||||
header.params.flags = 0;
|
header.params.flags = flags;
|
||||||
header.params.compression = 0;
|
header.params.compression = 0;
|
||||||
cbd_compression_alg_put(&header.params, alg);
|
cbd_compression_alg_put(&header.params, alg);
|
||||||
cbd_compression_level_put(&header.params, level);
|
cbd_compression_level_put(&header.params, level);
|
||||||
|
|
Loading…
Reference in New Issue