mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-03-10 00:00:04 +03:00
Merge branch 'master' of ssh://gits.daterainc.com:2984/project/2013.KERNEL/bcache-tools
Issue DAT-
This commit is contained in:
commit
7243fbd22d
6
bcache.c
6
bcache.c
@ -452,7 +452,7 @@ static void do_write_sb(int fd, struct cache_sb *sb)
|
||||
}
|
||||
|
||||
void write_backingdev_sb(int fd, unsigned block_size, unsigned *bucket_sizes,
|
||||
bool writeback, uint64_t data_offset,
|
||||
unsigned mode, uint64_t data_offset,
|
||||
const char *label,
|
||||
uuid_le set_uuid)
|
||||
{
|
||||
@ -474,9 +474,7 @@ void write_backingdev_sb(int fd, unsigned block_size, unsigned *bucket_sizes,
|
||||
if (label)
|
||||
memcpy(sb.label, label, SB_LABEL_SIZE);
|
||||
|
||||
SET_BDEV_CACHE_MODE(&sb, writeback
|
||||
? CACHE_MODE_WRITEBACK
|
||||
: CACHE_MODE_WRITETHROUGH);
|
||||
SET_BDEV_CACHE_MODE(&sb, mode);
|
||||
|
||||
if (data_offset != BDEV_DATA_START_DEFAULT) {
|
||||
sb.version = BCACHE_SB_VERSION_BDEV_WITH_OFFSET;
|
||||
|
4
bcache.h
4
bcache.h
@ -61,8 +61,8 @@ uint64_t bch_checksum(unsigned, const void *, size_t);
|
||||
uint64_t getblocks(int);
|
||||
uint64_t hatoi(const char *);
|
||||
unsigned hatoi_validate(const char *, const char *);
|
||||
void write_backingdev_sb(int, unsigned, unsigned *, bool, uint64_t,
|
||||
const char *, uuid_le);
|
||||
void write_backingdev_sb(int, unsigned, unsigned *, unsigned, uint64_t,
|
||||
const char *, uuid_le);
|
||||
int dev_open(const char *, bool);
|
||||
void write_cache_sbs(int *, struct cache_sb *, unsigned, unsigned *, int);
|
||||
void next_cache_device(struct cache_sb *, unsigned, int, unsigned, bool);
|
||||
|
41
bcacheadm.c
41
bcacheadm.c
@ -41,14 +41,16 @@ int bdev = -1;
|
||||
int devs = 0;
|
||||
char *cache_devices[MAX_DEVS];
|
||||
int tier_mapping[MAX_DEVS];
|
||||
unsigned replacement_policy_mapping[MAX_DEVS];
|
||||
char *backing_devices[MAX_DEVS];
|
||||
char *backing_dev_labels[MAX_DEVS];
|
||||
size_t i, nr_backing_devices = 0, nr_cache_devices = 0;
|
||||
unsigned block_size = 0;
|
||||
unsigned bucket_sizes[MAX_DEVS];
|
||||
int num_bucket_sizes = 0;
|
||||
int writeback = 0, discard = 0, wipe_bcache = 0;
|
||||
unsigned replication_set = 0, replacement_policy = 0;
|
||||
int writeback = 0, writearound = 0, discard = 0, wipe_bcache = 0;
|
||||
unsigned replication_set = 0;
|
||||
char *replacement_policy = 0;
|
||||
uint64_t data_offset = BDEV_DATA_START_DEFAULT;
|
||||
char *label = NULL;
|
||||
struct cache_sb *cache_set_sb = NULL;
|
||||
@ -117,7 +119,26 @@ static int set_cache(NihOption *option, const char *arg)
|
||||
if(ntier == 0 || ntier == 1)
|
||||
tier_mapping[nr_cache_devices] = ntier;
|
||||
else
|
||||
printf("Invalid tier\n");
|
||||
printf("Invalid tier %s\n", tier);
|
||||
}
|
||||
|
||||
if (!replacement_policy)
|
||||
replacement_policy_mapping[nr_cache_devices] = 0;
|
||||
else {
|
||||
int i = 0;
|
||||
|
||||
while (replacement_policies[i] != NULL) {
|
||||
if (!strcmp(replacement_policy,
|
||||
replacement_policies[i])) {
|
||||
replacement_policy_mapping[nr_cache_devices] = i;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (replacement_policies[i] == NULL)
|
||||
printf("Invalid replacement policy: %s\n",
|
||||
replacement_policy);
|
||||
}
|
||||
|
||||
devs++;
|
||||
@ -183,6 +204,7 @@ static NihOption make_bcache_options[] = {
|
||||
{0, "wipe-bcache", N_("destroy existing bcache data if present"), NULL, NULL, &wipe_bcache, NULL},
|
||||
{0, "discard", N_("enable discards"), NULL, NULL, &discard, NULL},
|
||||
{0, "writeback", N_("enable writeback"), NULL, NULL, &writeback, NULL},
|
||||
{0, "writearound", N_("enable writearound"), NULL, NULL, &writearound, NULL},
|
||||
|
||||
NIH_OPTION_LAST
|
||||
};
|
||||
@ -270,6 +292,8 @@ int make_bcache(NihCommand *command, char *const *args)
|
||||
|
||||
int backing_dev_fd[devs];
|
||||
|
||||
unsigned cache_mode;
|
||||
|
||||
cache_set_sb = calloc(1, sizeof(*cache_set_sb) +
|
||||
sizeof(struct cache_member) * devs);
|
||||
|
||||
@ -322,7 +346,7 @@ int make_bcache(NihCommand *command, char *const *args)
|
||||
next_cache_device(cache_set_sb,
|
||||
replication_set,
|
||||
tier_mapping[i],
|
||||
replacement_policy,
|
||||
replacement_policy_mapping[i],
|
||||
discard);
|
||||
|
||||
if (!cache_set_sb->nr_in_set && !nr_backing_devices) {
|
||||
@ -359,10 +383,17 @@ int make_bcache(NihCommand *command, char *const *args)
|
||||
write_cache_sbs(cache_dev_fd, cache_set_sb, block_size,
|
||||
bucket_sizes, num_bucket_sizes);
|
||||
|
||||
if (writeback)
|
||||
cache_mode = CACHE_MODE_WRITEBACK;
|
||||
else if (writearound)
|
||||
cache_mode = CACHE_MODE_WRITEAROUND;
|
||||
else
|
||||
cache_mode = CACHE_MODE_WRITETHROUGH;
|
||||
|
||||
for (i = 0; i < nr_backing_devices; i++)
|
||||
write_backingdev_sb(backing_dev_fd[i],
|
||||
block_size, bucket_sizes,
|
||||
writeback, data_offset,
|
||||
cache_mode, data_offset,
|
||||
backing_dev_labels[i],
|
||||
cache_set_sb->set_uuid);
|
||||
|
||||
|
@ -247,7 +247,10 @@ int main(int argc, char **argv)
|
||||
for (i = 0; i < nr_backing_devices; i++)
|
||||
write_backingdev_sb(backing_dev_fd[i],
|
||||
block_size, bucket_sizes,
|
||||
writeback, data_offset,
|
||||
writeback
|
||||
? CACHE_MODE_WRITEBACK
|
||||
: CACHE_MODE_WRITETHROUGH,
|
||||
data_offset,
|
||||
backing_dev_labels[i],
|
||||
cache_set_sb->set_uuid);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user