• Dan Williams's avatar
    block: fix bdi vs gendisk lifetime mismatch · df08c32c
    Dan Williams authored
    The name for a bdi of a gendisk is derived from the gendisk's devt.
    However, since the gendisk is destroyed before the bdi it leaves a
    window where a new gendisk could dynamically reuse the same devt while a
    bdi with the same name is still live.  Arrange for the bdi to hold a
    reference against its "owner" disk device while it is registered.
    Otherwise we can hit sysfs duplicate name collisions like the following:
    
     WARNING: CPU: 10 PID: 2078 at fs/sysfs/dir.c:31 sysfs_warn_dup+0x64/0x80
     sysfs: cannot create duplicate filename '/devices/virtual/bdi/259:1'
    
     Hardware name: HP ProLiant DL580 Gen8, BIOS P79 05/06/2015
      0000000000000286 0000000002c04ad5 ffff88006f24f970 ffffffff8134caec
      ffff88006f24f9c0 0000000000000000 ffff88006f24f9b0 ffffffff8108c351
      0000001f0000000c ffff88105d236000 ffff88105d1031e0 ffff8800357427f8
     Call Trace:
      [<ffffffff8134caec>] dump_stack+0x63/0x87
      [<ffffffff8108c351>] __warn+0xd1/0xf0
      [<ffffffff8108c3cf>] warn_slowpath_fmt+0x5f/0...
    df08c32c
backing-dev.c 26.3 KB