2011-11-01 00:19:11 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2011 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This file is released under the GPL.
|
|
|
|
*/
|
|
|
|
#include "dm-transaction-manager.h"
|
|
|
|
#include "dm-space-map.h"
|
|
|
|
#include "dm-space-map-disk.h"
|
|
|
|
#include "dm-space-map-metadata.h"
|
|
|
|
#include "dm-persistent-data-internal.h"
|
|
|
|
|
2011-09-29 02:29:32 +04:00
|
|
|
#include <linux/export.h>
|
2014-10-06 18:27:26 +04:00
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/hash.h>
|
2011-11-01 00:19:11 +04:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/device-mapper.h>
|
|
|
|
|
|
|
|
#define DM_MSG_PREFIX "transaction manager"
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------*/
|
|
|
|
|
2014-10-06 18:27:26 +04:00
|
|
|
#define PREFETCH_SIZE 128
|
|
|
|
#define PREFETCH_BITS 7
|
|
|
|
#define PREFETCH_SENTINEL ((dm_block_t) -1ULL)
|
|
|
|
|
|
|
|
struct prefetch_set {
|
|
|
|
struct mutex lock;
|
|
|
|
dm_block_t blocks[PREFETCH_SIZE];
|
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned prefetch_hash(dm_block_t b)
|
|
|
|
{
|
|
|
|
return hash_64(b, PREFETCH_BITS);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void prefetch_wipe(struct prefetch_set *p)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < PREFETCH_SIZE; i++)
|
|
|
|
p->blocks[i] = PREFETCH_SENTINEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void prefetch_init(struct prefetch_set *p)
|
|
|
|
{
|
|
|
|
mutex_init(&p->lock);
|
|
|
|
prefetch_wipe(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void prefetch_add(struct prefetch_set *p, dm_block_t b)
|
|
|
|
{
|
|
|
|
unsigned h = prefetch_hash(b);
|
|
|
|
|
|
|
|
mutex_lock(&p->lock);
|
|
|
|
if (p->blocks[h] == PREFETCH_SENTINEL)
|
|
|
|
p->blocks[h] = b;
|
|
|
|
|
|
|
|
mutex_unlock(&p->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void prefetch_issue(struct prefetch_set *p, struct dm_block_manager *bm)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
mutex_lock(&p->lock);
|
|
|
|
|
|
|
|
for (i = 0; i < PREFETCH_SIZE; i++)
|
|
|
|
if (p->blocks[i] != PREFETCH_SENTINEL) {
|
|
|
|
dm_bm_prefetch(bm, p->blocks[i]);
|
|
|
|
p->blocks[i] = PREFETCH_SENTINEL;
|
|
|
|
}
|
|
|
|
|
|
|
|
mutex_unlock(&p->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------*/
|
|
|
|
|
2011-11-01 00:19:11 +04:00
|
|
|
struct shadow_info {
|
|
|
|
struct hlist_node hlist;
|
|
|
|
dm_block_t where;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It would be nice if we scaled with the size of transaction.
|
|
|
|
*/
|
2013-02-23 04:32:03 +04:00
|
|
|
#define DM_HASH_SIZE 256
|
|
|
|
#define DM_HASH_MASK (DM_HASH_SIZE - 1)
|
2011-11-01 00:19:11 +04:00
|
|
|
|
|
|
|
struct dm_transaction_manager {
|
|
|
|
int is_clone;
|
|
|
|
struct dm_transaction_manager *real;
|
|
|
|
|
|
|
|
struct dm_block_manager *bm;
|
|
|
|
struct dm_space_map *sm;
|
|
|
|
|
|
|
|
spinlock_t lock;
|
2013-02-23 04:32:03 +04:00
|
|
|
struct hlist_head buckets[DM_HASH_SIZE];
|
2014-10-06 18:27:26 +04:00
|
|
|
|
|
|
|
struct prefetch_set prefetches;
|
2011-11-01 00:19:11 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static int is_shadow(struct dm_transaction_manager *tm, dm_block_t b)
|
|
|
|
{
|
|
|
|
int r = 0;
|
2013-02-23 04:32:03 +04:00
|
|
|
unsigned bucket = dm_hash_block(b, DM_HASH_MASK);
|
2011-11-01 00:19:11 +04:00
|
|
|
struct shadow_info *si;
|
|
|
|
|
|
|
|
spin_lock(&tm->lock);
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 05:06:00 +04:00
|
|
|
hlist_for_each_entry(si, tm->buckets + bucket, hlist)
|
2011-11-01 00:19:11 +04:00
|
|
|
if (si->where == b) {
|
|
|
|
r = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
spin_unlock(&tm->lock);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This can silently fail if there's no memory. We're ok with this since
|
|
|
|
* creating redundant shadows causes no harm.
|
|
|
|
*/
|
|
|
|
static void insert_shadow(struct dm_transaction_manager *tm, dm_block_t b)
|
|
|
|
{
|
|
|
|
unsigned bucket;
|
|
|
|
struct shadow_info *si;
|
|
|
|
|
|
|
|
si = kmalloc(sizeof(*si), GFP_NOIO);
|
|
|
|
if (si) {
|
|
|
|
si->where = b;
|
2013-02-23 04:32:03 +04:00
|
|
|
bucket = dm_hash_block(b, DM_HASH_MASK);
|
2011-11-01 00:19:11 +04:00
|
|
|
spin_lock(&tm->lock);
|
|
|
|
hlist_add_head(&si->hlist, tm->buckets + bucket);
|
|
|
|
spin_unlock(&tm->lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void wipe_shadow_table(struct dm_transaction_manager *tm)
|
|
|
|
{
|
|
|
|
struct shadow_info *si;
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 05:06:00 +04:00
|
|
|
struct hlist_node *tmp;
|
2011-11-01 00:19:11 +04:00
|
|
|
struct hlist_head *bucket;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
spin_lock(&tm->lock);
|
2013-02-23 04:32:03 +04:00
|
|
|
for (i = 0; i < DM_HASH_SIZE; i++) {
|
2011-11-01 00:19:11 +04:00
|
|
|
bucket = tm->buckets + i;
|
hlist: drop the node parameter from iterators
I'm not sure why, but the hlist for each entry iterators were conceived
list_for_each_entry(pos, head, member)
The hlist ones were greedy and wanted an extra parameter:
hlist_for_each_entry(tpos, pos, head, member)
Why did they need an extra pos parameter? I'm not quite sure. Not only
they don't really need it, it also prevents the iterator from looking
exactly like the list iterator, which is unfortunate.
Besides the semantic patch, there was some manual work required:
- Fix up the actual hlist iterators in linux/list.h
- Fix up the declaration of other iterators based on the hlist ones.
- A very small amount of places were using the 'node' parameter, this
was modified to use 'obj->member' instead.
- Coccinelle didn't handle the hlist_for_each_entry_safe iterator
properly, so those had to be fixed up manually.
The semantic patch which is mostly the work of Peter Senna Tschudin is here:
@@
iterator name hlist_for_each_entry, hlist_for_each_entry_continue, hlist_for_each_entry_from, hlist_for_each_entry_rcu, hlist_for_each_entry_rcu_bh, hlist_for_each_entry_continue_rcu_bh, for_each_busy_worker, ax25_uid_for_each, ax25_for_each, inet_bind_bucket_for_each, sctp_for_each_hentry, sk_for_each, sk_for_each_rcu, sk_for_each_from, sk_for_each_safe, sk_for_each_bound, hlist_for_each_entry_safe, hlist_for_each_entry_continue_rcu, nr_neigh_for_each, nr_neigh_for_each_safe, nr_node_for_each, nr_node_for_each_safe, for_each_gfn_indirect_valid_sp, for_each_gfn_sp, for_each_host;
type T;
expression a,c,d,e;
identifier b;
statement S;
@@
-T b;
<+... when != b
(
hlist_for_each_entry(a,
- b,
c, d) S
|
hlist_for_each_entry_continue(a,
- b,
c) S
|
hlist_for_each_entry_from(a,
- b,
c) S
|
hlist_for_each_entry_rcu(a,
- b,
c, d) S
|
hlist_for_each_entry_rcu_bh(a,
- b,
c, d) S
|
hlist_for_each_entry_continue_rcu_bh(a,
- b,
c) S
|
for_each_busy_worker(a, c,
- b,
d) S
|
ax25_uid_for_each(a,
- b,
c) S
|
ax25_for_each(a,
- b,
c) S
|
inet_bind_bucket_for_each(a,
- b,
c) S
|
sctp_for_each_hentry(a,
- b,
c) S
|
sk_for_each(a,
- b,
c) S
|
sk_for_each_rcu(a,
- b,
c) S
|
sk_for_each_from
-(a, b)
+(a)
S
+ sk_for_each_from(a) S
|
sk_for_each_safe(a,
- b,
c, d) S
|
sk_for_each_bound(a,
- b,
c) S
|
hlist_for_each_entry_safe(a,
- b,
c, d, e) S
|
hlist_for_each_entry_continue_rcu(a,
- b,
c) S
|
nr_neigh_for_each(a,
- b,
c) S
|
nr_neigh_for_each_safe(a,
- b,
c, d) S
|
nr_node_for_each(a,
- b,
c) S
|
nr_node_for_each_safe(a,
- b,
c, d) S
|
- for_each_gfn_sp(a, c, d, b) S
+ for_each_gfn_sp(a, c, d) S
|
- for_each_gfn_indirect_valid_sp(a, c, d, b) S
+ for_each_gfn_indirect_valid_sp(a, c, d) S
|
for_each_host(a,
- b,
c) S
|
for_each_host_safe(a,
- b,
c, d) S
|
for_each_mesh_entry(a,
- b,
c, d) S
)
...+>
[akpm@linux-foundation.org: drop bogus change from net/ipv4/raw.c]
[akpm@linux-foundation.org: drop bogus hunk from net/ipv6/raw.c]
[akpm@linux-foundation.org: checkpatch fixes]
[akpm@linux-foundation.org: fix warnings]
[akpm@linux-foudnation.org: redo intrusive kvm changes]
Tested-by: Peter Senna Tschudin <peter.senna@gmail.com>
Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
Cc: Wu Fengguang <fengguang.wu@intel.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-28 05:06:00 +04:00
|
|
|
hlist_for_each_entry_safe(si, tmp, bucket, hlist)
|
2011-11-01 00:19:11 +04:00
|
|
|
kfree(si);
|
|
|
|
|
|
|
|
INIT_HLIST_HEAD(bucket);
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_unlock(&tm->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static struct dm_transaction_manager *dm_tm_create(struct dm_block_manager *bm,
|
|
|
|
struct dm_space_map *sm)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct dm_transaction_manager *tm;
|
|
|
|
|
|
|
|
tm = kmalloc(sizeof(*tm), GFP_KERNEL);
|
|
|
|
if (!tm)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
tm->is_clone = 0;
|
|
|
|
tm->real = NULL;
|
|
|
|
tm->bm = bm;
|
|
|
|
tm->sm = sm;
|
|
|
|
|
|
|
|
spin_lock_init(&tm->lock);
|
2013-02-23 04:32:03 +04:00
|
|
|
for (i = 0; i < DM_HASH_SIZE; i++)
|
2011-11-01 00:19:11 +04:00
|
|
|
INIT_HLIST_HEAD(tm->buckets + i);
|
|
|
|
|
2014-10-06 18:27:26 +04:00
|
|
|
prefetch_init(&tm->prefetches);
|
|
|
|
|
2011-11-01 00:19:11 +04:00
|
|
|
return tm;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dm_transaction_manager *dm_tm_create_non_blocking_clone(struct dm_transaction_manager *real)
|
|
|
|
{
|
|
|
|
struct dm_transaction_manager *tm;
|
|
|
|
|
|
|
|
tm = kmalloc(sizeof(*tm), GFP_KERNEL);
|
|
|
|
if (tm) {
|
|
|
|
tm->is_clone = 1;
|
|
|
|
tm->real = real;
|
|
|
|
}
|
|
|
|
|
|
|
|
return tm;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_tm_create_non_blocking_clone);
|
|
|
|
|
|
|
|
void dm_tm_destroy(struct dm_transaction_manager *tm)
|
|
|
|
{
|
2012-07-03 15:55:33 +04:00
|
|
|
if (!tm->is_clone)
|
|
|
|
wipe_shadow_table(tm);
|
|
|
|
|
2011-11-01 00:19:11 +04:00
|
|
|
kfree(tm);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_tm_destroy);
|
|
|
|
|
|
|
|
int dm_tm_pre_commit(struct dm_transaction_manager *tm)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
if (tm->is_clone)
|
|
|
|
return -EWOULDBLOCK;
|
|
|
|
|
|
|
|
r = dm_sm_commit(tm->sm);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2014-03-27 18:13:20 +04:00
|
|
|
return dm_bm_flush(tm->bm);
|
2011-11-01 00:19:11 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_tm_pre_commit);
|
|
|
|
|
|
|
|
int dm_tm_commit(struct dm_transaction_manager *tm, struct dm_block *root)
|
|
|
|
{
|
|
|
|
if (tm->is_clone)
|
|
|
|
return -EWOULDBLOCK;
|
|
|
|
|
|
|
|
wipe_shadow_table(tm);
|
2014-03-27 18:13:20 +04:00
|
|
|
dm_bm_unlock(root);
|
2011-11-01 00:19:11 +04:00
|
|
|
|
2014-03-27 18:13:20 +04:00
|
|
|
return dm_bm_flush(tm->bm);
|
2011-11-01 00:19:11 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_tm_commit);
|
|
|
|
|
|
|
|
int dm_tm_new_block(struct dm_transaction_manager *tm,
|
|
|
|
struct dm_block_validator *v,
|
|
|
|
struct dm_block **result)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
dm_block_t new_block;
|
|
|
|
|
|
|
|
if (tm->is_clone)
|
|
|
|
return -EWOULDBLOCK;
|
|
|
|
|
|
|
|
r = dm_sm_new_block(tm->sm, &new_block);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = dm_bm_write_lock_zero(tm->bm, new_block, v, result);
|
|
|
|
if (r < 0) {
|
|
|
|
dm_sm_dec_block(tm->sm, new_block);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* New blocks count as shadows in that they don't need to be
|
|
|
|
* shadowed again.
|
|
|
|
*/
|
|
|
|
insert_shadow(tm, new_block);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __shadow_block(struct dm_transaction_manager *tm, dm_block_t orig,
|
|
|
|
struct dm_block_validator *v,
|
|
|
|
struct dm_block **result)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
dm_block_t new;
|
|
|
|
struct dm_block *orig_block;
|
|
|
|
|
|
|
|
r = dm_sm_new_block(tm->sm, &new);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = dm_sm_dec_block(tm->sm, orig);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
r = dm_bm_read_lock(tm->bm, orig, v, &orig_block);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
2012-07-27 18:08:09 +04:00
|
|
|
/*
|
|
|
|
* It would be tempting to use dm_bm_unlock_move here, but some
|
|
|
|
* code, such as the space maps, keeps using the old data structures
|
|
|
|
* secure in the knowledge they won't be changed until the next
|
|
|
|
* transaction. Using unlock_move would force a synchronous read
|
|
|
|
* since the old block would no longer be in the cache.
|
|
|
|
*/
|
|
|
|
r = dm_bm_write_lock_zero(tm->bm, new, v, result);
|
|
|
|
if (r) {
|
2011-11-01 00:19:11 +04:00
|
|
|
dm_bm_unlock(orig_block);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2012-07-27 18:08:09 +04:00
|
|
|
memcpy(dm_block_data(*result), dm_block_data(orig_block),
|
|
|
|
dm_bm_block_size(tm->bm));
|
|
|
|
|
|
|
|
dm_bm_unlock(orig_block);
|
|
|
|
return r;
|
2011-11-01 00:19:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int dm_tm_shadow_block(struct dm_transaction_manager *tm, dm_block_t orig,
|
|
|
|
struct dm_block_validator *v, struct dm_block **result,
|
|
|
|
int *inc_children)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
|
|
|
if (tm->is_clone)
|
|
|
|
return -EWOULDBLOCK;
|
|
|
|
|
|
|
|
r = dm_sm_count_is_more_than_one(tm->sm, orig, inc_children);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
if (is_shadow(tm, orig) && !*inc_children)
|
|
|
|
return dm_bm_write_lock(tm->bm, orig, v, result);
|
|
|
|
|
|
|
|
r = __shadow_block(tm, orig, v, result);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
insert_shadow(tm, dm_block_location(*result));
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
2012-06-03 03:30:01 +04:00
|
|
|
EXPORT_SYMBOL_GPL(dm_tm_shadow_block);
|
2011-11-01 00:19:11 +04:00
|
|
|
|
|
|
|
int dm_tm_read_lock(struct dm_transaction_manager *tm, dm_block_t b,
|
|
|
|
struct dm_block_validator *v,
|
|
|
|
struct dm_block **blk)
|
|
|
|
{
|
2014-10-06 18:27:26 +04:00
|
|
|
if (tm->is_clone) {
|
|
|
|
int r = dm_bm_read_try_lock(tm->real->bm, b, v, blk);
|
|
|
|
|
|
|
|
if (r == -EWOULDBLOCK)
|
|
|
|
prefetch_add(&tm->real->prefetches, b);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
2011-11-01 00:19:11 +04:00
|
|
|
|
|
|
|
return dm_bm_read_lock(tm->bm, b, v, blk);
|
|
|
|
}
|
2012-06-03 03:30:01 +04:00
|
|
|
EXPORT_SYMBOL_GPL(dm_tm_read_lock);
|
2011-11-01 00:19:11 +04:00
|
|
|
|
2015-10-22 23:46:59 +03:00
|
|
|
void dm_tm_unlock(struct dm_transaction_manager *tm, struct dm_block *b)
|
2011-11-01 00:19:11 +04:00
|
|
|
{
|
2015-10-22 23:46:59 +03:00
|
|
|
dm_bm_unlock(b);
|
2011-11-01 00:19:11 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_tm_unlock);
|
|
|
|
|
|
|
|
void dm_tm_inc(struct dm_transaction_manager *tm, dm_block_t b)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The non-blocking clone doesn't support this.
|
|
|
|
*/
|
|
|
|
BUG_ON(tm->is_clone);
|
|
|
|
|
|
|
|
dm_sm_inc_block(tm->sm, b);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_tm_inc);
|
|
|
|
|
|
|
|
void dm_tm_dec(struct dm_transaction_manager *tm, dm_block_t b)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* The non-blocking clone doesn't support this.
|
|
|
|
*/
|
|
|
|
BUG_ON(tm->is_clone);
|
|
|
|
|
|
|
|
dm_sm_dec_block(tm->sm, b);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_tm_dec);
|
|
|
|
|
|
|
|
int dm_tm_ref(struct dm_transaction_manager *tm, dm_block_t b,
|
|
|
|
uint32_t *result)
|
|
|
|
{
|
|
|
|
if (tm->is_clone)
|
|
|
|
return -EWOULDBLOCK;
|
|
|
|
|
|
|
|
return dm_sm_get_count(tm->sm, b, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dm_block_manager *dm_tm_get_bm(struct dm_transaction_manager *tm)
|
|
|
|
{
|
|
|
|
return tm->bm;
|
|
|
|
}
|
|
|
|
|
2014-10-06 18:27:26 +04:00
|
|
|
void dm_tm_issue_prefetches(struct dm_transaction_manager *tm)
|
|
|
|
{
|
|
|
|
prefetch_issue(&tm->prefetches, tm->bm);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_tm_issue_prefetches);
|
|
|
|
|
2011-11-01 00:19:11 +04:00
|
|
|
/*----------------------------------------------------------------*/
|
|
|
|
|
|
|
|
static int dm_tm_create_internal(struct dm_block_manager *bm,
|
|
|
|
dm_block_t sb_location,
|
|
|
|
struct dm_transaction_manager **tm,
|
|
|
|
struct dm_space_map **sm,
|
2012-07-27 18:08:09 +04:00
|
|
|
int create,
|
|
|
|
void *sm_root, size_t sm_len)
|
2011-11-01 00:19:11 +04:00
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
2012-07-27 18:07:58 +04:00
|
|
|
*sm = dm_sm_metadata_init();
|
|
|
|
if (IS_ERR(*sm))
|
|
|
|
return PTR_ERR(*sm);
|
2011-11-01 00:19:11 +04:00
|
|
|
|
2012-07-27 18:07:58 +04:00
|
|
|
*tm = dm_tm_create(bm, *sm);
|
2011-11-01 00:19:11 +04:00
|
|
|
if (IS_ERR(*tm)) {
|
2012-07-27 18:07:58 +04:00
|
|
|
dm_sm_destroy(*sm);
|
2011-11-01 00:19:11 +04:00
|
|
|
return PTR_ERR(*tm);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (create) {
|
2012-07-27 18:07:58 +04:00
|
|
|
r = dm_sm_metadata_create(*sm, *tm, dm_bm_nr_blocks(bm),
|
2011-11-01 00:19:11 +04:00
|
|
|
sb_location);
|
|
|
|
if (r) {
|
|
|
|
DMERR("couldn't create metadata space map");
|
2012-07-27 18:08:09 +04:00
|
|
|
goto bad;
|
2011-11-01 00:19:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
2012-07-27 18:08:09 +04:00
|
|
|
r = dm_sm_metadata_open(*sm, *tm, sm_root, sm_len);
|
2011-11-01 00:19:11 +04:00
|
|
|
if (r) {
|
|
|
|
DMERR("couldn't open metadata space map");
|
2012-07-27 18:08:09 +04:00
|
|
|
goto bad;
|
2011-11-01 00:19:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2012-07-27 18:08:09 +04:00
|
|
|
bad:
|
2011-11-01 00:19:11 +04:00
|
|
|
dm_tm_destroy(*tm);
|
2012-07-27 18:08:09 +04:00
|
|
|
dm_sm_destroy(*sm);
|
2011-11-01 00:19:11 +04:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
int dm_tm_create_with_sm(struct dm_block_manager *bm, dm_block_t sb_location,
|
|
|
|
struct dm_transaction_manager **tm,
|
2012-07-27 18:08:09 +04:00
|
|
|
struct dm_space_map **sm)
|
2011-11-01 00:19:11 +04:00
|
|
|
{
|
2012-07-27 18:08:09 +04:00
|
|
|
return dm_tm_create_internal(bm, sb_location, tm, sm, 1, NULL, 0);
|
2011-11-01 00:19:11 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_tm_create_with_sm);
|
|
|
|
|
|
|
|
int dm_tm_open_with_sm(struct dm_block_manager *bm, dm_block_t sb_location,
|
2012-07-27 18:08:09 +04:00
|
|
|
void *sm_root, size_t root_len,
|
2011-11-01 00:19:11 +04:00
|
|
|
struct dm_transaction_manager **tm,
|
2012-07-27 18:08:09 +04:00
|
|
|
struct dm_space_map **sm)
|
2011-11-01 00:19:11 +04:00
|
|
|
{
|
2012-07-27 18:08:09 +04:00
|
|
|
return dm_tm_create_internal(bm, sb_location, tm, sm, 0, sm_root, root_len);
|
2011-11-01 00:19:11 +04:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(dm_tm_open_with_sm);
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------*/
|