From patchwork Tue Jan 8 19:39:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 10752781 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C9B7D6C5 for ; Tue, 8 Jan 2019 19:40:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BA9C028F9D for ; Tue, 8 Jan 2019 19:40:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AEE7C28FB2; Tue, 8 Jan 2019 19:40:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FAAA28F9D for ; Tue, 8 Jan 2019 19:40:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732500AbfAHTkV (ORCPT ); Tue, 8 Jan 2019 14:40:21 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:36183 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728746AbfAHTkO (ORCPT ); Tue, 8 Jan 2019 14:40:14 -0500 Received: by mail-wr1-f66.google.com with SMTP id u4so5284260wrp.3 for ; Tue, 08 Jan 2019 11:40:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=NL+JUkFLWB9Vb+SzZ9qllQdqgAZNSmTieS18TTnLCkc=; b=U1j2WYVnKCn1wwhGcbBrm9kLeJ51NIAkB6+926/OgCTLhZ9aq1GC1VX8lG/R8b9/aY uj8maFLnwAW3lwHd1HwWlRF+R+Glx5HTxNgCE+cAQesucA1vr+6bn3fomMFy5yk3EbEs 8CKSdaexY3QPBT0XWLvd1GeP/rZzmjoxOdbBhPX4XD0HtfkEihZgqEWKJcm1E0QpizIX gpO+gQq8mpf8wklDv/KHJ0ABkn8jNPHsTpI7LWOp78vglqTLmUkH9aw/VLs36aUrJDYj Ak7y4UoT5737fhIX3bGG0L6z+32fQRRQ9df16JwXSIBTUmxn8zwchumER5UO5IT2xyk/ qocQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=NL+JUkFLWB9Vb+SzZ9qllQdqgAZNSmTieS18TTnLCkc=; b=QPeD2QbdWwRt3hyO6xiG8cucDUfuLxifIY73WLplw2BSfzkAqkJvXJpveWSjEg30GA M/haWKRrrKWOaKGmoMHfcje8K+arK2vrbk8vhe2t/Ojzg/o86giXQEYcEih9dG7qnqLp omtn7fhCRROMUeRym+kHtYmWnYX3Zi5GPHxPlLy5Y636cVvfmYHtiqitbL2Y1oHkIGAe Qyn3LoDABgbcY8RfaBUEN48sVYsRGKFXl/VQ3FkUOmTyjtqSHE8hzZRuD2i6xpl3/01S d0icDRiyuDpRXPRZmmxNUeuBdrTmqJUXi/bYmHLuj/GjDVMefBA9GNwks/fKyNj3+BFm GD8w== X-Gm-Message-State: AJcUukfpSIUwvn1W4FC5ee6fABXmLHRyP/1MCRTbg4+kz74300ZfmmPX OAsBT/sZpYKl7FyjOZ2K78u8xKpj X-Google-Smtp-Source: ALg8bN5o5UJpdBUX9cvZGvAMGPVmpo2GtrVF09H2KkDpk/7/TB1EHz6fFmvNUQYz39PW5LjJc8nu5Q== X-Received: by 2002:adf:f691:: with SMTP id v17mr2351642wrp.114.1546976412091; Tue, 08 Jan 2019 11:40:12 -0800 (PST) Received: from orange.local (ip-89-102-68-132.net.upcbroadband.cz. [89.102.68.132]) by smtp.gmail.com with ESMTPSA id w6sm11397952wme.46.2019.01.08.11.40.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 08 Jan 2019 11:40:11 -0800 (PST) From: Ilya Dryomov To: ceph-devel@vger.kernel.org Cc: Alex Elder Subject: [PATCH] rbd: don't return 0 on unmap if RBD_DEV_FLAG_REMOVING is set Date: Tue, 8 Jan 2019 20:39:42 +0100 Message-Id: <20190108193942.29715-1-idryomov@gmail.com> X-Mailer: git-send-email 2.14.4 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/block/rbd.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 63f73e8a1ab5..2f91dee0ab5f 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -5986,7 +5986,6 @@ static ssize_t do_rbd_remove(struct bus_type *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_type *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) {