tcmu: release blocks for partially setup cmds

"Linux Kernel Mailing List" <[email protected]>
Newsgroups gmane.linux.kernel.commits.head
Message-ID <[email protected]>
Web:        https://git.kernel.org/torvalds/c/810b8153c4243d2012a6ec002ddd3bbc9a9ae8c2
Commit:     810b8153c4243d2012a6ec002ddd3bbc9a9ae8c2
Parent:     6fddcb775477bb2213bd76ab62145645eb570f33
Refname:    refs/heads/master
Author:     Mike Christie <[email protected]>
AuthorDate: Tue Nov 28 12:40:33 2017 -0600
Committer:  Nicholas Bellinger <[email protected]>
CommitDate: Fri Jan 12 15:07:14 2018 -0800

    tcmu: release blocks for partially setup cmds
    
    If we cannot setup a cmd because we run out of ring space
    or global pages release the blocks before sleeping. This
    prevents a deadlock where dev0 has waiting_blocks set and
    needs N blocks, but dev1 to devX have each allocated N / X blocks
    and also hit the global block limit so they went to sleep.
    
    find_free_blocks is not able to take the sleeping dev's
    blocks becaause their waiting_blocks is set and even
    if it was not the block returned by find_last_bit could equal
    dbi_max. The latter will probably never happen because
    DATA_BLOCK_BITS is so high but in the next patches
    DATA_BLOCK_BITS and TCMU_GLOBAL_MAX_BLOCKS will be settable so
    it might be lower and could happen.
    
    Signed-off-by: Mike Christie <[email protected]>
    Signed-off-by: Nicholas Bellinger <[email protected]>
---
 drivers/target/target_core_user.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/target/target_core_user.c b/drivers/target/target_core_user.c
index 43583a792439..c7541f090453 100644
--- a/drivers/target/target_core_user.c
+++ b/drivers/target/target_core_user.c
@@ -807,6 +807,13 @@ tcmu_queue_cmd_ring(struct tcmu_cmd *tcmu_cmd)
 		int ret;
 		DEFINE_WAIT(__wait);
 
+		/*
+		 * Don't leave commands partially setup because the unmap
+		 * thread might need the blocks to make forward progress.
+		 */
+		tcmu_cmd_free_data(tcmu_cmd, tcmu_cmd->dbi_cur);
+		tcmu_cmd_reset_dbi_cur(tcmu_cmd);
+
 		prepare_to_wait(&udev->wait_cmdr, &__wait, TASK_INTERRUPTIBLE);
 
 		pr_debug("sleeping for ring space\n");
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.