mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-23 00:00:02 +03:00
Get blocksize from the devices if it's not specified
This commit is contained in:
parent
94755cc757
commit
ebb76d0c4a
@ -21,6 +21,12 @@
|
|||||||
|
|
||||||
#include "bcache.h"
|
#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 getblocks(int fd)
|
||||||
{
|
{
|
||||||
uint64_t ret;
|
uint64_t ret;
|
||||||
@ -246,6 +252,19 @@ static void write_sb(char *dev, unsigned block_size, unsigned bucket_size,
|
|||||||
close(fd);
|
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 main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int c, bdev = -1;
|
int c, bdev = -1;
|
||||||
@ -253,7 +272,7 @@ int main(int argc, char **argv)
|
|||||||
char *cache_devices[argc];
|
char *cache_devices[argc];
|
||||||
char *backing_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;
|
int writeback = 0, discard = 0;
|
||||||
unsigned cache_replacement_policy = 0;
|
unsigned cache_replacement_policy = 0;
|
||||||
uint64_t data_offset = BDEV_DATA_START_DEFAULT;
|
uint64_t data_offset = BDEV_DATA_START_DEFAULT;
|
||||||
@ -343,6 +362,16 @@ int main(int argc, char **argv)
|
|||||||
exit(EXIT_FAILURE);
|
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++)
|
for (i = 0; i < ncache_devices; i++)
|
||||||
write_sb(cache_devices[i], block_size, bucket_size,
|
write_sb(cache_devices[i], block_size, bucket_size,
|
||||||
writeback, discard, cache_replacement_policy,
|
writeback, discard, cache_replacement_policy,
|
||||||
|
Loading…
Reference in New Issue
Block a user