On 2018/7/17 8:20 PM, shenghui wrote: > > When run make-bcache with --wipe-bcache on a bcache device, > write_sb() would fall through to blkid probe before write cache_sb. > If libblkid is not up-to-date, e.g version provided by Linux distribution, > it will not recognize bcache magic, and will complain > " > Device XX already has a non-bcache superblock, remove it using wipefs and wipefs -a > " > even if it's a bcache device. This should be avoided. > > > Test steps before the change: > --------- > 1) ./make-bcache -C /dev/sda8 > 2) ./make-bcache -B --wipe-bcache /dev/sda8 > Device /dev/sda8 already has a non-bcache superblock, remove it using wipefs and wipefs -a > > > Test steps after the change: > --------- > 1) ./make-bcache -C /dev/sda8 > 2) ./make-bcache -B --wipe-bcache /dev/sda8 > UUID: c43ac77e-1821-4445-9d44-217676662a97 > Set UUID: 398f284e-dbf2-4d53-b602-3c2b8de31b0c > version: 1 > block_size: 1 > data_offset: 16 > 3) mkfs.xfs -f /dev/sda8 > 4) ./make-bcache -C --wipe-bcache /dev/sda8 > Device /dev/sda8 already has a non-bcache superblock, remove it using wipefs and wipefs -a > 5) wipefs -a /dev/sda8 > /dev/sda8: 4 bytes were erased at offset 0x00000000 (xfs): 58 46 53 42 > 6) ./make-bcache -C /dev/sda8 > UUID: 398413e6-27f3-48f6-bbad-07a1f8550e25 > Set UUID: 347612c8-c2e8-4794-bfd5-9d039a0bd139 > version: 0 > nbuckets: 102998 > block_size: 1 > bucket_size: 1024 > nr_in_set: 1 > nr_this_dev: 0 > first_bucket: 1 > > > Signed-off-by: Shenghui Wang <shhuiw@xxxxxxxxxxx> It looks good to me. Reviewed-by: Coly Li <colyli@xxxxxxx> Thanks. Coly Li > --- > make-bcache.c | 38 ++++++++++++++++++++------------------ > 1 file changed, 20 insertions(+), 18 deletions(-) > > diff --git a/make-bcache.c b/make-bcache.c > index c626eae..a9c9f2d 100644 > --- a/make-bcache.c > +++ b/make-bcache.c > @@ -186,24 +186,26 @@ static void write_sb(char *dev, unsigned block_size, unsigned bucket_size, > if (pread(fd, &sb, sizeof(sb), SB_START) != sizeof(sb)) > exit(EXIT_FAILURE); > > - if (!memcmp(sb.magic, bcache_magic, 16) && !wipe_bcache) { > - fprintf(stderr, "Already a bcache device on %s, " > - "overwrite with --wipe-bcache\n", dev); > - exit(EXIT_FAILURE); > - } > - > - if (!(pr = blkid_new_probe())) > - exit(EXIT_FAILURE); > - if (blkid_probe_set_device(pr, fd, 0, 0)) > - exit(EXIT_FAILURE); > - /* enable ptable probing; superblock probing is enabled by default */ > - if (blkid_probe_enable_partitions(pr, true)) > - exit(EXIT_FAILURE); > - if (!blkid_do_probe(pr)) { > - /* XXX wipefs doesn't know how to remove partition tables */ > - fprintf(stderr, "Device %s already has a non-bcache superblock, " > - "remove it using wipefs and wipefs -a\n", dev); > - exit(EXIT_FAILURE); > + if (!memcmp(sb.magic, bcache_magic, 16)) { > + if (!wipe_bcache) { > + fprintf(stderr, "Already a bcache device on %s, " > + "overwrite with --wipe-bcache\n", dev); > + exit(EXIT_FAILURE); > + } > + } else { > + if (!(pr = blkid_new_probe())) > + exit(EXIT_FAILURE); > + if (blkid_probe_set_device(pr, fd, 0, 0)) > + exit(EXIT_FAILURE); > + /* enable ptable probing; superblock probing is enabled by default */ > + if (blkid_probe_enable_partitions(pr, true)) > + exit(EXIT_FAILURE); > + if (!blkid_do_probe(pr)) { > + /* XXX wipefs doesn't know how to remove partition tables */ > + fprintf(stderr, "Device %s already has a non-bcache superblock, " > + "remove it using wipefs and wipefs -a\n", dev); > + exit(EXIT_FAILURE); > + } > } > > memset(&sb, 0, sizeof(struct cache_sb)); > -- To unsubscribe from this list: send the line "unsubscribe linux-bcache" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html