summaryrefslogtreecommitdiff
path: root/make-bcache.c
diff options
context:
space:
mode:
authorKent Overstreet <koverstreet@google.com>2013-04-23 17:43:47 -0700
committerKent Overstreet <koverstreet@google.com>2013-04-23 17:43:47 -0700
commitebb76d0c4a92fdcd861a066b73536e68bb717c68 (patch)
tree2d8e2347f08849e1e46b8313cc4883adfef78160 /make-bcache.c
parent94755cc7572a9a6c368d3518a370b49c8913727a (diff)
Get blocksize from the devices if it's not specified
Diffstat (limited to 'make-bcache.c')
-rw-r--r--make-bcache.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/make-bcache.c b/make-bcache.c
index fbf547f..164d40c 100644
--- a/make-bcache.c
+++ b/make-bcache.c
@@ -21,6 +21,12 @@
#include "bcache.h"
+#define max(x, y) ({ \
+ typeof(x) _max1 = (x); \
+ typeof(y) _max2 = (y); \
+ (void) (&_max1 == &_max2); \
+ _max1 > _max2 ? _max1 : _max2; })
+
uint64_t getblocks(int fd)
{
uint64_t ret;
@@ -246,6 +252,19 @@ static void write_sb(char *dev, unsigned block_size, unsigned bucket_size,
close(fd);
}
+static unsigned get_blocksize(const char *path)
+{
+ struct stat statbuf;
+
+ if (stat(path, &statbuf)) {
+ fprintf(stderr, "Error statting %s: %s\n",
+ path, strerror(errno));
+ exit(EXIT_FAILURE);
+ }
+
+ return statbuf.st_blksize / 512;
+}
+
int main(int argc, char **argv)
{
int c, bdev = -1;
@@ -253,7 +272,7 @@ int main(int argc, char **argv)
char *cache_devices[argc];
char *backing_devices[argc];
- unsigned block_size = 1, bucket_size = 1024;
+ unsigned block_size = 0, bucket_size = 1024;
int writeback = 0, discard = 0;
unsigned cache_replacement_policy = 0;
uint64_t data_offset = BDEV_DATA_START_DEFAULT;
@@ -343,6 +362,16 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
+ if (!block_size) {
+ for (i = 0; i < ncache_devices; i++)
+ block_size = max(block_size,
+ get_blocksize(cache_devices[i]));
+
+ for (i = 0; i < nbacking_devices; i++)
+ block_size = max(block_size,
+ get_blocksize(backing_devices[i]));
+ }
+
for (i = 0; i < ncache_devices; i++)
write_sb(cache_devices[i], block_size, bucket_size,
writeback, discard, cache_replacement_policy,