Don't overwrite priorities that aren't there on a backing device

This commit is contained in:
Kent Overstreet 2011-05-24 14:12:00 -07:00
parent eb9054a32e
commit 9e6daaffa7
2 changed files with 12 additions and 6 deletions

View File

@ -35,6 +35,8 @@ struct cache_sb {
uint16_t nr_in_set; uint16_t nr_in_set;
uint16_t nr_this_dev; uint16_t nr_this_dev;
uint16_t _pad[1]; uint16_t _pad[1];
#define SB_LABEL_SIZE 32
uint8_t label[SB_LABEL_SIZE];
}; };
struct bucket_disk { struct bucket_disk {

View File

@ -63,6 +63,8 @@ void usage()
" -C Format a cache device\n" " -C Format a cache device\n"
" -B Format a backing device\n" " -B Format a backing device\n"
" -b bucket size\n" " -b bucket size\n"
" -w block size (hard sector size of SSD, often 2k)\n"
" -j journal size, in buckets\n"
" -U UUID\n"); " -U UUID\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -113,7 +115,7 @@ int main(int argc, char **argv)
if (cache == backingdev) { if (cache == backingdev) {
printf("Must specify one of -C or -B\n"); printf("Must specify one of -C or -B\n");
exit(EXIT_FAILURE); usage();
} }
if (argc <= optind) { if (argc <= optind) {
@ -159,11 +161,13 @@ int main(int argc, char **argv)
sb.nbuckets, sb.nbuckets,
uuid, set_uuid); uuid, set_uuid);
/* Zero out priorities */ if (!backingdev) {
lseek(fd, 4096, SEEK_SET); /* Zero out priorities */
for (i = 8; i < sb.first_bucket * sb.bucket_size; i++) lseek(fd, 4096, SEEK_SET);
if (write(fd, zero, 512) != 512) for (i = 8; i < sb.first_bucket * sb.bucket_size; i++)
goto err; if (write(fd, zero, 512) != 512)
goto err;
}
if (pwrite(fd, &sb, sizeof(sb), 4096) != sizeof(sb)) if (pwrite(fd, &sb, sizeof(sb), 4096) != sizeof(sb))
goto err; goto err;