Skip to contentSkip to conversation

target/tcmu: Adds a timeout for the completion of netlink command reply

PATCH Superseded Kenjiro Nakayama 2 participants 2 messages Sep 13, 2017

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/tcmu: Adds a timeout for the completion of netlink command reply

This patch adds a timeout for the completion of netlink command reply.

Current code waits for the netlink reply from userspace and the status change, but it hangs forever when userspace failed to reply. To fix this issue, this patch replace wait_for_completion with wait_for_completion_timeout.

---
 drivers/target/target_core_user.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/target/target_core_user.c +6 -1
index 942d094269fb..284294340167 100644
@@ -1333,7 +1333,12 @@ static int tcmu_wait_genl_cmd_reply(struct tcmu_dev *udev)
 		return 0;
 
 	pr_debug("sleeping for nl reply\n");
-	wait_for_completion(&nl_cmd->complete);
+	ret = wait_for_completion_timeout(&nl_cmd->complete,
+			msecs_to_jiffies(3000));
+	if (!ret) {
+		printk(KERN_ERR "timeout waiting for nl reply from userspace\n");
+		return -ETIME;
+	}
 
 	spin_lock(&udev->nl_cmd_lock);
 	nl_cmd->cmd = TCMU_CMD_UNSPEC;
Signature · 1 line
2.13.5
#1 lore raw
Quoted 18 lines · Kenjiro Nakayama

This patch adds a timeout for the completion of netlink command reply.

Current code waits for the netlink reply from userspace and the status change, but it hangs forever when userspace failed to reply. To fix this issue, this patch replace wait_for_completion with wait_for_completion_timeout.

---
 drivers/target/target_core_user.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/target/target_core_user.c +0 -0
index 942d094269fb..284294340167 100644
@@ -1333,7 +1333,12 @@ static int tcmu_wait_genl_cmd_reply(struct tcmu_dev *udev)
 		return 0;

drivers/target/target_core_user.c static int tcmu_wait_genl_cmd_reply(struct tcmu_dev *udev) · line 1342

Quoted 10 lines
drivers/target/target_core_user.c +6 -1
 
 	pr_debug("sleeping for nl reply\n");
-	wait_for_completion(&nl_cmd->complete);
+	ret = wait_for_completion_timeout(&nl_cmd->complete,
+			msecs_to_jiffies(3000));
+	if (!ret) {
+		printk(KERN_ERR "timeout waiting for nl reply from userspace\n");
+		return -ETIME;
+	}
 

30 sec is too short. You have to make this configurable, because tcmu does not know how long it will take userspace to complete the requested task. For a clustered device it can take a while.