static void nbd_bdev_reset(struct nbd_device *nbd)
 {
-       if (nbd->disk->part0->bd_openers > 1)
+       if (disk_openers(nbd->disk) > 1)
                return;
        set_capacity(nbd->disk, 0);
 }
        struct nbd_device *nbd = disk->private_data;
 
        if (test_bit(NBD_RT_DISCONNECT_ON_CLOSE, &nbd->config->runtime_flags) &&
-                       disk->part0->bd_openers == 0)
+                       disk_openers(disk) == 0)
                nbd_disconnect_and_put(nbd);
 
        nbd_config_put(nbd);
 
 
        mutex_lock(&disk->open_mutex);
        /* Do not reset an active device or claimed device */
-       if (disk->part0->bd_openers || zram->claim) {
+       if (disk_openers(disk) || zram->claim) {
                mutex_unlock(&disk->open_mutex);
                return -EBUSY;
        }
        bool claimed;
 
        mutex_lock(&zram->disk->open_mutex);
-       if (zram->disk->part0->bd_openers) {
+       if (disk_openers(zram->disk)) {
                mutex_unlock(&zram->disk->open_mutex);
                return -EBUSY;
        }
 
        return !inode_unhashed(disk->part0->bd_inode);
 }
 
+/**
+ * disk_openers - returns how many openers are there for a disk
+ * @disk: disk to check
+ *
+ * This returns the number of openers for a disk.  Note that this value is only
+ * stable if disk->open_mutex is held.
+ *
+ * Note: Due to a quirk in the block layer open code, each open partition is
+ * only counted once even if there are multiple openers.
+ */
+static inline unsigned int disk_openers(struct gendisk *disk)
+{
+       return disk->part0->bd_openers;
+}
+
 /*
  * The gendisk is refcounted by the part0 block_device, and the bd_device
  * therein is also used for device model presentation in sysfs.