[Devel] [PATCH vz9 2/3] dm-qcow2: enable injection fault

Alexander Atanasov alexander.atanasov at virtuozzo.com
Mon Nov 14 22:04:16 MSK 2022


Instrument dm-qcow2 functions to allow injection fault.

https://jira.sw.ru/browse/PSBM-143153
Signed-off-by: Alexander Atanasov <alexander.atanasov at virtuozzo.com>
---
 drivers/md/dm-qcow2-cmd.c    |  5 +++++
 drivers/md/dm-qcow2-map.c    |  4 ++++
 drivers/md/dm-qcow2-target.c | 12 ++++++++++++
 3 files changed, 21 insertions(+)

diff --git a/drivers/md/dm-qcow2-cmd.c b/drivers/md/dm-qcow2-cmd.c
index 8580f2377860..d510f8d06d24 100644
--- a/drivers/md/dm-qcow2-cmd.c
+++ b/drivers/md/dm-qcow2-cmd.c
@@ -5,6 +5,7 @@
 #include <linux/device-mapper.h>
 #include <linux/sched/signal.h>
 #include <linux/file.h>
+#include <linux/error-injection.h>
 #include "dm-qcow2.h"
 
 #define SERVICE_QIOS_MAX 64
@@ -99,6 +100,7 @@ static int qcow2_service_iter(struct qcow2_target *tgt, struct qcow2 *qcow2,
 
 	return ret;
 }
+ALLOW_ERROR_INJECTION(qcow2_service_iter, ERRNO);
 
 static int qcow2_merge_common(struct qcow2_target *tgt)
 {
@@ -121,6 +123,7 @@ static int qcow2_merge_forward(struct qcow2_target *tgt)
 {
 	return -ENOTTY; /* TODO */
 }
+ALLOW_ERROR_INJECTION(qcow2_merge_forward, ERRNO);
 
 static int qcow2_break_l1cow(struct qcow2_target *tgt)
 {
@@ -216,6 +219,7 @@ static int qcow2_merge_backward(struct qcow2_target *tgt)
 out:
 	return ret;
 }
+ALLOW_ERROR_INJECTION(qcow2_merge_backward, ERRNO);
 
 static struct qcow2 *qcow2_get_img(struct qcow2_target *tgt, u32 img_id, u8 *ref_index)
 {
@@ -232,6 +236,7 @@ static struct qcow2 *qcow2_get_img(struct qcow2_target *tgt, u32 img_id, u8 *ref
 	}
 	return qcow2;
 }
+ALLOW_ERROR_INJECTION(qcow2_get_img, NULL);
 
 static int qcow2_get_img_fd(struct qcow2_target *tgt, u32 img_id,
 			    char *result, unsigned int maxlen)
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index 08a4c340a34d..28bd9a7c27d3 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -8,6 +8,7 @@
 #include <uapi/linux/falloc.h>
 #include <linux/blk-mq.h>
 #include <linux/zlib.h>
+#include <linux/error-injection.h>
 
 #include "dm.h"
 #include "dm-rq.h"
@@ -323,6 +324,7 @@ struct qio *qcow2_alloc_qio(mempool_t *pool, bool zero)
 	}
 	return qio;
 }
+ALLOW_ERROR_INJECTION(qcow2_alloc_qio, NULL);
 
 void qcow2_init_qio(struct qio *qio, unsigned int bi_op, struct qcow2 *qcow2)
 {
@@ -352,6 +354,7 @@ static int qcow2_alloc_qio_ext(struct qio *qio)
 		return -ENOMEM;
 	return 0;
 }
+ALLOW_ERROR_INJECTION(qcow2_alloc_qio_ext, ERRNO);
 
 static void finalize_qio_ext(struct qio *qio)
 {
@@ -531,6 +534,7 @@ static int qcow2_split_qio_to_list(struct qcow2 *qcow2, struct qio *qio,
 	}
 	return -ENOMEM;
 }
+ALLOW_ERROR_INJECTION(qcow2_split_qio_to_list, ERRNO);
 
 static void perform_zero_read(struct qio *qio, u32 size)
 {
diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index d132b25c150d..11a21e8c788e 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -295,6 +295,7 @@ static struct md_page *qcow2_md_page_find(struct qcow2 *qcow2, unsigned int id)
 	spin_unlock_irq(&qcow2->md_pages_lock);
 	return md;
 }
+ALLOW_ERROR_INJECTION(qcow2_md_page_find, NULL);
 
 /*
  * This returns md if it's found and up to date, or NULL.
@@ -317,6 +318,7 @@ struct md_page *qcow2_md_page_find_or_postpone(struct qcow2 *qcow2, unsigned int
 
 	return md;
 }
+ALLOW_ERROR_INJECTION(qcow2_md_page_find_or_postpone, NULL);
 
 static int md_page_try_insert(struct qcow2 *qcow2, struct md_page *new_md)
 {
@@ -367,6 +369,7 @@ struct md_page *qcow2_md_page_renumber(struct qcow2 *qcow2, unsigned int id,
 	}
 	return md;
 }
+ALLOW_ERROR_INJECTION(qcow2_md_page_renumber, NULL);
 
 void qcow2_zero_fill_page_from(struct page *page, unsigned int from)
 {
@@ -410,6 +413,7 @@ int qcow2_alloc_and_insert_md_page(struct qcow2 *qcow2, u64 index, struct md_pag
 	kfree(*md);
 	return ret;
 }
+ALLOW_ERROR_INJECTION(qcow2_alloc_and_insert_md_page, ERRNO);
 
 static void inflight_ref_exit0(struct percpu_ref *ref)
 {
@@ -579,6 +583,7 @@ static int qcow2_check_convert_hdr(struct dm_target *ti,
 
 	return 0;
 }
+ALLOW_ERROR_INJECTION(qcow2_check_convert_hdr, ERRNO);
 
 void qcow2_calc_cached_parameters(struct qcow2 *qcow2, struct QCowHeader *hdr)
 {
@@ -635,6 +640,7 @@ int qcow2_set_image_file_features(struct qcow2 *qcow2, bool dirty)
 
 	return qcow2_rw_page_sync(WRITE, qcow2, md->id, md->page);
 }
+ALLOW_ERROR_INJECTION(qcow2_set_image_file_features, ERRNO);
 
 static struct qcow2 *qcow2_alloc_delta(struct qcow2_target *tgt, struct qcow2 *upper)
 {
@@ -665,6 +671,7 @@ static struct qcow2 *qcow2_alloc_delta(struct qcow2_target *tgt, struct qcow2 *u
 
 	return qcow2;
 }
+ALLOW_ERROR_INJECTION(qcow2_alloc_delta, NULL);
 
 static int qcow2_attach_file(struct dm_target *ti, struct qcow2_target *tgt,
 			     struct qcow2 *qcow2, int fd)
@@ -698,6 +705,7 @@ static int qcow2_attach_file(struct dm_target *ti, struct qcow2_target *tgt,
 
 	return 0;
 }
+ALLOW_ERROR_INJECTION(qcow2_attach_file, ERRNO);
 
 static int qcow2_parse_header(struct dm_target *ti, struct qcow2 *qcow2,
 			      struct qcow2 *upper, bool is_bottom)
@@ -761,6 +769,7 @@ static int qcow2_parse_header(struct dm_target *ti, struct qcow2 *qcow2,
 out:
 	return ret;
 }
+ALLOW_ERROR_INJECTION(qcow2_parse_header, ERRNO);
 
 static int qcow2_parse_metadata(struct dm_target *ti, struct qcow2_target *tgt)
 {
@@ -842,6 +851,7 @@ static int qcow2_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 	qcow2_tgt_destroy(tgt);
 	return ret;
 }
+ALLOW_ERROR_INJECTION(qcow2_ctr, ERRNO);
 
 static void qcow2_dtr(struct dm_target *ti)
 {
@@ -985,6 +995,8 @@ static int qcow2_preresume(struct dm_target *ti)
 
 	return ret;
 }
+ALLOW_ERROR_INJECTION(qcow2_preresume, ERRNO);
+
 static void qcow2_resume(struct dm_target *ti)
 {
 	qcow2_set_service_operations(ti, true);
-- 
2.31.1



More information about the Devel mailing list