Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix option parsing so that passing --bucket_size after the device works

This makes supporting -U more annoying; dropping that for the moment,
unless someone complains
  • Loading branch information...
commit 2b8d6cc7d0770b9eec2448d41a5bc18aaf603cb5 1 parent 2f0e753
@g2p authored
Showing with 29 additions and 15 deletions.
  1. +29 −15 make-bcache.c
View
44 make-bcache.c
@@ -137,7 +137,7 @@ void usage()
" -b, --bucket bucket size\n"
" -w, --block block size (hard sector size of SSD, often 2k)\n"
" -o, --data-offset data offset in sectors\n"
- " -U UUID\n"
+// " -U UUID\n"
" --writeback enable writeback\n"
" --discard enable discards\n"
" --cache_replacement_policy=(lru|fifo)\n"
@@ -170,16 +170,11 @@ struct option opts[] = {
{ NULL, 0, NULL, 0 },
};
-void write_sb(char *dev, struct cache_sb *sb)
+void write_sb(char *dev, struct cache_sb *sb, bool bdev)
{
int fd;
char uuid[40], set_uuid[40];
- if (sb->version > BCACHE_SB_MAX_VERSION) {
- printf("Must specify one of -C or -B\n");
- usage();
- }
-
if (sb->bucket_size < sb->block_size) {
printf("Bucket size cannot be smaller than block size\n");
exit(EXIT_FAILURE);
@@ -192,7 +187,7 @@ void write_sb(char *dev, struct cache_sb *sb)
sb->flags = 0;
- if (SB_IS_BDEV(sb)) {
+ if (bdev) {
SET_BDEV_WRITEBACK(sb, writeback);
if (data_offset != BDEV_DATA_START_DEFAULT) {
@@ -203,6 +198,7 @@ void write_sb(char *dev, struct cache_sb *sb)
sb->version = BCACHE_SB_VERSION_BDEV;
}
} else {
+ sb->version = BCACHE_SB_VERSION_CDEV;
SET_CACHE_DISCARD(sb, discard);
SET_CACHE_REPLACEMENT(sb, cache_replacement_policy);
}
@@ -251,10 +247,13 @@ void write_sb(char *dev, struct cache_sb *sb)
int main(int argc, char **argv)
{
- bool written = false;
- int c;
+ int c, bdev = -1;
struct cache_sb *sb = calloc(1, SB_SIZE);
+ unsigned i, ncache_devices = 0, nbacking_devices = 0;
+ char *cache_devices[argc];
+ char *backing_devices[argc];
+
sb->version = -1;
sb->block_size = 1;
sb->bucket_size = 1024;
@@ -267,10 +266,10 @@ int main(int argc, char **argv)
opts, NULL)) != -1)
switch (c) {
case 'C':
- sb->version = 0;
+ bdev = 0;
break;
case 'B':
- sb->version = BCACHE_SB_VERSION_BDEV;
+ bdev = 1;
break;
case 'b':
sb->bucket_size = hatoi_validate(optarg, "bucket size");
@@ -278,12 +277,14 @@ int main(int argc, char **argv)
case 'w':
sb->block_size = hatoi_validate(optarg, "block size");
break;
+#if 0
case 'U':
if (uuid_parse(optarg, sb->uuid)) {
printf("Bad uuid\n");
exit(EXIT_FAILURE);
}
break;
+#endif
case 'p':
cache_replacement_policy = read_string_list(optarg,
cache_replacement_policies);
@@ -299,15 +300,28 @@ int main(int argc, char **argv)
usage();
break;
case 1:
- write_sb(optarg, sb);
- written = true;
+ if (bdev == -1) {
+ printf("Please specify -C or -B\n");
+ exit(EXIT_FAILURE);
+ }
+
+ if (bdev)
+ backing_devices[nbacking_devices++] = optarg;
+ else
+ cache_devices[ncache_devices++] = optarg;
break;
}
- if (!written) {
+ if (!ncache_devices && !nbacking_devices) {
printf("Please supply a device\n");
usage();
}
+ for (i = 0; i < ncache_devices; i++) {
+ write_sb(cache_devices[i], sb, false);
+ }
+ for (i = 0; i < nbacking_devices; i++) {
+ write_sb(backing_devices[i], sb, true);
+ }
free(sb);
return 0;
Please sign in to comment.
Something went wrong with that request. Please try again.