nvme-multipath: add error handling support for add_disk()
authorLuis Chamberlain <mcgrof@kernel.org>
Fri, 15 Oct 2021 23:52:08 +0000 (16:52 -0700)
committerChristoph Hellwig <hch@lst.de>
Wed, 20 Oct 2021 17:16:03 +0000 (19:16 +0200)
We never checked for errors on add_disk() as this function
returned void. Now that this is fixed, use the shiny new
error handling.

Since we now can tell for sure when a disk was added, move
setting the bit NVME_NSHEAD_DISK_LIVE only when we did
add the disk successfully.

Nothing to do here as the cleanup is done elsewhere. We take
care and use test_and_set_bit() because it is protects against
two nvme paths simultaneously calling device_add_disk() on the
same namespace head.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
Reviewed-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/host/multipath.c

index 22c6b64f4d93c30f892493941502fcc56f8a9ea7..bc1e7d8a2c0fbbcc3c730cc314b52bd05d1cb035 100644 (file)
@@ -509,13 +509,23 @@ int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head)
 static void nvme_mpath_set_live(struct nvme_ns *ns)
 {
        struct nvme_ns_head *head = ns->head;
+       int rc;
 
        if (!head->disk)
                return;
 
+       /*
+        * test_and_set_bit() is used because it is protecting against two nvme
+        * paths simultaneously calling device_add_disk() on the same namespace
+        * head.
+        */
        if (!test_and_set_bit(NVME_NSHEAD_DISK_LIVE, &head->flags)) {
-               device_add_disk(&head->subsys->dev, head->disk,
-                               nvme_ns_id_attr_groups);
+               rc = device_add_disk(&head->subsys->dev, head->disk,
+                                    nvme_ns_id_attr_groups);
+               if (rc) {
+                       clear_bit(NVME_NSHEAD_DISK_LIVE, &ns->flags);
+                       return;
+               }
                nvme_add_ns_head_cdev(head);
        }