Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5255362imu; Tue, 15 Jan 2019 14:11:00 -0800 (PST) X-Google-Smtp-Source: ALg8bN4Yz9+dUqLVLHPT/3/4xl671uSRD/ghoDhoRyPi8RWs/wwH/Q7lRlxkIFNicg7qPpZq4GrH X-Received: by 2002:a17:902:2ec1:: with SMTP id r59mr6461706plb.254.1547590260081; Tue, 15 Jan 2019 14:11:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547590260; cv=none; d=google.com; s=arc-20160816; b=rccT/hODJcw5xIV/BbFH5r/Rw3k+5vgQkhAk3Vrcf4sYt8zKUQ4VKx7LgTXsbdbNaC UfkVESfz7KRn89yuBtsIeNgtIXlsx9Zq9pvRdNWckJGB75ElvFJMwtQ3/Zij1zA6tjSA +0fA3zEXhkvCUKW5E5phP2UQKj51G4JPZsyqKMx1+Pl0Tdwkr1aguLx4Cx+odYwp73wd 2Jcw+QUdtWSkkeDbNSGa2Ge8rcyVicbA+p2PEfjbhK0m3TjQzRn+WJjcUA+n4fJ0sYgY CkXyiOQfh7ZoP4IqpAni0k1Ts5lumMU3TLdTPc8QML2BBD2pVl8xFCogqfz8Nj2BVf0l C82w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Y6EEJTVfR6eTmQoew8SqmOeYLww6K6gSemd73DXSnU0=; b=Z3MrjNuAYbH2Sx4j2g3lnXtthYrtytX+tchw7EjiHqyot/Q/XK9tHHzP7G5q4PTfBb D1G4L/1RqUlkuJWxAeutHkjsn0vrsG4Z+KwZTkrZF8w56ienaNibfAirzhDuCuZ2hunZ 1lXznAVHSopDUNlOSf7K2qvR0UiqsbLKOdhJqoWEo317CReyvjvDnEfDFwGH1AU6jVsD JACX+iDi1Fb4+6BIVxJvyaEcy5/mHS3JGwtAfBMo+WB1bTD9GXIMiqBjbFLgX9Pe3VaZ Z0XQgKgaoAD8J5QOmA9eGN/67KgPXsLPcGaz7LLh30u6t85DZKQfV3wCO5fsNMl0JUXi RHLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Jmr5JqOL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j29si4175314pgm.554.2019.01.15.14.10.43; Tue, 15 Jan 2019 14:11:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Jmr5JqOL; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731879AbfAOQrq (ORCPT + 99 others); Tue, 15 Jan 2019 11:47:46 -0500 Received: from mail.kernel.org ([198.145.29.99]:35002 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387758AbfAOQpS (ORCPT ); Tue, 15 Jan 2019 11:45:18 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 354142054F; Tue, 15 Jan 2019 16:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1547570717; bh=Y+JnD15Ddw4Ag10QCxHlrSikPeErEfspmeczg28CvEQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jmr5JqOLhahQKNi6GcRCnFP+jvz0R24RcraKvrYQcg20ixQ50S0Eje47NIqiTCaT/ NGlj16SCNZDIVz1XteDqlvVS0QODbNjqBI0qWqOlMU6n+Avb2zPsmPDljxKgKnJ3PT 0rQt9WMwX0DjmIBpCX+bbjgOpe7tiiMdSP648dzk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ilya Dryomov , Dongsheng Yang Subject: [PATCH 4.20 46/57] rbd: dont return 0 on unmap if RBD_DEV_FLAG_REMOVING is set Date: Tue, 15 Jan 2019 17:36:27 +0100 Message-Id: <20190115154913.547084607@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190115154910.734892368@linuxfoundation.org> References: <20190115154910.734892368@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Ilya Dryomov commit 85f5a4d666fd9be73856ed16bb36c5af5b406b29 upstream. There is a window between when RBD_DEV_FLAG_REMOVING is set and when the device is removed from rbd_dev_list. During this window, we set "already" and return 0. Returning 0 from write(2) can confuse userspace tools because 0 indicates that nothing was written. In particular, "rbd unmap" will retry the write multiple times a second: 10:28:05.463299 write(4, "0", 1) = 0 10:28:05.463509 write(4, "0", 1) = 0 10:28:05.463720 write(4, "0", 1) = 0 10:28:05.463942 write(4, "0", 1) = 0 10:28:05.464155 write(4, "0", 1) = 0 Cc: stable@vger.kernel.org Signed-off-by: Ilya Dryomov Tested-by: Dongsheng Yang Signed-off-by: Greg Kroah-Hartman --- drivers/block/rbd.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -5986,7 +5986,6 @@ static ssize_t do_rbd_remove(struct bus_ struct list_head *tmp; int dev_id; char opt_buf[6]; - bool already = false; bool force = false; int ret; @@ -6019,13 +6018,13 @@ static ssize_t do_rbd_remove(struct bus_ spin_lock_irq(&rbd_dev->lock); if (rbd_dev->open_count && !force) ret = -EBUSY; - else - already = test_and_set_bit(RBD_DEV_FLAG_REMOVING, - &rbd_dev->flags); + else if (test_and_set_bit(RBD_DEV_FLAG_REMOVING, + &rbd_dev->flags)) + ret = -EINPROGRESS; spin_unlock_irq(&rbd_dev->lock); } spin_unlock(&rbd_dev_list_lock); - if (ret < 0 || already) + if (ret) return ret; if (force) {