Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3052089ybi; Tue, 2 Jul 2019 01:11:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqz/1AGb/dvwpC9uEPyenN+pgP5ULtEWRZbrvwXg6WSPreUqM2rZ/Pcr2Ee6jT97my5pANe5 X-Received: by 2002:a17:902:a40c:: with SMTP id p12mr33870788plq.146.1562055074201; Tue, 02 Jul 2019 01:11:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562055074; cv=none; d=google.com; s=arc-20160816; b=RqmWr9U2OWOTzk05ESxs/Jm8Mz6AM6fUxQI5GWPSrv9fVcbb/ZGT/DpnJjclQKJHBN JxEw+obPJWFroboizpHrjT8ye+VppU+tBVwrm8Mlbt9gomEKx/7wtuzc2F+b96Aaz6Jz o7kgBNAoTMdDybtvtyLVk0913eXLn49+yyVHdVYjTU7g0gYrdxhrh9VfHAtoIJs9tBQV WUAQ8SuL/+l97kmrzfk310r6bSMgu6+cT1gHgBwl7nPdG9DrrM/IbcLk6ghRcseuaO5v +AwAGapk1UXCXavl2rj+aNTvm+QFZc5H4ntcJWGTw903vaOxZit8X3YQNukSB30W4Okd Fm3g== 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=/6GiEt61rhMtP/mpeTjZFSPns8S74Mk4EWlfCidaPf4=; b=0hCNfTz7IlzaiJak+2EYgY+W0ORS39FU9ENV83LwF4qa24xfwXF0rk7l6EGWa09ZL0 YQRGZwQzE1bUzdplOgDgKvYUKoCmxrGe4kgZ0aQZDxfiTcopcpvT7GDOFWCHwLWzDmgC SdD6Dsd9QyoQe6uJZ82yH7MDNDtP9+ri3QrRma2FdNhgtPXiSZxR3olIr2othsGPqOif uB7sAUaYgK5f7kdrZiyBB2d3/25Fadbo/nGqr+752KzWk5kJGbjlcmyJGVVqwAPXOvdf SVb/Klj4bZk/dbdYices00EcVa7HjVk+iLazMgD31TFoDQ2ZqnIkwiI10HwBlTCNpCuL xpzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oonXpVsK; 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 l13si1608236pjq.69.2019.07.02.01.10.59; Tue, 02 Jul 2019 01:11:14 -0700 (PDT) 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=oonXpVsK; 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 S1727812AbfGBIJr (ORCPT + 99 others); Tue, 2 Jul 2019 04:09:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:57694 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728091AbfGBIJn (ORCPT ); Tue, 2 Jul 2019 04:09:43 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.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 27B5A206A2; Tue, 2 Jul 2019 08:09:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562054982; bh=mEcSQA743o/+5T1M9riLJ9D6Uq5/D9wKIGLRBU3Iwiw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oonXpVsKejcXHekLTKIn/VMyMjZgXllMa39CgvpzeKuyUtx9VJVlaoI444oT7EDz5 S3wALHDzBwxjw1LBjzf+1zRPQhXiT8giT6/5TVzvOHNVRYRdM0VCRJ5LH2iHJdJjCg g9cuZD9mAPo4DxxeRtEDvQ7BBkKDe8Okkwfnj8x4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "zhangyi (F)" , Josef Bacik , Mike Snitzer Subject: [PATCH 4.14 20/43] dm log writes: make sure super sector log updates are written in order Date: Tue, 2 Jul 2019 10:02:00 +0200 Message-Id: <20190702080124.846911554@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190702080123.904399496@linuxfoundation.org> References: <20190702080123.904399496@linuxfoundation.org> User-Agent: quilt/0.66 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 From: zhangyi (F) commit 211ad4b733037f66f9be0a79eade3da7ab11cbb8 upstream. Currently, although we submit super bios in order (and super.nr_entries is incremented by each logged entry), submit_bio() is async so each super sector may not be written to log device in order and then the final nr_entries may be smaller than it should be. This problem can be reproduced by the xfstests generic/455 with ext4: QA output created by 455 -Silence is golden +mark 'end' does not exist Fix this by serializing submission of super sectors to make sure each is written to the log disk in order. Fixes: 0e9cebe724597 ("dm: add log writes target") Cc: stable@vger.kernel.org Signed-off-by: zhangyi (F) Suggested-by: Josef Bacik Reviewed-by: Josef Bacik Signed-off-by: Mike Snitzer Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm-log-writes.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) --- a/drivers/md/dm-log-writes.c +++ b/drivers/md/dm-log-writes.c @@ -57,6 +57,7 @@ #define WRITE_LOG_VERSION 1ULL #define WRITE_LOG_MAGIC 0x6a736677736872ULL +#define WRITE_LOG_SUPER_SECTOR 0 /* * The disk format for this is braindead simple. @@ -112,6 +113,7 @@ struct log_writes_c { struct list_head logging_blocks; wait_queue_head_t wait; struct task_struct *log_kthread; + struct completion super_done; }; struct pending_block { @@ -177,6 +179,14 @@ static void log_end_io(struct bio *bio) bio_put(bio); } +static void log_end_super(struct bio *bio) +{ + struct log_writes_c *lc = bio->bi_private; + + complete(&lc->super_done); + log_end_io(bio); +} + /* * Meant to be called if there is an error, it will free all the pages * associated with the block. @@ -212,7 +222,8 @@ static int write_metadata(struct log_wri bio->bi_iter.bi_size = 0; bio->bi_iter.bi_sector = sector; bio_set_dev(bio, lc->logdev->bdev); - bio->bi_end_io = log_end_io; + bio->bi_end_io = (sector == WRITE_LOG_SUPER_SECTOR) ? + log_end_super : log_end_io; bio->bi_private = lc; bio_set_op_attrs(bio, REQ_OP_WRITE, 0); @@ -334,11 +345,18 @@ static int log_super(struct log_writes_c super.nr_entries = cpu_to_le64(lc->logged_entries); super.sectorsize = cpu_to_le32(lc->sectorsize); - if (write_metadata(lc, &super, sizeof(super), NULL, 0, 0)) { + if (write_metadata(lc, &super, sizeof(super), NULL, 0, + WRITE_LOG_SUPER_SECTOR)) { DMERR("Couldn't write super"); return -1; } + /* + * Super sector should be writen in-order, otherwise the + * nr_entries could be rewritten incorrectly by an old bio. + */ + wait_for_completion_io(&lc->super_done); + return 0; } @@ -447,6 +465,7 @@ static int log_writes_ctr(struct dm_targ INIT_LIST_HEAD(&lc->unflushed_blocks); INIT_LIST_HEAD(&lc->logging_blocks); init_waitqueue_head(&lc->wait); + init_completion(&lc->super_done); atomic_set(&lc->io_blocks, 0); atomic_set(&lc->pending_blocks, 0);