Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 209156
b: refs/heads/master
c: a5664da
h: refs/heads/master
v: v3
  • Loading branch information
Mike Snitzer authored and Alasdair G Kergon committed Aug 12, 2010
1 parent 24f3ab0 commit c43e87d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 10 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 708e929513502fb050c0a3c3ee267cab5b056ded
refs/heads/master: a5664dad7e1a278d2915c2bf79cf42250e12d7db
15 changes: 15 additions & 0 deletions trunk/drivers/md/dm-ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1189,6 +1189,21 @@ static int table_load(struct dm_ioctl *param, size_t param_size)
goto out;
}

/* Protect md->type against concurrent table loads. */
dm_lock_md_type(md);
if (dm_get_md_type(md) == DM_TYPE_NONE)
/* Initial table load: acquire type of table. */
dm_set_md_type(md, dm_table_get_type(t));
else if (dm_get_md_type(md) != dm_table_get_type(t)) {
DMWARN("can't change device type after initial table load.");
dm_table_destroy(t);
dm_unlock_md_type(md);
r = -EINVAL;
goto out;
}
dm_unlock_md_type(md);

/* stage inactive table */
down_write(&_hash_lock);
hc = dm_get_mdptr(md);
if (!hc || hc->md != md) {
Expand Down
37 changes: 30 additions & 7 deletions trunk/drivers/md/dm.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ struct mapped_device {
unsigned long flags;

struct request_queue *queue;
unsigned type;
/* Protect type against concurrent access. */
struct mutex type_lock;

struct gendisk *disk;
char name[16];

Expand Down Expand Up @@ -1877,8 +1881,10 @@ static struct mapped_device *alloc_dev(int minor)
if (r < 0)
goto bad_minor;

md->type = DM_TYPE_NONE;
init_rwsem(&md->io_lock);
mutex_init(&md->suspend_lock);
mutex_init(&md->type_lock);
spin_lock_init(&md->deferred_lock);
spin_lock_init(&md->barrier_error_lock);
rwlock_init(&md->map_lock);
Expand Down Expand Up @@ -2130,6 +2136,30 @@ int dm_create(int minor, struct mapped_device **result)
return 0;
}

/*
* Functions to manage md->type.
* All are required to hold md->type_lock.
*/
void dm_lock_md_type(struct mapped_device *md)
{
mutex_lock(&md->type_lock);
}

void dm_unlock_md_type(struct mapped_device *md)
{
mutex_unlock(&md->type_lock);
}

void dm_set_md_type(struct mapped_device *md, unsigned type)
{
md->type = type;
}

unsigned dm_get_md_type(struct mapped_device *md)
{
return md->type;
}

static struct mapped_device *dm_find_md(dev_t dev)
{
struct mapped_device *md;
Expand Down Expand Up @@ -2440,13 +2470,6 @@ struct dm_table *dm_swap_table(struct mapped_device *md, struct dm_table *table)
goto out;
}

/* cannot change the device type, once a table is bound */
if (md->map &&
(dm_table_get_type(md->map) != dm_table_get_type(table))) {
DMWARN("can't change the device type after a table is bound");
goto out;
}

map = __bind(md, table, &limits);

out:
Expand Down
5 changes: 5 additions & 0 deletions trunk/drivers/md/dm.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ int dm_table_alloc_md_mempools(struct dm_table *t);
void dm_table_free_md_mempools(struct dm_table *t);
struct dm_md_mempools *dm_table_get_md_mempools(struct dm_table *t);

void dm_lock_md_type(struct mapped_device *md);
void dm_unlock_md_type(struct mapped_device *md);
void dm_set_md_type(struct mapped_device *md, unsigned type);
unsigned dm_get_md_type(struct mapped_device *md);

/*
* To check the return value from dm_table_find_target().
*/
Expand Down
4 changes: 2 additions & 2 deletions trunk/include/linux/dm-ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,9 @@ enum {
#define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl)

#define DM_VERSION_MAJOR 4
#define DM_VERSION_MINOR 17
#define DM_VERSION_MINOR 18
#define DM_VERSION_PATCHLEVEL 0
#define DM_VERSION_EXTRA "-ioctl (2010-03-05)"
#define DM_VERSION_EXTRA "-ioctl (2010-06-29)"

/* Status bits */
#define DM_READONLY_FLAG (1 << 0) /* In/Out */
Expand Down

0 comments on commit c43e87d

Please sign in to comment.