[Devel] [PATCH v1] Allow all ploop functions for fault injection

Alexander Atanasov alexander.atanasov at virtuozzo.com
Mon Aug 15 12:33:40 MSK 2022


Signed-off-by: Alexander Atanasov <alexander.atanasov at virtuozzo.com>
---
 drivers/md/dm-ploop-bat.c    | 10 ++++++++++
 drivers/md/dm-ploop-cmd.c    | 21 +++++++++++++++++++--
 drivers/md/dm-ploop-map.c    | 11 +++++++++++
 drivers/md/dm-ploop-target.c |  7 +++++++
 4 files changed, 47 insertions(+), 2 deletions(-)

To be applied after the previous cleanup patch

diff --git a/drivers/md/dm-ploop-bat.c b/drivers/md/dm-ploop-bat.c
index fed024f8ab36..dd1840f4e57a 100644
--- a/drivers/md/dm-ploop-bat.c
+++ b/drivers/md/dm-ploop-bat.c
@@ -8,6 +8,7 @@
 #include <linux/init.h>
 #include <linux/file.h>
 #include <linux/uio.h>
+#include <linux/error-injection.h>
 #include <linux/mm.h>
 #include "dm-ploop.h"
 
@@ -30,6 +31,7 @@ struct md_page *ploop_md_page_find(struct ploop *ploop, u32 id)
 
 	return NULL;
 }
+ALLOW_ERROR_INJECTION(ploop_md_page_find, NULL);
 
 static void __md_page_insert(struct rb_root *root, struct md_page *new_md)
 {
@@ -93,6 +95,7 @@ static struct md_page *ploop_alloc_md_page(u32 id)
 	kfree(md);
 	return NULL;
 }
+ALLOW_ERROR_INJECTION(ploop_alloc_md_page, NULL);
 
 void ploop_free_md_page(struct md_page *md)
 {
@@ -175,6 +178,7 @@ static int ploop_setup_holes_bitmap(struct ploop *ploop, u32 bat_clusters)
 
 	return 0;
 }
+ALLOW_ERROR_INJECTION(ploop_setup_holes_bitmap, ERRNO);
 
 int ploop_setup_metadata(struct ploop *ploop, struct page *page)
 {
@@ -228,6 +232,7 @@ int ploop_setup_metadata(struct ploop *ploop, struct page *page)
 		kunmap(page);
 	return ret;
 }
+ALLOW_ERROR_INJECTION(ploop_setup_metadata, ERRNO);
 
 static int ploop_delta_check_header(struct ploop *ploop,
 				    struct rb_root *md_root,
@@ -261,6 +266,7 @@ static int ploop_delta_check_header(struct ploop *ploop,
 	kunmap(md0->page);
 	return ret;
 }
+ALLOW_ERROR_INJECTION(ploop_delta_check_header, ERRNO);
 
 static int ploop_convert_bat_entries(struct ploop *ploop, struct rb_root *md_root,
 			       u32 nr_be, u32 nr_pages, loff_t file_size)
@@ -297,6 +303,7 @@ static int ploop_convert_bat_entries(struct ploop *ploop, struct rb_root *md_roo
 
 	return ret;
 }
+ALLOW_ERROR_INJECTION(ploop_convert_bat_entries, ERRNO);
 
 int ploop_read_delta_metadata(struct ploop *ploop, struct file *file,
 			      struct rb_root *md_root, u32 *delta_nr_be_ret)
@@ -374,6 +381,7 @@ int ploop_read_delta_metadata(struct ploop *ploop, struct file *file,
 		kvfree(bvec);
 	return ret;
 }
+ALLOW_ERROR_INJECTION(ploop_read_delta_metadata, ERRNO);
 
 static void ploop_set_not_hole(struct ploop *ploop, u32 dst_clu)
 {
@@ -463,6 +471,7 @@ int ploop_check_delta_length(struct ploop *ploop, struct file *file, loff_t *fil
 	*file_size = loff;
 	return 0;
 }
+ALLOW_ERROR_INJECTION(ploop_check_delta_length, ERRNO)
 
 /*
  * @fd refers to a new delta, which is placed right before top_delta.
@@ -504,3 +513,4 @@ int ploop_add_delta(struct ploop *ploop, u32 level, struct file *file, bool is_r
 	ploop_free_md_pages_tree(&md_root);
 	return ret;
 }
+ALLOW_ERROR_INJECTION(ploop_add_delta, ERRNO);
diff --git a/drivers/md/dm-ploop-cmd.c b/drivers/md/dm-ploop-cmd.c
index 0554076def59..c98a0f8a3559 100644
--- a/drivers/md/dm-ploop-cmd.c
+++ b/drivers/md/dm-ploop-cmd.c
@@ -7,6 +7,7 @@
 
 #include <linux/init.h>
 #include <linux/file.h>
+#include <linux/error-injection.h>
 #include <linux/uio.h>
 #include <linux/ctype.h>
 #include <linux/umh.h>
@@ -119,6 +120,7 @@ static int ploop_inflight_bios_ref_switch(struct ploop *ploop, bool killable)
 	percpu_ref_reinit(&ploop->inflight_bios_ref[index]);
 	return 0;
 }
+ALLOW_ERROR_INJECTION(ploop_inflight_bios_ref_switch, ERRNO);
 
 static void ploop_resume_submitting_pios(struct ploop *ploop)
 {
@@ -147,6 +149,7 @@ static int ploop_suspend_submitting_pios(struct ploop *ploop)
 		ploop_resume_submitting_pios(ploop);
 	return ret;
 }
+ALLOW_ERROR_INJECTION(ploop_suspend_submitting_pios, ERRNO);
 
 /* Find existing BAT clu pointing to dst_clu */
 static u32 ploop_find_bat_entry(struct ploop *ploop, u32 dst_clu, bool *is_locked)
@@ -225,6 +228,7 @@ static int ploop_read_cluster_sync(struct ploop *ploop, struct pio *pio,
 
 	return 0;
 }
+ALLOW_ERROR_INJECTION(ploop_read_cluster_sync, ERRNO);
 
 static int ploop_write_cluster_sync(struct ploop *ploop, struct pio *pio,
 				    u32 dst_clu)
@@ -251,6 +255,7 @@ static int ploop_write_cluster_sync(struct ploop *ploop, struct pio *pio,
 
 	return vfs_fsync(file, 0);
 }
+ALLOW_ERROR_INJECTION(ploop_write_cluster_sync, ERRNO);
 
 static int ploop_write_zero_cluster_sync(struct ploop *ploop,
 					 struct pio *pio, u32 clu)
@@ -358,6 +363,7 @@ static int ploop_grow_relocate_cluster(struct ploop *ploop,
 out:
 	return ret;
 }
+ALLOW_ERROR_INJECTION(ploop_grow_relocate_cluster, ERRNO);
 
 static int ploop_grow_update_header(struct ploop *ploop,
 				    struct ploop_cmd *cmd)
@@ -411,13 +417,14 @@ static int ploop_grow_update_header(struct ploop *ploop,
 
 	return ret;
 }
+ALLOW_ERROR_INJECTION(ploop_grow_update_header, ERRNO);
 
 static void ploop_add_md_pages(struct ploop *ploop, struct rb_root *from)
 {
 	struct rb_node *node;
-        struct md_page *md;
+	struct md_page *md;
 
-        while ((node = from->rb_node) != NULL) {
+	while ((node = from->rb_node) != NULL) {
 		md = rb_entry(node, struct md_page, node);
 		rb_erase(node, from);
 		ploop_md_page_insert(ploop, md);
@@ -464,6 +471,7 @@ static int ploop_process_resize_cmd(struct ploop *ploop, struct ploop_cmd *cmd)
 
 	return ret;
 }
+ALLOW_ERROR_INJECTION(ploop_process_resize_cmd, ERRNO);
 
 struct pio *ploop_alloc_pio_with_pages(struct ploop *ploop)
 {
@@ -495,6 +503,7 @@ struct pio *ploop_alloc_pio_with_pages(struct ploop *ploop)
 	kfree(pio);
 	return NULL;
 }
+ALLOW_ERROR_INJECTION(ploop_alloc_pio_with_pages, NULL);
 
 void ploop_free_pio_with_pages(struct ploop *ploop, struct pio *pio)
 {
@@ -599,6 +608,8 @@ static int ploop_resize(struct ploop *ploop, sector_t new_sectors)
 	ploop_free_md_pages_tree(&cmd.resize.md_pages_root);
 	return ret;
 }
+ALLOW_ERROR_INJECTION(ploop_resize, ERRNO);
+
 static void service_pio_endio(struct pio *pio, void *data, blk_status_t status)
 {
 	struct ploop *ploop = pio->ploop;
@@ -665,6 +676,7 @@ static int ploop_process_merge_latest_snapshot(struct ploop *ploop)
 
 	return ret;
 }
+ALLOW_ERROR_INJECTION(ploop_process_merge_latest_snapshot, ERRNO);
 
 static int ploop_merge_latest_snapshot(struct ploop *ploop)
 {
@@ -700,6 +712,7 @@ static int ploop_merge_latest_snapshot(struct ploop *ploop)
 out:
 	return ret;
 }
+ALLOW_ERROR_INJECTION(ploop_merge_latest_snapshot, ERRNO);
 
 static void notify_delta_merged(struct ploop *ploop, u8 level,
 				struct rb_root *md_root,
@@ -803,6 +816,7 @@ static int ploop_process_update_delta_index(struct ploop *ploop, u8 level,
 	write_unlock_irq(&ploop->bat_rwlock);
 	return ret;
 }
+ALLOW_ERROR_INJECTION(ploop_process_update_delta_index, ERRNO);
 
 static int ploop_delta_clusters_merged(struct ploop *ploop, u8 level,
 				       bool forward)
@@ -848,6 +862,7 @@ static int ploop_delta_clusters_merged(struct ploop *ploop, u8 level,
 	ploop_free_md_pages_tree(&md_root);
 	return ret;
 }
+ALLOW_ERROR_INJECTION(ploop_delta_clusters_merged, ERRNO);
 
 static int ploop_notify_merged(struct ploop *ploop, u8 level, bool forward)
 {
@@ -914,6 +929,7 @@ static int ploop_get_delta_name_cmd(struct ploop *ploop, u8 level,
 out:
 	return ret;
 }
+ALLOW_ERROR_INJECTION(ploop_get_delta_name_cmd, ERRNO_NULL);
 
 static int ploop_update_delta_index(struct ploop *ploop, unsigned int level,
 				    const char *map)
@@ -946,6 +962,7 @@ static int ploop_update_delta_index(struct ploop *ploop, unsigned int level,
 out:
 	return ret;
 }
+ALLOW_ERROR_INJECTION(ploop_update_delta_index, ERRNO);
 
 static int process_flip_upper_deltas(struct ploop *ploop)
 {
diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index ba678aaa01fc..56aa98991068 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -13,6 +13,7 @@
 #include <linux/blk-cgroup.h>
 #include <linux/init.h>
 #include <linux/vmalloc.h>
+#include <linux/error-injection.h>
 #include <linux/uio.h>
 #include <linux/blk-mq.h>
 #include <uapi/linux/falloc.h>
@@ -110,6 +111,7 @@ static int ploop_rq_valid(struct ploop *ploop, struct request *rq)
 
 	return 0;
 }
+ALLOW_ERROR_INJECTION(ploop_rq_valid, ERRNO);
 
 static void ploop_init_prq(struct ploop_rq *prq, struct request *rq)
 {
@@ -288,6 +290,7 @@ static struct pio *ploop_split_and_chain_pio(struct ploop *ploop,
 		ploop_pio_advance(pio, len);
 	return split;
 }
+ALLOW_ERROR_INJECTION(ploop_split_and_chain_pio, NULL);
 
 static int ploop_split_pio_to_list(struct ploop *ploop, struct pio *pio,
 			     struct list_head *ret_list)
@@ -325,6 +328,7 @@ static int ploop_split_pio_to_list(struct ploop *ploop, struct pio *pio,
 	}
 	return -ENOMEM;
 }
+ALLOW_ERROR_INJECTION(ploop_split_pio_to_list, ERRNO);
 
 static void ploop_dispatch_pio(struct ploop *ploop, struct pio *pio,
 			 bool *is_data, bool *is_flush)
@@ -422,6 +426,7 @@ struct pio *ploop_find_pio(struct hlist_head head[], u32 clu)
 
 	return NULL;
 }
+ALLOW_ERROR_INJECTION(ploop_find_pio, NULL);
 
 static struct pio *ploop_find_inflight_bio(struct ploop *ploop, u32 clu)
 {
@@ -983,6 +988,7 @@ static int ploop_find_dst_clu_bit(struct ploop *ploop,
 	*ret_dst_clu = dst_clu;
 	return 0;
 }
+ALLOW_ERROR_INJECTION(ploop_find_dst_clu_bit, ERRNO);
 
 static int ploop_truncate_prealloc_safe(struct ploop *ploop, struct ploop_delta *delta,
 				  loff_t len, const char *func)
@@ -1015,6 +1021,7 @@ static int ploop_truncate_prealloc_safe(struct ploop *ploop, struct ploop_delta
 	delta->file_preallocated_area_start = len;
 	return 0;
 }
+ALLOW_ERROR_INJECTION(ploop_truncate_prealloc_safe, ERRNO);
 
 static int ploop_allocate_cluster(struct ploop *ploop, u32 *dst_clu)
 {
@@ -1071,6 +1078,7 @@ static int ploop_allocate_cluster(struct ploop *ploop, u32 *dst_clu)
 	ploop_hole_clear_bit(*dst_clu, ploop);
 	return 0;
 }
+ALLOW_ERROR_INJECTION(ploop_allocate_cluster, ERRNO);
 
 /*
  * This finds a free dst_clu on origin device, and reflects this
@@ -1299,6 +1307,7 @@ static void ploop_initiate_cluster_cow(struct ploop *ploop, unsigned int level,
 	pio->bi_status = BLK_STS_RESOURCE;
 	ploop_pio_endio(pio);
 }
+ALLOW_ERROR_INJECTION(ploop_submit_cluster_cow, ERRNO);
 
 static void ploop_submit_cluster_write(struct ploop_cow *cow)
 {
@@ -1590,6 +1599,7 @@ static struct bio_vec *ploop_create_bvec_from_rq(struct request *rq)
 out:
 	return bvec;
 }
+ALLOW_ERROR_INJECTION(ploop_create_bvec_from_rq, NULL);
 
 static void ploop_prepare_one_embedded_pio(struct ploop *ploop,
 				struct pio *pio, struct list_head *deferred_pios)
@@ -1925,3 +1935,4 @@ int ploop_prepare_reloc_index_wb(struct ploop *ploop,
 out_error:
 	return err;
 }
+ALLOW_ERROR_INJECTION(ploop_prepare_reloc_index_wb, ERRNO);
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index 0e17a80ae1d6..bc4a801ca3a8 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -18,6 +18,7 @@
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
 #include <linux/uio.h>
+#include <linux/error-injection.h>
 #include "dm-ploop.h"
 
 #define DM_MSG_PREFIX "ploop"
@@ -104,6 +105,7 @@ int ploop_rw_page_sync(unsigned rw, struct file *file,
 
 	return ret;
 }
+ALLOW_ERROR_INJECTION(ploop_rw_page_sync, ERRNO);
 
 static void ploop_inflight_bios_ref_exit0(struct percpu_ref *ref)
 {
@@ -197,6 +199,7 @@ static struct file *ploop_get_delta_file(int fd)
 
 	return file;
 }
+ALLOW_ERROR_INJECTION(ploop_get_delta_file, ERRNO_NULL);
 
 static int ploop_check_top_delta(struct ploop *ploop, struct file *file)
 {
@@ -235,6 +238,7 @@ static int ploop_check_top_delta(struct ploop *ploop, struct file *file)
 		put_page(page);
 	return ret;
 }
+ALLOW_ERROR_INJECTION(ploop_check_top_delta, ERRNO);
 
 static int ploop_add_deltas_stack(struct ploop *ploop, char **argv, int argc)
 {
@@ -294,6 +298,7 @@ static int ploop_add_deltas_stack(struct ploop *ploop, char **argv, int argc)
 	fput(file);
 	goto out;
 }
+ALLOW_ERROR_INJECTION(ploop_add_deltas_stack, ERRNO);
 
 #define EAT_ARG(argc, argv)					\
 	do {							\
@@ -428,6 +433,7 @@ static int ploop_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 	ploop_destroy(ploop);
 	return ret;
 }
+ALLOW_ERROR_INJECTION(ploop_ctr, ERRNO);
 
 static void ploop_dtr(struct dm_target *ti)
 {
@@ -539,6 +545,7 @@ static int ploop_preresume(struct dm_target *ti)
 	}
 	return ret;
 }
+ALLOW_ERROR_INJECTION(ploop_preresume, ERRNO);
 
 /*----------------------------------------------------------------*/
 
-- 
2.31.1



More information about the Devel mailing list