From nobody Fri Oct 18 08:39:06 2024 Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F8D9157489 for ; Tue, 23 Jul 2024 15:44:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721749468; cv=none; b=QXrPu8xNYY+PS0sxSLfCdHNeJ5wTef6RKpd9O67LpwVSpy/ounEnKttn9RmlNBKyGzGN/9VXKp1krIorTEo0pLkxV3O6OzMrL70SVwWD3s2/+UffX3iuLvLI/frFK3KI3B39doXvA0fUDlxSV2DSPymAfwalwuNO+rUS0T/1xgs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721749468; c=relaxed/simple; bh=Bxkl0Hsq/C8M5vztSXAU7ypBDTyy8EAXeWXTtS31tww=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BPTpxn0NDTGo9ssB570aHadasqT8bRrNyZNn571yH8tYRFzRrN+g00ncVlPfE/24NvnLc5mU8ikFxiPwjQJB9aGrEsTr677PFymBVrjpz5UkS9n0dI+uDjV2UhAwDHYA4oRlBH8xOaolmk/SYoztAsJoWb3zOiQOPX+2qvDX0CU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=dreQwsXf; arc=none smtp.client-ip=95.215.58.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="dreQwsXf" X-Envelope-To: tytso@mit.edu DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1721749465; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rz9lvD/QnXWNWbo/BvxmhM9orJ0FJCtlryAD6j/pNsA=; b=dreQwsXfs96IstFiRI1hPoQfQqqUhB116zeyx2xnP7tnJ+ZGwLcg0kgvZTqiwmRqvA+869 AQJTft3iLRrg23gf3XUyPXGVFdp8pm34oQaDS1lN01fHTwHojAwhsMUaEkb2QiO3WNuCMD heAKdE44lTrFIu/gGUNqjzJQGBPLLoM= X-Envelope-To: adilger@dilger.ca X-Envelope-To: jack@suse.cz X-Envelope-To: harshadshirwadkar@gmail.com X-Envelope-To: linux-ext4@vger.kernel.org X-Envelope-To: linux-kernel@vger.kernel.org X-Envelope-To: luis.henriques@linux.dev X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: "Luis Henriques (SUSE)" To: Theodore Ts'o , Andreas Dilger , Jan Kara , Harshad Shirwadkar Cc: linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, "Luis Henriques (SUSE)" Subject: [PATCH 3/4] ext4: fix incorrect tid assumption in jbd2_journal_shrink_checkpoint_list() Date: Tue, 23 Jul 2024 16:44:01 +0100 Message-ID: <20240723154402.21125-4-luis.henriques@linux.dev> In-Reply-To: <20240723154402.21125-1-luis.henriques@linux.dev> References: <20240723154402.21125-1-luis.henriques@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Function jbd2_journal_shrink_checkpoint_list() assumes that '0' is not a valid value for transaction IDs, which is incorrect. Don't assume that and use two extra boolean variables to control the loop iterations and keep track of the first and last tid. Signed-off-by: Luis Henriques (SUSE) --- fs/jbd2/checkpoint.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/jbd2/checkpoint.c b/fs/jbd2/checkpoint.c index 77bc522e6821..f5a594237b7a 100644 --- a/fs/jbd2/checkpoint.c +++ b/fs/jbd2/checkpoint.c @@ -410,6 +410,7 @@ unsigned long jbd2_journal_shrink_checkpoint_list(journ= al_t *journal, tid_t tid =3D 0; unsigned long nr_freed =3D 0; unsigned long freed; + bool is_first =3D true, is_last =3D false; =20 again: spin_lock(&journal->j_list_lock); @@ -429,8 +430,10 @@ unsigned long jbd2_journal_shrink_checkpoint_list(jour= nal_t *journal, else transaction =3D journal->j_checkpoint_transactions; =20 - if (!first_tid) + if (is_first) { first_tid =3D transaction->t_tid; + is_first =3D false; + } last_transaction =3D journal->j_checkpoint_transactions->t_cpprev; next_transaction =3D transaction; last_tid =3D last_transaction->t_tid; @@ -455,12 +458,13 @@ unsigned long jbd2_journal_shrink_checkpoint_list(jou= rnal_t *journal, } else { journal->j_shrink_transaction =3D NULL; next_tid =3D 0; + is_last =3D true; } =20 spin_unlock(&journal->j_list_lock); cond_resched(); =20 - if (*nr_to_scan && next_tid) + if (*nr_to_scan && !is_last) goto again; out: trace_jbd2_shrink_checkpoint_list(journal, first_tid, tid, last_tid,