Merge tag 'ovl-update-5.1' of git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/vfs
[platform/kernel/linux-starfive.git] / block / genhd.c
index cff6bdf..7032678 100644 (file)
@@ -47,51 +47,64 @@ static void disk_release_events(struct gendisk *disk);
 
 void part_inc_in_flight(struct request_queue *q, struct hd_struct *part, int rw)
 {
-       if (q->mq_ops)
+       if (queue_is_mq(q))
                return;
 
-       atomic_inc(&part->in_flight[rw]);
+       part_stat_local_inc(part, in_flight[rw]);
        if (part->partno)
-               atomic_inc(&part_to_disk(part)->part0.in_flight[rw]);
+               part_stat_local_inc(&part_to_disk(part)->part0, in_flight[rw]);
 }
 
 void part_dec_in_flight(struct request_queue *q, struct hd_struct *part, int rw)
 {
-       if (q->mq_ops)
+       if (queue_is_mq(q))
                return;
 
-       atomic_dec(&part->in_flight[rw]);
+       part_stat_local_dec(part, in_flight[rw]);
        if (part->partno)
-               atomic_dec(&part_to_disk(part)->part0.in_flight[rw]);
+               part_stat_local_dec(&part_to_disk(part)->part0, in_flight[rw]);
 }
 
-void part_in_flight(struct request_queue *q, struct hd_struct *part,
-                   unsigned int inflight[2])
+unsigned int part_in_flight(struct request_queue *q, struct hd_struct *part)
 {
-       if (q->mq_ops) {
-               blk_mq_in_flight(q, part, inflight);
-               return;
+       int cpu;
+       unsigned int inflight;
+
+       if (queue_is_mq(q)) {
+               return blk_mq_in_flight(q, part);
        }
 
-       inflight[0] = atomic_read(&part->in_flight[0]) +
-                       atomic_read(&part->in_flight[1]);
-       if (part->partno) {
-               part = &part_to_disk(part)->part0;
-               inflight[1] = atomic_read(&part->in_flight[0]) +
-                               atomic_read(&part->in_flight[1]);
+       inflight = 0;
+       for_each_possible_cpu(cpu) {
+               inflight += part_stat_local_read_cpu(part, in_flight[0], cpu) +
+                           part_stat_local_read_cpu(part, in_flight[1], cpu);
        }
+       if ((int)inflight < 0)
+               inflight = 0;
+
+       return inflight;
 }
 
 void part_in_flight_rw(struct request_queue *q, struct hd_struct *part,
                       unsigned int inflight[2])
 {
-       if (q->mq_ops) {
+       int cpu;
+
+       if (queue_is_mq(q)) {
                blk_mq_in_flight_rw(q, part, inflight);
                return;
        }
 
-       inflight[0] = atomic_read(&part->in_flight[0]);
-       inflight[1] = atomic_read(&part->in_flight[1]);
+       inflight[0] = 0;
+       inflight[1] = 0;
+       for_each_possible_cpu(cpu) {
+               inflight[0] += part_stat_local_read_cpu(part, in_flight[0], cpu);
+               inflight[1] += part_stat_local_read_cpu(part, in_flight[1], cpu);
+       }
+       if ((int)inflight[0] < 0)
+               inflight[0] = 0;
+       if ((int)inflight[1] < 0)
+               inflight[1] = 0;
 }
 
 struct hd_struct *__disk_get_part(struct gendisk *disk, int partno)
@@ -352,8 +365,8 @@ int register_blkdev(unsigned int major, const char *name)
                }
 
                if (index == 0) {
-                       printk("register_blkdev: failed to get major for %s\n",
-                              name);
+                       printk("%s: failed to get major for %s\n",
+                              __func__, name);
                        ret = -EBUSY;
                        goto out;
                }
@@ -362,8 +375,8 @@ int register_blkdev(unsigned int major, const char *name)
        }
 
        if (major >= BLKDEV_MAJOR_MAX) {
-               pr_err("register_blkdev: major requested (%u) is greater than the maximum (%u) for %s\n",
-                      major, BLKDEV_MAJOR_MAX-1, name);
+               pr_err("%s: major requested (%u) is greater than the maximum (%u) for %s\n",
+                      __func__, major, BLKDEV_MAJOR_MAX-1, name);
 
                ret = -EINVAL;
                goto out;
@@ -642,10 +655,12 @@ exit:
                kobject_uevent(&part_to_dev(part)->kobj, KOBJ_ADD);
        disk_part_iter_exit(&piter);
 
-       err = sysfs_create_link(&ddev->kobj,
-                               &disk->queue->backing_dev_info->dev->kobj,
-                               "bdi");
-       WARN_ON(err);
+       if (disk->queue->backing_dev_info->dev) {
+               err = sysfs_create_link(&ddev->kobj,
+                         &disk->queue->backing_dev_info->dev->kobj,
+                         "bdi");
+               WARN_ON(err);
+       }
 }
 
 /**
@@ -1325,8 +1340,7 @@ static int diskstats_show(struct seq_file *seqf, void *v)
        struct disk_part_iter piter;
        struct hd_struct *hd;
        char buf[BDEVNAME_SIZE];
-       unsigned int inflight[2];
-       int cpu;
+       unsigned int inflight;
 
        /*
        if (&disk_to_dev(gp)->kobj.entry == block_class.devices.next)
@@ -1338,10 +1352,7 @@ static int diskstats_show(struct seq_file *seqf, void *v)
 
        disk_part_iter_init(&piter, gp, DISK_PITER_INCL_EMPTY_PART0);
        while ((hd = disk_part_iter_next(&piter))) {
-               cpu = part_stat_lock();
-               part_round_stats(gp->queue, cpu, hd);
-               part_stat_unlock();
-               part_in_flight(gp->queue, hd, inflight);
+               inflight = part_in_flight(gp->queue, hd);
                seq_printf(seqf, "%4d %7d %s "
                           "%lu %lu %lu %u "
                           "%lu %lu %lu %u "
@@ -1357,7 +1368,7 @@ static int diskstats_show(struct seq_file *seqf, void *v)
                           part_stat_read(hd, merges[STAT_WRITE]),
                           part_stat_read(hd, sectors[STAT_WRITE]),
                           (unsigned int)part_stat_read_msecs(hd, STAT_WRITE),
-                          inflight[0],
+                          inflight,
                           jiffies_to_msecs(part_stat_read(hd, io_ticks)),
                           jiffies_to_msecs(part_stat_read(hd, time_in_queue)),
                           part_stat_read(hd, ios[STAT_DISCARD]),