OSDN Git Service

Merge tag 'v4.4.214' into 10
[sagit-ice-cold/kernel_xiaomi_msm8998.git] / drivers / md / persistent-data / dm-space-map-common.c
index 306d2e4..22729fd 100644 (file)
@@ -382,6 +382,33 @@ int sm_ll_find_free_block(struct ll_disk *ll, dm_block_t begin,
        return -ENOSPC;
 }
 
+int sm_ll_find_common_free_block(struct ll_disk *old_ll, struct ll_disk *new_ll,
+                                dm_block_t begin, dm_block_t end, dm_block_t *b)
+{
+       int r;
+       uint32_t count;
+
+       do {
+               r = sm_ll_find_free_block(new_ll, begin, new_ll->nr_blocks, b);
+               if (r)
+                       break;
+
+               /* double check this block wasn't used in the old transaction */
+               if (*b >= old_ll->nr_blocks)
+                       count = 0;
+               else {
+                       r = sm_ll_lookup(old_ll, *b, &count);
+                       if (r)
+                               break;
+
+                       if (count)
+                               begin = *b + 1;
+               }
+       } while (count);
+
+       return r;
+}
+
 static int sm_ll_mutate(struct ll_disk *ll, dm_block_t b,
                        int (*mutator)(void *context, uint32_t old, uint32_t *new),
                        void *context, enum allocation_event *ev)