libnvdimm/label: Return -ENXIO for no slot in __blk_label_update
[linux-2.6-microblaze.git] / drivers / nvdimm / label.c
index 47a4828..9251441 100644 (file)
@@ -980,6 +980,15 @@ static int __blk_label_update(struct nd_region *nd_region,
                }
        }
 
+       /* release slots associated with any invalidated UUIDs */
+       mutex_lock(&nd_mapping->lock);
+       list_for_each_entry_safe(label_ent, e, &nd_mapping->labels, list)
+               if (test_and_clear_bit(ND_LABEL_REAP, &label_ent->flags)) {
+                       reap_victim(nd_mapping, label_ent);
+                       list_move(&label_ent->list, &list);
+               }
+       mutex_unlock(&nd_mapping->lock);
+
        /*
         * Find the resource associated with the first label in the set
         * per the v1.2 namespace specification.
@@ -999,8 +1008,10 @@ static int __blk_label_update(struct nd_region *nd_region,
                if (is_old_resource(res, old_res_list, old_num_resources))
                        continue; /* carry-over */
                slot = nd_label_alloc_slot(ndd);
-               if (slot == UINT_MAX)
+               if (slot == UINT_MAX) {
+                       rc = -ENXIO;
                        goto abort;
+               }
                dev_dbg(ndd->dev, "allocated: %d\n", slot);
 
                nd_label = to_label(ndd, slot);