Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1370758ybl; Mon, 2 Dec 2019 02:26:29 -0800 (PST) X-Google-Smtp-Source: APXvYqx0SrVifxKjBUWK6mooAhdcOk7yeREXh7AuyYEYqcFfeKmActRcsMsmxOIpwXI/DqWEpZwV X-Received: by 2002:a17:906:248f:: with SMTP id e15mr16588686ejb.141.1575282389181; Mon, 02 Dec 2019 02:26:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575282389; cv=none; d=google.com; s=arc-20160816; b=YzS4zIbaVWa4RcRlBfYinOaeytIs7uUJTI0IMXQBW2aQWA/MSnls70pXyEkosa35yP AssfHjqec+uitwo7Y1qXfDBv2oHx5aHulNh4t40SutRymAWTCAuE+qkWrc4CNyyjjg6E 9bfP9f4O5r8cPVzmOAOEReobFHJuytq+ELhNWAzoZf6E1j1gYsFGDbkEALsdFOq19iip hOzs6V3FrObA77nbBd4Q6+v4qexMCu/FVq+1ZXKUJKSidgy7k56tCFS3KS/MID26tGYW 9QvdN0dE858Gx6rA0Vn3AIMMmr7tiKdhN7koyb3vTsngOEcJA0BC3g92EapQSwqlOUX0 dUVQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=m0LCE5hcVVGk8fjDfWm4sSuGTECQ8UothTBhXvlTHPM=; b=Awd7OvHMV9VxAFl56izSzVo/G9IOi8ARlUsOXz8Hdj7lzBaX36danxyTcfTY7bjz3X P63QSs6s493dI8nXxiI4/nUIxoxkckXRUmMmCAsiUnBm60JDpU9rvr5wJQ616JJyVRO8 NBnW2IK8gK1kZmvDi/wEAZQsU059J4WL76EHSNA0sNDfdV9OTqG4Fpe2mFMlHLYlOoLq EhUD8DMcKHv4KA6nle/auv4B+FjSd/UzHQ1btQzUuy+Pg6GHg/ryfYkeKluekDOskt9u X+DJdx8gAIAnY+WqG0kR8VfHTRRj2HlVfEBAYVYIffQetg1SZvQet6hqWfCppSpEDHej sz/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=novKqp8H; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u2si20008214ejo.137.2019.12.02.02.26.04; Mon, 02 Dec 2019 02:26:29 -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=@gmail.com header.s=20161025 header.b=novKqp8H; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727388AbfLBKYe (ORCPT + 99 others); Mon, 2 Dec 2019 05:24:34 -0500 Received: from mail-pg1-f194.google.com ([209.85.215.194]:36435 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726276AbfLBKYe (ORCPT ); Mon, 2 Dec 2019 05:24:34 -0500 Received: by mail-pg1-f194.google.com with SMTP id k13so18156711pgh.3; Mon, 02 Dec 2019 02:24:32 -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:mime-version :content-transfer-encoding; bh=m0LCE5hcVVGk8fjDfWm4sSuGTECQ8UothTBhXvlTHPM=; b=novKqp8HWeDTOaxtSE7iRnp+oxbOVTDKu5VeT7nuojFFq4Bja0+QGnvmpv8mMxF0lp CkdfBH7XWnDjZOgzL+Kpov4pkK53VNxDniXkeZEq6xTaau5HaS85SfIpSHxK/akRnYTN fiDUP8MSCTDw+m2YQZQMgwKC8tyJOVySc9qjLx/whf5c+XhT7D3eAZt6gP1Yp03sfEla h3n2g7lrWWlUZNBqq0HvK4tndbg+xuwLErgGNhniFb+l43lyACzQq/ktmkOOLpZgA5nn NzyV90EIzfCCg8GuVGCB6z4//8YEUroJVB2mv9d9bKe+lSQdG6I+kkpe0hlBVVZ/e5/X H07A== 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:mime-version :content-transfer-encoding; bh=m0LCE5hcVVGk8fjDfWm4sSuGTECQ8UothTBhXvlTHPM=; b=DOq0g4jvRkzB6VLecY1tE5LEW8NYx+DAueBQiZo4EoDQZnqKb6QxzKska+Iy8aphf+ 5VYoZgFHpeMzD9XD0WlXnKBL8OLfF0fIie5XT+a+l3h6PkTbY2KWU3ZbnD0Ji+O0fdf2 4jJgilP4HRzJ7P+F23pNzQEpbyHVwe4prr7V5MCAHnv41Bxv9TNOUFirJVUoSAZZwUPa suafrPi+qGWmqyPbzTnz+hahaOpejAl6bvAyLqkOfJLo3tZSSJ9mfO8tOw0jCnI+KvUz I381Tm7+Zrd9ll8Vom4cK4EGH1PnR4qpH8dIORecX4fgZFc/r0odV8tno6tj94P6l6/W elXw== X-Gm-Message-State: APjAAAWd9Jv/TeX2IC/l2EPGjqg9HA713ZmAyVGjV8wG6JSnutLcTQ1J ZdnFpENNJEvuTVayM5llvz8= X-Received: by 2002:a63:cc05:: with SMTP id x5mr31319016pgf.141.1575282272237; Mon, 02 Dec 2019 02:24:32 -0800 (PST) Received: from wangyang5-l1.corp.qihoo.net ([104.192.108.10]) by smtp.gmail.com with ESMTPSA id w2sm34639796pgm.18.2019.12.02.02.24.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Dec 2019 02:24:31 -0800 (PST) From: kungf To: colyli@suse.de Cc: kent.overstreet@gmail.com, linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, kungf Subject: [PATCH] bcache: add REQ_FUA to avoid data lost in writeback mode Date: Mon, 2 Dec 2019 18:24:09 +0800 Message-Id: <20191202102409.3980-1-wings.wyang@gmail.com> X-Mailer: git-send-email 2.17.1 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 data may lost when in the follow scene of writeback mode: 1. client write data1 to bcache 2. client fdatasync 3. bcache flush cache set and backing device if now data1 was not writed back to backing, it was only guaranteed safe in cache. 4.then cache writeback data1 to backing with only REQ_OP_WRITE So data1 was not guaranteed in non-volatile storage, it may lost if power interruptionĀ  Signed-off-by: kungf --- drivers/md/bcache/writeback.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c index 4a40f9eadeaf..e5cecb60569e 100644 --- a/drivers/md/bcache/writeback.c +++ b/drivers/md/bcache/writeback.c @@ -357,7 +357,7 @@ static void write_dirty(struct closure *cl) */ if (KEY_DIRTY(&w->key)) { dirty_init(w); - bio_set_op_attrs(&io->bio, REQ_OP_WRITE, 0); + bio_set_op_attrs(&io->bio, REQ_OP_WRITE | REQ_FUA, 0); io->bio.bi_iter.bi_sector = KEY_START(&w->key); bio_set_dev(&io->bio, io->dc->bdev); io->bio.bi_end_io = dirty_endio; -- 2.17.1