From: Gioh Kim <gi-oh.kim@xxxxxxxxxxxxxxx> If the fault is enabled, it sends an error to the client so that the client thinks the target device on the server has failed. Signed-off-by: Gioh Kim <gi-oh.kim@xxxxxxxxxxxxxxx> Signed-off-by: Jack Wang <jinpu.wang@xxxxxxxxxxxxxxx> --- drivers/block/rnbd/rnbd-srv-sysfs.c | 37 +++++++++++++++++++++++++++++ drivers/block/rnbd/rnbd-srv.c | 7 ++++++ drivers/block/rnbd/rnbd-srv.h | 13 ++++++++++ 3 files changed, 57 insertions(+) diff --git a/drivers/block/rnbd/rnbd-srv-sysfs.c b/drivers/block/rnbd/rnbd-srv-sysfs.c index 05ffe488ddc6..03fb26ac435e 100644 --- a/drivers/block/rnbd/rnbd-srv-sysfs.c +++ b/drivers/block/rnbd/rnbd-srv-sysfs.c @@ -253,3 +253,40 @@ void rnbd_srv_destroy_sysfs_files(void) device_destroy(rnbd_dev_class, MKDEV(0, 0)); class_destroy(rnbd_dev_class); } + +#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS +void rnbd_srv_fault_inject_init(struct rnbd_srv_fault_inject *fault_inject, + const char *dev_name) +{ + rnbd_fault_inject_init(&fault_inject->fj, dev_name, -EBUSY); + /* injection points */ + rnbd_fault_inject_add(fault_inject->fj.dir, + "fail-bio", &fault_inject->fail_bio); +} + +void rnbd_srv_fault_inject_fini(struct rnbd_srv_fault_inject *fault_inject) +{ + rnbd_fault_inject_final(&fault_inject->fj); +} + +int rnbd_should_fail_bio(struct rnbd_srv_sess_dev *sess_dev) +{ + struct rnbd_srv_fault_inject *fault_inject = &sess_dev->fault_inject; + + if (fault_inject->fail_bio && should_fail(&fault_inject->fj.attr, 1)) + return fault_inject->fj.status; + return 0; +} +#else +void rnbd_srv_fault_inject_init(struct rnbd_srv_fault_inject *fault_inj, + const char *dev_name) +{ +} +void rnbd_srv_fault_inject_fini(struct rnbd_srv_fault_inject *fault_inject) +{ +} +int rnbd_should_fail_bio(struct rnbd_srv_sess_dev *sess_dev) +{ + return 0; +} +#endif diff --git a/drivers/block/rnbd/rnbd-srv.c b/drivers/block/rnbd/rnbd-srv.c index a6a68d44f517..447fb0718525 100644 --- a/drivers/block/rnbd/rnbd-srv.c +++ b/drivers/block/rnbd/rnbd-srv.c @@ -88,9 +88,14 @@ void rnbd_endio(void *priv, int error) { struct rnbd_io_private *rnbd_priv = priv; struct rnbd_srv_sess_dev *sess_dev = rnbd_priv->sess_dev; + int fail_err = 0; rnbd_put_sess_dev(sess_dev); + fail_err = rnbd_should_fail_bio(sess_dev); + if (unlikely(fail_err)) /* over-write error which will be sent to client */ + error = fail_err; + rtrs_srv_resp_rdma(rnbd_priv->id, error); kfree(priv); @@ -230,6 +235,7 @@ void rnbd_destroy_sess_dev(struct rnbd_srv_sess_dev *sess_dev, bool keep_id) rnbd_put_sess_dev(sess_dev); wait_for_completion(&dc); /* wait for inflights to drop to zero */ + rnbd_srv_fault_inject_fini(&sess_dev->fault_inject); rnbd_dev_close(sess_dev->rnbd_dev); list_del(&sess_dev->sess_list); mutex_lock(&sess_dev->dev->lock); @@ -811,6 +817,7 @@ static int process_msg_open(struct rtrs_srv *rtrs, rnbd_srv_info(srv_sess_dev, "Opened device '%s'\n", srv_dev->id); kfree(full_path); + rnbd_srv_fault_inject_init(&srv_sess_dev->fault_inject, kbasename(srv_sess_dev->pathname)); fill_response: rnbd_srv_fill_msg_open_rsp(rsp, srv_sess_dev); diff --git a/drivers/block/rnbd/rnbd-srv.h b/drivers/block/rnbd/rnbd-srv.h index b157371c25ed..120e6d64cb82 100644 --- a/drivers/block/rnbd/rnbd-srv.h +++ b/drivers/block/rnbd/rnbd-srv.h @@ -45,6 +45,13 @@ struct rnbd_srv_dev { int open_write_cnt; }; +struct rnbd_srv_fault_inject { +#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS + struct rnbd_fault_inject fj; + bool fail_bio; +#endif +}; + /* Structure which binds N devices and N sessions */ struct rnbd_srv_sess_dev { /* Entry inside rnbd_srv_dev struct */ @@ -62,6 +69,7 @@ struct rnbd_srv_sess_dev { struct completion *destroy_comp; char pathname[NAME_MAX]; enum rnbd_access_mode access_mode; + struct rnbd_srv_fault_inject fault_inject; }; void rnbd_srv_sess_dev_force_close(struct rnbd_srv_sess_dev *sess_dev); @@ -77,4 +85,9 @@ int rnbd_srv_create_sysfs_files(void); void rnbd_srv_destroy_sysfs_files(void); void rnbd_destroy_sess_dev(struct rnbd_srv_sess_dev *sess_dev, bool keep_id); +void rnbd_srv_fault_inject_init(struct rnbd_srv_fault_inject *fault_inj, + const char *dev_name); +void rnbd_srv_fault_inject_fini(struct rnbd_srv_fault_inject *fault_inject); +int rnbd_should_fail_bio(struct rnbd_srv_sess_dev *sess_dev); + #endif /* RNBD_SRV_H */ -- 2.25.1