Some code tidy-ups in preparation for the next patches. Change
dm_table_pre/postsuspend_targets to accept NULL. Use dm_suspended()
throughout.
Signed-Off-By: Alasdair G Kergon <agk@redhat.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
void dm_table_presuspend_targets(struct dm_table *t)
{
void dm_table_presuspend_targets(struct dm_table *t)
{
return suspend_targets(t, 0);
}
void dm_table_postsuspend_targets(struct dm_table *t)
{
return suspend_targets(t, 0);
}
void dm_table_postsuspend_targets(struct dm_table *t)
{
return suspend_targets(t, 1);
}
return suspend_targets(t, 1);
}
int ret = -ENXIO;
if (map) {
int ret = -ENXIO;
if (map) {
- ret = dm_table_flush_all(md->map);
+ ret = dm_table_flush_all(map);
write_unlock(&md->map_lock);
dm_table_get(t);
write_unlock(&md->map_lock);
dm_table_get(t);
- dm_table_event_callback(md->map, event_callback, md);
+ dm_table_event_callback(t, event_callback, md);
dm_table_set_restrictions(t, q);
return 0;
}
dm_table_set_restrictions(t, q);
return 0;
}
struct dm_table *map = dm_get_table(md);
if (atomic_dec_and_test(&md->holders)) {
struct dm_table *map = dm_get_table(md);
if (atomic_dec_and_test(&md->holders)) {
- if (!test_bit(DMF_SUSPENDED, &md->flags) && map) {
+ if (!dm_suspended(md)) {
dm_table_presuspend_targets(map);
dm_table_postsuspend_targets(map);
}
dm_table_presuspend_targets(map);
dm_table_postsuspend_targets(map);
}
down_write(&md->lock);
/* device must be suspended */
down_write(&md->lock);
/* device must be suspended */
- if (!test_bit(DMF_SUSPENDED, &md->flags))
*/
static int __lock_fs(struct mapped_device *md)
{
*/
static int __lock_fs(struct mapped_device *md)
{
if (test_and_set_bit(DMF_FS_LOCKED, &md->flags))
return 0;
if (test_and_set_bit(DMF_FS_LOCKED, &md->flags))
return 0;
md->frozen_sb = freeze_bdev(md->frozen_bdev);
if (IS_ERR(md->frozen_sb)) {
md->frozen_sb = freeze_bdev(md->frozen_bdev);
if (IS_ERR(md->frozen_sb)) {
- error = PTR_ERR(md->frozen_sb);
+ r = PTR_ERR(md->frozen_sb);
md->frozen_bdev = NULL;
out:
clear_bit(DMF_FS_LOCKED, &md->flags);
md->frozen_bdev = NULL;
out:
clear_bit(DMF_FS_LOCKED, &md->flags);
}
static void __unlock_fs(struct mapped_device *md)
}
static void __unlock_fs(struct mapped_device *md)
{
struct dm_table *map;
DECLARE_WAITQUEUE(wait, current);
{
struct dm_table *map;
DECLARE_WAITQUEUE(wait, current);
- /* Flush I/O to the device. */
down_read(&md->lock);
if (test_bit(DMF_BLOCK_IO, &md->flags))
goto out_read_unlock;
map = dm_get_table(md);
down_read(&md->lock);
if (test_bit(DMF_BLOCK_IO, &md->flags))
goto out_read_unlock;
map = dm_get_table(md);
- if (map)
- /* This does not get reverted if there's an error later. */
- dm_table_presuspend_targets(map);
- error = __lock_fs(md);
- if (error) {
+ /* This does not get reverted if there's an error later. */
+ dm_table_presuspend_targets(map);
+
+ /* Flush I/O to the device. */
+ r = __lock_fs(md);
+ if (r) {
dm_table_put(map);
goto out_read_unlock;
}
dm_table_put(map);
goto out_read_unlock;
}
* If the flag is already set we know another thread is trying to
* suspend as well, so we leave the fs locked for this thread.
*/
* If the flag is already set we know another thread is trying to
* suspend as well, so we leave the fs locked for this thread.
*/
down_write(&md->lock);
if (test_and_set_bit(DMF_BLOCK_IO, &md->flags)) {
if (map)
down_write(&md->lock);
if (test_and_set_bit(DMF_BLOCK_IO, &md->flags)) {
if (map)
remove_wait_queue(&md->wait, &wait);
/* were we interrupted ? */
remove_wait_queue(&md->wait, &wait);
/* were we interrupted ? */
if (atomic_read(&md->pending))
goto out_unfreeze;
set_bit(DMF_SUSPENDED, &md->flags);
map = dm_get_table(md);
if (atomic_read(&md->pending))
goto out_unfreeze;
set_bit(DMF_SUSPENDED, &md->flags);
map = dm_get_table(md);
- if (map)
- dm_table_postsuspend_targets(map);
+ dm_table_postsuspend_targets(map);
dm_table_put(map);
up_write(&md->lock);
dm_table_put(map);
up_write(&md->lock);
clear_bit(DMF_BLOCK_IO, &md->flags);
out_write_unlock:
up_write(&md->lock);
clear_bit(DMF_BLOCK_IO, &md->flags);
out_write_unlock:
up_write(&md->lock);
out_read_unlock:
up_read(&md->lock);
out_read_unlock:
up_read(&md->lock);
}
int dm_resume(struct mapped_device *md)
{
}
int dm_resume(struct mapped_device *md)
{
- struct dm_table *map = dm_get_table(md);
+ struct dm_table *map = NULL;
- if (!map ||
- !test_bit(DMF_SUSPENDED, &md->flags) ||
- !dm_table_get_size(map)) {
+ if (!dm_suspended(md)) {
- dm_table_put(map);
- return -EINVAL;
+ goto out;
+ }
+
+ map = dm_get_table(md);
+ if (!map || !dm_table_get_size(map)) {
+ up_write(&md->lock);
+ goto out;
}
dm_table_resume_targets(map);
}
dm_table_resume_targets(map);
up_write(&md->lock);
__unlock_fs(md);
dm_table_unplug_all(map);
up_write(&md->lock);
__unlock_fs(md);
dm_table_unplug_all(map);
+ r = 0;
+out:
+ dm_table_put(map);
+ return r;
}
/*-----------------------------------------------------------------
}
/*-----------------------------------------------------------------