From patchwork Thu Oct 26 07:28:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 10027529 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5C58F601E8 for ; Thu, 26 Oct 2017 07:29:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4AB5428D2D for ; Thu, 26 Oct 2017 07:29:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F89228D45; Thu, 26 Oct 2017 07:29:00 +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=-6.9 required=2.0 tests=BAYES_00,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 4A2C928D2D for ; Thu, 26 Oct 2017 07:28:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751663AbdJZH2z (ORCPT ); Thu, 26 Oct 2017 03:28:55 -0400 Received: from prv3-mh.provo.novell.com ([137.65.250.26]:43550 "EHLO prv3-mh.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751166AbdJZH2z (ORCPT ); Thu, 26 Oct 2017 03:28:55 -0400 Received: from adam-pc.lan (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by prv3-mh.provo.novell.com with ESMTP (NOT encrypted); Thu, 26 Oct 2017 01:28:40 -0600 From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH] btrfs-progs: convert: Open the fs readonly for rollback Date: Thu, 26 Oct 2017 15:28:37 +0800 Message-Id: <20171026072837.27460-1-wqu@suse.com> X-Mailer: git-send-email 2.14.3 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP For rollback, we only needs to open the fs to check if it meets the condition to rollback. And this RW read makes us failed to rollback btrfs with v2 space cache. In fact, we don't even start a transaction during rollback. So open the fs RO for rollback, to avoid v2 space cache problem. Reported-by: Gu Jinxiang Signed-off-by: Qu Wenruo --- convert/main.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/convert/main.c b/convert/main.c index 882daf7ced53..3ec10f233915 100644 --- a/convert/main.c +++ b/convert/main.c @@ -1529,7 +1529,13 @@ static int do_rollback(const char *devname) goto free_mem; } fsize = lseek(fd, 0, SEEK_END); - root = open_ctree_fd(fd, devname, 0, OPEN_CTREE_WRITES); + + /* + * For rollback, we don't really need write anything into btrfs, + * so open it RO. + * The write part will happen after we close the btrfs. + */ + root = open_ctree_fd(fd, devname, 0, 0); if (!root) { error("unable to open ctree"); ret = -EIO;