All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gioh Kim <gi-oh.kim@ionos.com>
To: linux-block@vger.kernel.org
Cc: axboe@kernel.dk, hch@infradead.org, sagi@grimberg.me,
	bvanassche@acm.org, haris.iqbal@ionos.com, jinpu.wang@ionos.com,
	Gioh Kim <gi-oh.kim@cloud.ionos.com>,
	Jack Wang <jinpu.wang@cloud.ionos.com>
Subject: [PATCH for-rc 03/24] block/rnbd: Enable the fault-injection
Date: Thu, 25 Mar 2021 16:28:50 +0100	[thread overview]
Message-ID: <20210325152911.1213627-4-gi-oh.kim@ionos.com> (raw)
In-Reply-To: <20210325152911.1213627-1-gi-oh.kim@ionos.com>

From: Gioh Kim <gi-oh.kim@cloud.ionos.com>

This patch introduces functions to enable the fault-injection for RTRS.
* rnbd_fault_inject_init/final: initialize the fault-injection
and create a debugfs directory.
* rnbd_fault_inject_add: create a debugfs entry to enable
the fault-injection point.

Signed-off-by: Gioh Kim <gi-oh.kim@cloud.ionos.com>
Signed-off-by: Jack Wang <jinpu.wang@cloud.ionos.com>
---
 drivers/block/rnbd/rnbd-common.c | 44 ++++++++++++++++++++++++++++++++
 drivers/block/rnbd/rnbd-proto.h  | 14 ++++++++++
 2 files changed, 58 insertions(+)

diff --git a/drivers/block/rnbd/rnbd-common.c b/drivers/block/rnbd/rnbd-common.c
index 596c3f732403..84bfbf015f6d 100644
--- a/drivers/block/rnbd/rnbd-common.c
+++ b/drivers/block/rnbd/rnbd-common.c
@@ -21,3 +21,47 @@ const char *rnbd_access_mode_str(enum rnbd_access_mode mode)
 		return "unknown";
 	}
 }
+
+#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
+static DECLARE_FAULT_ATTR(fail_default_attr);
+
+void rnbd_fault_inject_init(struct rnbd_fault_inject *fj,
+			    const char *dir_name,
+			    u32 err_status)
+{
+	struct dentry *dir, *parent;
+	struct fault_attr *attr = &fj->attr;
+
+	/* create debugfs directory and attribute */
+	parent = debugfs_create_dir(dir_name, NULL);
+	if (!parent) {
+		pr_warn("%s: failed to create debugfs directory\n", dir_name);
+		return;
+	}
+
+	*attr = fail_default_attr;
+	dir = fault_create_debugfs_attr("fault_inject", parent, attr);
+	if (IS_ERR(dir)) {
+		pr_warn("%s: failed to create debugfs attr\n", dir_name);
+		debugfs_remove_recursive(parent);
+		return;
+	}
+	fj->parent = parent;
+	fj->dir = dir;
+
+	/* create debugfs for status code */
+	fj->status = err_status;
+	debugfs_create_u32("status", 0600, dir,	&fj->status);
+}
+
+void rnbd_fault_inject_add(struct dentry *dir, const char *fname, bool *value)
+{
+	debugfs_create_bool(fname, 0600, dir, value);
+}
+
+void rnbd_fault_inject_final(struct rnbd_fault_inject *fj)
+{
+	/* remove debugfs directories */
+	debugfs_remove_recursive(fj->parent);
+}
+#endif
diff --git a/drivers/block/rnbd/rnbd-proto.h b/drivers/block/rnbd/rnbd-proto.h
index c1bc5c0fef71..d13dc1d3a00e 100644
--- a/drivers/block/rnbd/rnbd-proto.h
+++ b/drivers/block/rnbd/rnbd-proto.h
@@ -15,6 +15,7 @@
 #include <linux/inet.h>
 #include <linux/in.h>
 #include <linux/in6.h>
+#include <linux/fault-inject.h>
 #include <rdma/ib.h>
 
 #define RNBD_PROTO_VER_MAJOR 2
@@ -305,6 +306,19 @@ static inline u32 rq_to_rnbd_flags(struct request *rq)
 	return rnbd_opf;
 }
 
+struct rnbd_fault_inject {
+#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
+	struct fault_attr attr;
+	struct dentry *parent;
+	struct dentry *dir;
+	u32 status;
+#endif
+};
+
 const char *rnbd_access_mode_str(enum rnbd_access_mode mode);
 
+void rnbd_fault_inject_init(struct rnbd_fault_inject *fj,
+			    const char *dev_name, u32 err_status);
+void rnbd_fault_inject_add(struct dentry *dir, const char *fname, bool *value);
+void rnbd_fault_inject_final(struct rnbd_fault_inject *fj);
 #endif /* RNBD_PROTO_H */
-- 
2.25.1


  parent reply	other threads:[~2021-03-25 15:31 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-25 15:28 [PATCH for-rc 00/24] Misc update for rnbd Gioh Kim
2021-03-25 15:28 ` [PATCH for-rc 01/24] MAINTAINERS: Change maintainer for rnbd module Gioh Kim
2021-03-25 15:28 ` [PATCH for-rc 02/24] Documentation/sysfs-block-rnbd: Add descriptions for remap_device and resize Gioh Kim
2021-03-25 15:28 ` Gioh Kim [this message]
2021-03-25 15:28 ` [PATCH for-rc 04/24] block/rnbd-srv: Inject a fault at bio processing Gioh Kim
2021-03-25 15:28 ` [PATCH for-rc 05/24] block/rnbd-clt: Inject some fault points Gioh Kim
2021-03-25 15:28 ` [PATCH for-rc 06/24] docs: fault-injection: Add fault-injection manual of RNBD Gioh Kim
2021-03-25 15:28 ` [PATCH for-rc 07/24] docs: Add RTRS/RNBD to the index of fault-injection Gioh Kim
2021-03-25 15:28 ` [PATCH for-rc 08/24] block/rnbd-clt: Remove some arguments from insert_dev_if_not_exists_devpath Gioh Kim
2021-03-25 15:28 ` [PATCH for-rc 09/24] block/rnbd-clt: Remove some arguments from rnbd_client_setup_device Gioh Kim
2021-03-25 15:28 ` [PATCH for-rc 10/24] block/rnbd-clt: Move add_disk(dev->gd) to rnbd_clt_setup_gen_disk Gioh Kim
2021-03-25 15:28 ` [PATCH for-rc 11/24] block/rnbd: Kill rnbd_clt_destroy_default_group Gioh Kim
2021-03-25 15:28 ` [PATCH for-rc 12/24] block/rnbd: Kill destroy_device_cb Gioh Kim
2021-03-25 15:29 ` [PATCH for-rc 13/24] block/rnbd-clt: Replace {NO_WAIT,WAIT} with RTRS_PERMIT_{WAIT,NOWAIT} Gioh Kim
2021-03-25 16:12   ` Leon Romanovsky
2021-03-25 16:23     ` Gioh Kim
2021-03-25 15:29 ` [PATCH for-rc 14/24] block/rnbd-srv: Prevent a deadlock generated by accessing sysfs in parallel Gioh Kim
2021-03-25 15:29 ` [PATCH for-rc 15/24] block/rnbd-srv: Remove force_close file after holding a lock Gioh Kim
2021-03-25 15:29 ` [PATCH for-rc 16/24] block/rnbd-clt: Improve find_or_create_sess() return check Gioh Kim
2021-03-25 15:29 ` [PATCH for-rc 17/24] block/rnbd-clt: Fix missing a memory free when unloading the module Gioh Kim
2021-03-25 15:29 ` [PATCH for-rc 18/24] block/rnbd-clt: Support polling mode for IO latency optimization Gioh Kim
2021-03-25 15:29 ` [PATCH for-rc 19/24] Documentation/ABI/rnbd-clt: Add description for nr_poll_queues Gioh Kim
2021-03-25 15:29 ` [PATCH for-rc 20/24] block/rnbd-srv: Remove unused arguments of rnbd_srv_rdma_ev Gioh Kim
2021-03-25 15:29 ` [PATCH for-rc 21/24] block/rnbd-clt: Generate kobject_uevent when the rnbd device state changes Gioh Kim
2021-03-25 15:29 ` [PATCH for-rc 22/24] block/rnbd-clt: Remove max_segment_size Gioh Kim
2021-03-25 15:29 ` [PATCH for-rc 23/24] block/rnbd-clt-sysfs: Remove copy buffer overlap in rnbd_clt_get_path_name Gioh Kim
2021-03-25 15:29 ` [PATCH for-rc 24/24] block/rnbd: Use strscpy instead of strlcpy Gioh Kim

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210325152911.1213627-4-gi-oh.kim@ionos.com \
    --to=gi-oh.kim@ionos.com \
    --cc=axboe@kernel.dk \
    --cc=bvanassche@acm.org \
    --cc=gi-oh.kim@cloud.ionos.com \
    --cc=haris.iqbal@ionos.com \
    --cc=hch@infradead.org \
    --cc=jinpu.wang@cloud.ionos.com \
    --cc=jinpu.wang@ionos.com \
    --cc=linux-block@vger.kernel.org \
    --cc=sagi@grimberg.me \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.