提交 31097557 编写于 作者: J Joe Thornber 提交者: Alasdair G Kergon

dm persistent data: introduce dm_bm_set_read_only

Introduce dm_bm_set_read_only to switch the block manager into a
read-only mode.  To be used when dm-thin degrades due to io errors on
the metadata device.
Signed-off-by: NJoe Thornber <ejt@redhat.com>
Signed-off-by: NMike Snitzer <snitzer@redhat.com>
Signed-off-by: NAlasdair G Kergon <agk@redhat.com>
上级 4afdd680
...@@ -364,6 +364,7 @@ static void dm_block_manager_write_callback(struct dm_buffer *buf) ...@@ -364,6 +364,7 @@ static void dm_block_manager_write_callback(struct dm_buffer *buf)
*--------------------------------------------------------------*/ *--------------------------------------------------------------*/
struct dm_block_manager { struct dm_block_manager {
struct dm_bufio_client *bufio; struct dm_bufio_client *bufio;
bool read_only:1;
}; };
struct dm_block_manager *dm_block_manager_create(struct block_device *bdev, struct dm_block_manager *dm_block_manager_create(struct block_device *bdev,
...@@ -390,6 +391,8 @@ struct dm_block_manager *dm_block_manager_create(struct block_device *bdev, ...@@ -390,6 +391,8 @@ struct dm_block_manager *dm_block_manager_create(struct block_device *bdev,
goto bad; goto bad;
} }
bm->read_only = false;
return bm; return bm;
bad: bad:
...@@ -481,6 +484,9 @@ int dm_bm_write_lock(struct dm_block_manager *bm, ...@@ -481,6 +484,9 @@ int dm_bm_write_lock(struct dm_block_manager *bm,
void *p; void *p;
int r; int r;
if (bm->read_only)
return -EPERM;
p = dm_bufio_read(bm->bufio, b, (struct dm_buffer **) result); p = dm_bufio_read(bm->bufio, b, (struct dm_buffer **) result);
if (unlikely(IS_ERR(p))) if (unlikely(IS_ERR(p)))
return PTR_ERR(p); return PTR_ERR(p);
...@@ -547,6 +553,9 @@ int dm_bm_write_lock_zero(struct dm_block_manager *bm, ...@@ -547,6 +553,9 @@ int dm_bm_write_lock_zero(struct dm_block_manager *bm,
struct buffer_aux *aux; struct buffer_aux *aux;
void *p; void *p;
if (bm->read_only)
return -EPERM;
p = dm_bufio_new(bm->bufio, b, (struct dm_buffer **) result); p = dm_bufio_new(bm->bufio, b, (struct dm_buffer **) result);
if (unlikely(IS_ERR(p))) if (unlikely(IS_ERR(p)))
return PTR_ERR(p); return PTR_ERR(p);
...@@ -589,6 +598,9 @@ int dm_bm_flush_and_unlock(struct dm_block_manager *bm, ...@@ -589,6 +598,9 @@ int dm_bm_flush_and_unlock(struct dm_block_manager *bm,
{ {
int r; int r;
if (bm->read_only)
return -EPERM;
r = dm_bufio_write_dirty_buffers(bm->bufio); r = dm_bufio_write_dirty_buffers(bm->bufio);
if (unlikely(r)) { if (unlikely(r)) {
dm_bm_unlock(superblock); dm_bm_unlock(superblock);
...@@ -600,6 +612,12 @@ int dm_bm_flush_and_unlock(struct dm_block_manager *bm, ...@@ -600,6 +612,12 @@ int dm_bm_flush_and_unlock(struct dm_block_manager *bm,
return dm_bufio_write_dirty_buffers(bm->bufio); return dm_bufio_write_dirty_buffers(bm->bufio);
} }
void dm_bm_set_read_only(struct dm_block_manager *bm)
{
bm->read_only = true;
}
EXPORT_SYMBOL_GPL(dm_bm_set_read_only);
u32 dm_bm_checksum(const void *data, size_t len, u32 init_xor) u32 dm_bm_checksum(const void *data, size_t len, u32 init_xor)
{ {
return crc32c(~(u32) 0, data, len) ^ init_xor; return crc32c(~(u32) 0, data, len) ^ init_xor;
......
...@@ -108,6 +108,19 @@ int dm_bm_unlock(struct dm_block *b); ...@@ -108,6 +108,19 @@ int dm_bm_unlock(struct dm_block *b);
int dm_bm_flush_and_unlock(struct dm_block_manager *bm, int dm_bm_flush_and_unlock(struct dm_block_manager *bm,
struct dm_block *superblock); struct dm_block *superblock);
/*
* Switches the bm to a read only mode. Once read-only mode
* has been entered the following functions will return -EPERM.
*
* dm_bm_write_lock
* dm_bm_write_lock_zero
* dm_bm_flush_and_unlock
*
* Additionally you should not use dm_bm_unlock_move, however no error will
* be returned if you do.
*/
void dm_bm_set_read_only(struct dm_block_manager *bm);
u32 dm_bm_checksum(const void *data, size_t len, u32 init_xor); u32 dm_bm_checksum(const void *data, size_t len, u32 init_xor);
/*----------------------------------------------------------------*/ /*----------------------------------------------------------------*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册