From nobody Sun Feb 8 03:10:30 2026 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4E8501990AF; Mon, 26 Aug 2024 17:41:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724694095; cv=none; b=smmdzbin3mrK5MBSsSM3HCL5DnymAI7G+KnlDfwT0SIGzO7bhNh7uFJndoNqAJkFl+6b5+5OfAo3LUKKb143dT8Iou/T810uykBCpo/zIHOlBMn/iksE5ZCI9cGLy3+jNAJHYR213D1rXbRWQDVDUH8Q+5BsyMcuzaphVq0kT/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724694095; c=relaxed/simple; bh=8EnvAihNq6tOIhgL6V5zBWfQsQ5CZXfVaMzGWaWrT5s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HiDPMJ6g/GXtomoYiNI2esQSedwC5Pq0VKImObIlWDWIo7AG7acSg5XTmOvpq57L14WLF3Bwi+kH2AQ7Xk9CHwS4wef6IvA2Xe3WfVyTUg6C4K6Jy6CsBMiFve/S+ld2EqplszxsyPXDYMl0gFsQuXduYbvz6NR3X9eHPWGHvEM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZceIzULg; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZceIzULg" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-202318c4f45so46630405ad.0; Mon, 26 Aug 2024 10:41:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724694093; x=1725298893; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Bb3DPdn0pj3TNjeQ2c5ACYytiWwIREFsen47gNLgdCE=; b=ZceIzULguwXnNlmHrdN/Utxc4O/UEj97t7VVx7itFjHH6AaYxlZsZVpYVMwQg/N9/c lQy/RVi2IMnljw9uHqOsld4w1KPg1yiAQYXtexgMnVfKvFRkCIIaD1E/bJomQCF5inhf sYqDRkS3pVcpyXXbnPcPGwZWe/icMlHSQemyGF3Lo+7YENtOInj9Hk1s5RjmNDVuRoEx RzfHlmjB2gOocxWm+PVChYQhpUlUeAJIJC8VFllQOatJbw83f1A7suHKytpLHc/Q+CkK KPMw4qKYsigmx7Bjv6W/vYcoZK72OseUU4lNRBAwOgHlImnUBpN3BcB61npvwfg2BhkG IUgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724694093; x=1725298893; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Bb3DPdn0pj3TNjeQ2c5ACYytiWwIREFsen47gNLgdCE=; b=tDu4LqKUC0uvu8H32CdCleQO/xFdo2CviG3bYfZLSjAVvo2Yvqf9zqrs3y3CrYiTjS JZzrS+uP6iayxD7HJhXZKpbqA0Nt2D3L0Ct7w64PaCfXRrJ+YF9umPBrFT/ume3C8flX yk4akK7cgAVUFc4TvYnWMtlEmiJUkdRidsB8+oZEMlupgUTmGBn5Vt17jMl/XjIoEqx9 PpIp3tDRo33fJPhaMS6YYNfrHiOaJ4F1H3fFIKuGK3xRU1v/iZoqFzOp1Kd5skjuLNfm u8kBSict4hS7PB8YxO/d+xgH3Llt/0RcdcENn/xu7SpaoD9hqOu7n0r69ynbnBqc8vUn JWAQ== X-Forwarded-Encrypted: i=1; AJvYcCX59fJgz0kpv2OSE3a4QLeh66hBkcN8S4Xg5rPXORIbIgP89NKKKBslBRXmdxqYsUAeSTfftdlxzLFoTuE=@vger.kernel.org X-Gm-Message-State: AOJu0Yyz//yxGp/s0/IGVzibs1E3fo6iyoh/y4zvpgL4aLz6fR/3eTRV 7UxnxA2fpDRA6Vwb6qPjyEhPFFDhFfLiaR9yAHcRh5fIuszuZXvi X-Google-Smtp-Source: AGHT+IHOU2+ySwRRTK3i0lx33XAgq/AJ2L3rvoi6nlp3xljwaszM/3uWo8aDPwZ+GwdYToH/zG1bow== X-Received: by 2002:a17:903:11c3:b0:203:a116:7953 with SMTP id d9443c01a7336-204def2d5a1mr3812525ad.10.1724694093270; Mon, 26 Aug 2024 10:41:33 -0700 (PDT) Received: from carrot.. (i222-151-34-139.s42.a014.ap.plala.or.jp. [222.151.34.139]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855665besm70057055ad.34.2024.08.26.10.41.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 10:41:32 -0700 (PDT) From: Ryusuke Konishi To: Andrew Morton Cc: linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/8] nilfs2: use common implementation of file type Date: Tue, 27 Aug 2024 02:41:09 +0900 Message-Id: <20240826174116.5008-2-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240826174116.5008-1-konishi.ryusuke@gmail.com> References: <20240826174116.5008-1-konishi.ryusuke@gmail.com> 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 Content-Type: text/plain; charset="utf-8" From: Huang Xiaojia Deduplicate the nilfs2 file type conversion implementation. Link: https://lkml.kernel.org/r/20240815013442.1220909-1-huangxiaojia2@huaw= ei.com Signed-off-by: Huang Xiaojia Signed-off-by: Ryusuke Konishi --- fs/nilfs2/dir.c | 44 +++++--------------------------------------- 1 file changed, 5 insertions(+), 39 deletions(-) diff --git a/fs/nilfs2/dir.c b/fs/nilfs2/dir.c index 4a29b0138d75..ba6bc6efcf11 100644 --- a/fs/nilfs2/dir.c +++ b/fs/nilfs2/dir.c @@ -231,37 +231,6 @@ static struct nilfs_dir_entry *nilfs_next_entry(struct= nilfs_dir_entry *p) nilfs_rec_len_from_disk(p->rec_len)); } =20 -static unsigned char -nilfs_filetype_table[NILFS_FT_MAX] =3D { - [NILFS_FT_UNKNOWN] =3D DT_UNKNOWN, - [NILFS_FT_REG_FILE] =3D DT_REG, - [NILFS_FT_DIR] =3D DT_DIR, - [NILFS_FT_CHRDEV] =3D DT_CHR, - [NILFS_FT_BLKDEV] =3D DT_BLK, - [NILFS_FT_FIFO] =3D DT_FIFO, - [NILFS_FT_SOCK] =3D DT_SOCK, - [NILFS_FT_SYMLINK] =3D DT_LNK, -}; - -#define S_SHIFT 12 -static unsigned char -nilfs_type_by_mode[(S_IFMT >> S_SHIFT) + 1] =3D { - [S_IFREG >> S_SHIFT] =3D NILFS_FT_REG_FILE, - [S_IFDIR >> S_SHIFT] =3D NILFS_FT_DIR, - [S_IFCHR >> S_SHIFT] =3D NILFS_FT_CHRDEV, - [S_IFBLK >> S_SHIFT] =3D NILFS_FT_BLKDEV, - [S_IFIFO >> S_SHIFT] =3D NILFS_FT_FIFO, - [S_IFSOCK >> S_SHIFT] =3D NILFS_FT_SOCK, - [S_IFLNK >> S_SHIFT] =3D NILFS_FT_SYMLINK, -}; - -static void nilfs_set_de_type(struct nilfs_dir_entry *de, struct inode *in= ode) -{ - umode_t mode =3D inode->i_mode; - - de->file_type =3D nilfs_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; -} - static int nilfs_readdir(struct file *file, struct dir_context *ctx) { loff_t pos =3D ctx->pos; @@ -297,10 +266,7 @@ static int nilfs_readdir(struct file *file, struct dir= _context *ctx) if (de->inode) { unsigned char t; =20 - if (de->file_type < NILFS_FT_MAX) - t =3D nilfs_filetype_table[de->file_type]; - else - t =3D DT_UNKNOWN; + t =3D fs_ftype_to_dtype(de->file_type); =20 if (!dir_emit(ctx, de->name, de->name_len, le64_to_cpu(de->inode), t)) { @@ -444,7 +410,7 @@ void nilfs_set_link(struct inode *dir, struct nilfs_dir= _entry *de, err =3D nilfs_prepare_chunk(folio, from, to); BUG_ON(err); de->inode =3D cpu_to_le64(inode->i_ino); - nilfs_set_de_type(de, inode); + de->file_type =3D fs_umode_to_ftype(inode->i_mode); nilfs_commit_chunk(folio, mapping, from, to); inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); } @@ -531,7 +497,7 @@ int nilfs_add_link(struct dentry *dentry, struct inode = *inode) de->name_len =3D namelen; memcpy(de->name, name, namelen); de->inode =3D cpu_to_le64(inode->i_ino); - nilfs_set_de_type(de, inode); + de->file_type =3D fs_umode_to_ftype(inode->i_mode); nilfs_commit_chunk(folio, folio->mapping, from, to); inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); nilfs_mark_inode_dirty(dir); @@ -612,14 +578,14 @@ int nilfs_make_empty(struct inode *inode, struct inod= e *parent) de->rec_len =3D nilfs_rec_len_to_disk(NILFS_DIR_REC_LEN(1)); memcpy(de->name, ".\0\0", 4); de->inode =3D cpu_to_le64(inode->i_ino); - nilfs_set_de_type(de, inode); + de->file_type =3D fs_umode_to_ftype(inode->i_mode); =20 de =3D (struct nilfs_dir_entry *)(kaddr + NILFS_DIR_REC_LEN(1)); de->name_len =3D 2; de->rec_len =3D nilfs_rec_len_to_disk(chunk_size - NILFS_DIR_REC_LEN(1)); de->inode =3D cpu_to_le64(parent->i_ino); memcpy(de->name, "..\0", 4); - nilfs_set_de_type(de, inode); + de->file_type =3D fs_umode_to_ftype(inode->i_mode); kunmap_local(kaddr); nilfs_commit_chunk(folio, mapping, 0, chunk_size); fail: --=20 2.34.1 From nobody Sun Feb 8 03:10:30 2026 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 27B521991C9; Mon, 26 Aug 2024 17:41:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724694097; cv=none; b=TEdp0uNKBXYXl7LtTuHkcmPoSNtfbrjm/3keDCTP1xbugs6dm0P7QPZAtRs+WAfsXyQSpbCWaEcxyRsJaiLkRPAR2t+pKOSSeXi+I+w8mGcTsBPa7l2Tn/C/8yQgDucGdczjojmymHyakaBrMfIqgL2xTLrbn5mRIF/Tah0M9S8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724694097; c=relaxed/simple; bh=2s+R3X+6d9hrFj0u7Wf5JEZyteFBCxrbQzEt/SyOWeE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VaNx+urzYgkh4nrlgafQsoOwLoRe1j04PHbQ13ZKyS79hTjjuO6a+HPQV+TlcjJDukZ22soVkvquFsFHJvBCgWekyOWv6OdpO43jH7RVyQy75GcJ4Fb7dco52gN2scKoMGJCeqUSRxQeS3UhtpOu1PIhgQwFudGWzkZh5XfSUxA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ixyRpL2E; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ixyRpL2E" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2021c03c13aso34137975ad.1; Mon, 26 Aug 2024 10:41:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724694095; x=1725298895; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8fkI07GsRrIlEcuKQ1pK78Clu2EL4VeyO3HrgEkrrck=; b=ixyRpL2E4mvkKuG96VH5fvSy8YpTyFA3aypJyfBUXsoIIlYXi+FC8d82pQnK8kfjvr XAqmKkZ3UOefy0QgdlqZG0JkzExQfMVvrt6y3Jc2j5b28qMMGLsxQnOc3WHzM2V9t6F4 reZFUOTBbnQmDOyNiZjG31hXAxGbDg5+gbANEq7G7StZAUep4rye8bFxPvuJ529YI8rc X8D8wugUeEslJzKMAF9X5c+/sqmD2+P9l8Zy5B8T2M9QLZnHuQaTaqr17mcBjRfUumNj LdlaqRYAYvN+73dqgSqm8NwO5vktefmNX5yv2IIK9C3tYDyrlFQWI4snPzU+lrUJtZAZ Dktw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724694095; x=1725298895; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8fkI07GsRrIlEcuKQ1pK78Clu2EL4VeyO3HrgEkrrck=; b=WkRnUMoZ2VEYZ/OUTj2/eA3i4W+moSW3dNkiHO2PmijNjQUxZNV3ZhUcluqoAcYku9 r+3WYd/fBuJFszPLyt3rVoDHPKjndYbUx6MG4KjOnpVMPhbuweP9G3L42lGUU68eLybt 4Y0hr5fy+GgjXf248cH1yuf8Q5p0I/MTNTzZ5d22Rj1e0tQlb9jw0GYHjYjTfSaAzKfe gNn8y/6eWBQEoTx06qJiUrLnlIcKTV63psir+REoqRUnrC5uGGqhXYMhqTiCiEY6kOkw HV/vqOXbBUx8qyttmymfHLPGC0iqidP3jAtBY8T+M33xNP9XPOpFDYX02LNLJWwJh28l /Jqw== X-Forwarded-Encrypted: i=1; AJvYcCVD80MblBki9EI2P9oTl9hY+g3MU9BLM3A3qkzQd2ydB0/q52moIpQxhS8Th8LMtLZA9wKqZdtaepLR+KE=@vger.kernel.org X-Gm-Message-State: AOJu0YyerZMNG8Q//rRqtUFLWFQnc8hlIXIRJZ13zNlSrNQk5EZFij7L LvsbTgDWxZ8E9VNoRshxkjoWL1r6Wz3JXLgY/6TYb47dM23KYzbLwXCeQA== X-Google-Smtp-Source: AGHT+IHTFfDs7jD0NoK45VdOAOpIUBuIgFY5mFUesDJ6HOkDaj9FmAAby+5Xabw0TJvKhSpLPPjqEA== X-Received: by 2002:a17:902:d507:b0:1fb:5d71:20dd with SMTP id d9443c01a7336-204ddb87a51mr6478495ad.0.1724694095249; Mon, 26 Aug 2024 10:41:35 -0700 (PDT) Received: from carrot.. (i222-151-34-139.s42.a014.ap.plala.or.jp. [222.151.34.139]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855665besm70057055ad.34.2024.08.26.10.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 10:41:34 -0700 (PDT) From: Ryusuke Konishi To: Andrew Morton Cc: linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/8] nilfs2: use the BITS_PER_LONG macro Date: Tue, 27 Aug 2024 02:41:10 +0900 Message-Id: <20240826174116.5008-3-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240826174116.5008-1-konishi.ryusuke@gmail.com> References: <20240826174116.5008-1-konishi.ryusuke@gmail.com> 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 Content-Type: text/plain; charset="utf-8" The macros NILFS_BMAP_KEY_BIT and NILFS_BMAP_NEW_PTR_INIT calculate, within their definitions, the number of bits in an unsigned long variable. Use the BITS_PER_LONG macro to make them simpler. Signed-off-by: Ryusuke Konishi --- fs/nilfs2/bmap.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/nilfs2/bmap.h b/fs/nilfs2/bmap.h index 5f8c8c552620..4656df392722 100644 --- a/fs/nilfs2/bmap.h +++ b/fs/nilfs2/bmap.h @@ -87,9 +87,8 @@ struct nilfs_bmap_operations { =20 =20 #define NILFS_BMAP_SIZE (NILFS_INODE_BMAP_SIZE * sizeof(__le64)) -#define NILFS_BMAP_KEY_BIT (sizeof(unsigned long) * 8 /* CHAR_BIT */) -#define NILFS_BMAP_NEW_PTR_INIT \ - (1UL << (sizeof(unsigned long) * 8 /* CHAR_BIT */ - 1)) +#define NILFS_BMAP_KEY_BIT BITS_PER_LONG +#define NILFS_BMAP_NEW_PTR_INIT (1UL << (BITS_PER_LONG - 1)) =20 static inline int nilfs_bmap_is_new_ptr(unsigned long ptr) { --=20 2.34.1 From nobody Sun Feb 8 03:10:30 2026 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 33A16199259; Mon, 26 Aug 2024 17:41:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724694099; cv=none; b=mq513gAJmeqTyDLUjs5bijcuyzFm1a1lwqlHW5Uj9ik/pTL3nmgIYkf19lKmepDAcYzxDTaN3cClpBGR/+Q1RB5pj+r3mYkeeZJRop9fIjUd2FbJ3J2cApAEwILC7TYDL/7VSXiM3kvU/PonED8jQaq6LkEgF/4A4HN2JHmxDaI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724694099; c=relaxed/simple; bh=IBpjGpT3+dfPMCbwZ8AstCshDNqRkTKGECu191f0TUw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ieM2VDenH9ThTLUmwTmKWF/KMPadkK3wpsHxTSkHshHb0uZZ02KMK4Gi6td3W2SA2ym4DRAUhEiCtDUnrlh5TSvwP/rf6MzFey/vzBvZd97WbyUdenzRt+2Qadvq1h4krPMN+ljARTeb3Xle5uiTd6aNQ1pMMrD7IwD97Rgena0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nrVolagg; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nrVolagg" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2021537a8e6so40664045ad.2; Mon, 26 Aug 2024 10:41:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724694098; x=1725298898; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uRKVjbw/gvzrgcStUudURUfM0z4wfapb4mMVAu16Gjc=; b=nrVolaggQ6/F0agtFRfpBvkzseUHSN/qeenrq8l634m4Tfgg1mJG4Pu1br/YL9evp+ KsSvV77oYAl22A+bnCSY7F+3WuJhaC3E9FpOGpDrFvpvbcA6Vv36a5IIVBBCLx2qQjkO yY8kCHZBRNwdLflXMXuE1EE23Fm76lSTO1URYSuSsOTdjCZy8MtEwTF9HrM6Pb/lBToz V26z2KxGBe8OzQCKuCG5NCBrqmsykYK/LC4DYPT9AnC07T+7AwksICbfvl+I37OrY8jg ahMXzfLRc/Zm+4eSRhl0HE6F0c12/2Nfq3CO5AaLqt45WlZieaRWCXEGDnQCqqYwhBjv AecA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724694098; x=1725298898; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uRKVjbw/gvzrgcStUudURUfM0z4wfapb4mMVAu16Gjc=; b=S1aYAHqCnJaszjGJBgFFbEbAu4FiZ1688S2KvcEt8y0hFj453aI09O7QmCXLhHBKfJ +OO15GPeLxRi6RLRT77Y1TEfw9X8VhDlXWVUMXqcJXaPRw4MNuGN3+tUD3jDfgNUk1yt SPbVV7SIKBhiM97/iS5fTm0xjOkc/oF2o4LryXie6Sgcbp1Y9uYogkfhJLtbThRdUT2p iHpKBw99rWDGWPsIkR8Esz3bY7y1vln7sHjigsbVGwnc9OdBqls7QGzZudEXUq0a4HwT vMcxfCluIVoH8Z3hVCA6sc6sfJL3q/fpfrPBp02bYbVO+YLtdlN/LxlSOHfr9XR8ytlL DWEQ== X-Forwarded-Encrypted: i=1; AJvYcCUg+oLUApCwCJHfJK0+V8Q4iMGi6CnEzboYZ+BFORpRJPqxQr5NlBXR3xy7n1u/h/7d5E2ZO//kBqAd+SM=@vger.kernel.org X-Gm-Message-State: AOJu0Yx9cXN4CqfMnLt5FdXAYYCMNoSayEMr8o7Iw5w/Xw9UNMOCuYIy R5W9TQrsKWcfKON/KMnCJv3rvtEehTKAyx2eP5NkQKMUh9ywKR7XpxVkDg== X-Google-Smtp-Source: AGHT+IFEvb3TP1BcRxf0l5w1dckNP9L9XzPXzTrmcJLSdKOctvuLxs13JO7cwZAADEJXClH14KivAQ== X-Received: by 2002:a17:902:dacc:b0:202:cbf:2d4e with SMTP id d9443c01a7336-2039e554fe8mr120479895ad.64.1724694097345; Mon, 26 Aug 2024 10:41:37 -0700 (PDT) Received: from carrot.. (i222-151-34-139.s42.a014.ap.plala.or.jp. [222.151.34.139]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855665besm70057055ad.34.2024.08.26.10.41.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 10:41:36 -0700 (PDT) From: Ryusuke Konishi To: Andrew Morton Cc: linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/8] nilfs2: separate inode type information from i_state field Date: Tue, 27 Aug 2024 02:41:11 +0900 Message-Id: <20240826174116.5008-4-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240826174116.5008-1-konishi.ryusuke@gmail.com> References: <20240826174116.5008-1-konishi.ryusuke@gmail.com> 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 Content-Type: text/plain; charset="utf-8" In nilfs_iget_locked() and nilfs_ilookup(), which are used to find or obtain nilfs2 inodes, the nilfs_iget_args structure used to identify inodes has type information divided into multiple booleans, making type determination complicated. Simplify inode type determination by consolidating inode type information into an unsigned integer represented by a comibination of flags and by separating the type identification information for on-memory inodes from the i_state member in the nilfs_inode_info structure. Signed-off-by: Ryusuke Konishi --- fs/nilfs2/inode.c | 56 ++++++++++++--------------------------------- fs/nilfs2/nilfs.h | 15 +++++++++--- fs/nilfs2/segment.c | 2 +- fs/nilfs2/super.c | 1 + 4 files changed, 28 insertions(+), 46 deletions(-) diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c index c39bc940e6f2..35f966cb4ece 100644 --- a/fs/nilfs2/inode.c +++ b/fs/nilfs2/inode.c @@ -28,17 +28,13 @@ * @ino: inode number * @cno: checkpoint number * @root: pointer on NILFS root object (mounted checkpoint) - * @for_gc: inode for GC flag - * @for_btnc: inode for B-tree node cache flag - * @for_shadow: inode for shadowed page cache flag + * @type: inode type */ struct nilfs_iget_args { u64 ino; __u64 cno; struct nilfs_root *root; - bool for_gc; - bool for_btnc; - bool for_shadow; + unsigned int type; }; =20 static int nilfs_iget_test(struct inode *inode, void *opaque); @@ -315,8 +311,7 @@ static int nilfs_insert_inode_locked(struct inode *inod= e, unsigned long ino) { struct nilfs_iget_args args =3D { - .ino =3D ino, .root =3D root, .cno =3D 0, .for_gc =3D false, - .for_btnc =3D false, .for_shadow =3D false + .ino =3D ino, .root =3D root, .cno =3D 0, .type =3D NILFS_I_TYPE_NORMAL }; =20 return insert_inode_locked4(inode, ino, nilfs_iget_test, &args); @@ -343,6 +338,7 @@ struct inode *nilfs_new_inode(struct inode *dir, umode_= t mode) root =3D NILFS_I(dir)->i_root; ii =3D NILFS_I(inode); ii->i_state =3D BIT(NILFS_I_NEW); + ii->i_type =3D NILFS_I_TYPE_NORMAL; ii->i_root =3D root; =20 err =3D nilfs_ifile_create_inode(root->ifile, &ino, &bh); @@ -546,23 +542,10 @@ static int nilfs_iget_test(struct inode *inode, void = *opaque) return 0; =20 ii =3D NILFS_I(inode); - if (test_bit(NILFS_I_BTNC, &ii->i_state)) { - if (!args->for_btnc) - return 0; - } else if (args->for_btnc) { + if (ii->i_type !=3D args->type) return 0; - } - if (test_bit(NILFS_I_SHADOW, &ii->i_state)) { - if (!args->for_shadow) - return 0; - } else if (args->for_shadow) { - return 0; - } =20 - if (!test_bit(NILFS_I_GCINODE, &ii->i_state)) - return !args->for_gc; - - return args->for_gc && args->cno =3D=3D ii->i_cno; + return !(args->type & NILFS_I_TYPE_GC) || args->cno =3D=3D ii->i_cno; } =20 static int nilfs_iget_set(struct inode *inode, void *opaque) @@ -572,15 +555,9 @@ static int nilfs_iget_set(struct inode *inode, void *o= paque) inode->i_ino =3D args->ino; NILFS_I(inode)->i_cno =3D args->cno; NILFS_I(inode)->i_root =3D args->root; + NILFS_I(inode)->i_type =3D args->type; if (args->root && args->ino =3D=3D NILFS_ROOT_INO) nilfs_get_root(args->root); - - if (args->for_gc) - NILFS_I(inode)->i_state =3D BIT(NILFS_I_GCINODE); - if (args->for_btnc) - NILFS_I(inode)->i_state |=3D BIT(NILFS_I_BTNC); - if (args->for_shadow) - NILFS_I(inode)->i_state |=3D BIT(NILFS_I_SHADOW); return 0; } =20 @@ -588,8 +565,7 @@ struct inode *nilfs_ilookup(struct super_block *sb, str= uct nilfs_root *root, unsigned long ino) { struct nilfs_iget_args args =3D { - .ino =3D ino, .root =3D root, .cno =3D 0, .for_gc =3D false, - .for_btnc =3D false, .for_shadow =3D false + .ino =3D ino, .root =3D root, .cno =3D 0, .type =3D NILFS_I_TYPE_NORMAL }; =20 return ilookup5(sb, ino, nilfs_iget_test, &args); @@ -599,8 +575,7 @@ struct inode *nilfs_iget_locked(struct super_block *sb,= struct nilfs_root *root, unsigned long ino) { struct nilfs_iget_args args =3D { - .ino =3D ino, .root =3D root, .cno =3D 0, .for_gc =3D false, - .for_btnc =3D false, .for_shadow =3D false + .ino =3D ino, .root =3D root, .cno =3D 0, .type =3D NILFS_I_TYPE_NORMAL }; =20 return iget5_locked(sb, ino, nilfs_iget_test, nilfs_iget_set, &args); @@ -631,8 +606,7 @@ struct inode *nilfs_iget_for_gc(struct super_block *sb,= unsigned long ino, __u64 cno) { struct nilfs_iget_args args =3D { - .ino =3D ino, .root =3D NULL, .cno =3D cno, .for_gc =3D true, - .for_btnc =3D false, .for_shadow =3D false + .ino =3D ino, .root =3D NULL, .cno =3D cno, .type =3D NILFS_I_TYPE_GC }; struct inode *inode; int err; @@ -677,9 +651,7 @@ int nilfs_attach_btree_node_cache(struct inode *inode) args.ino =3D inode->i_ino; args.root =3D ii->i_root; args.cno =3D ii->i_cno; - args.for_gc =3D test_bit(NILFS_I_GCINODE, &ii->i_state) !=3D 0; - args.for_btnc =3D true; - args.for_shadow =3D test_bit(NILFS_I_SHADOW, &ii->i_state) !=3D 0; + args.type =3D ii->i_type | NILFS_I_TYPE_BTNC; =20 btnc_inode =3D iget5_locked(inode->i_sb, inode->i_ino, nilfs_iget_test, nilfs_iget_set, &args); @@ -733,8 +705,8 @@ void nilfs_detach_btree_node_cache(struct inode *inode) struct inode *nilfs_iget_for_shadow(struct inode *inode) { struct nilfs_iget_args args =3D { - .ino =3D inode->i_ino, .root =3D NULL, .cno =3D 0, .for_gc =3D false, - .for_btnc =3D false, .for_shadow =3D true + .ino =3D inode->i_ino, .root =3D NULL, .cno =3D 0, + .type =3D NILFS_I_TYPE_SHADOW }; struct inode *s_inode; int err; @@ -900,7 +872,7 @@ static void nilfs_clear_inode(struct inode *inode) if (test_bit(NILFS_I_BMAP, &ii->i_state)) nilfs_bmap_clear(ii->i_bmap); =20 - if (!test_bit(NILFS_I_BTNC, &ii->i_state)) + if (!(ii->i_type & NILFS_I_TYPE_BTNC)) nilfs_detach_btree_node_cache(inode); =20 if (ii->i_root && inode->i_ino =3D=3D NILFS_ROOT_INO) diff --git a/fs/nilfs2/nilfs.h b/fs/nilfs2/nilfs.h index 3097490b6621..fb1c4c5bae7c 100644 --- a/fs/nilfs2/nilfs.h +++ b/fs/nilfs2/nilfs.h @@ -22,6 +22,7 @@ /** * struct nilfs_inode_info - nilfs inode data in memory * @i_flags: inode flags + * @i_type: inode type (combination of flags that inidicate usage) * @i_state: dynamic state flags * @i_bmap: pointer on i_bmap_data * @i_bmap_data: raw block mapping @@ -37,6 +38,7 @@ */ struct nilfs_inode_info { __u32 i_flags; + unsigned int i_type; unsigned long i_state; /* Dynamic state flags */ struct nilfs_bmap *i_bmap; struct nilfs_bmap i_bmap_data; @@ -90,9 +92,16 @@ enum { NILFS_I_UPDATED, /* The file has been written back */ NILFS_I_INODE_SYNC, /* dsync is not allowed for inode */ NILFS_I_BMAP, /* has bmap and btnode_cache */ - NILFS_I_GCINODE, /* inode for GC, on memory only */ - NILFS_I_BTNC, /* inode for btree node cache */ - NILFS_I_SHADOW, /* inode for shadowed page cache */ +}; + +/* + * Flags to identify the usage of on-memory inodes (i_type) + */ +enum { + NILFS_I_TYPE_NORMAL =3D 0, + NILFS_I_TYPE_GC =3D 0x0001, /* For data caching during GC */ + NILFS_I_TYPE_BTNC =3D 0x0002, /* For btree node cache */ + NILFS_I_TYPE_SHADOW =3D 0x0004, /* For shadowed page cache */ }; =20 /* diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c index 765d55333a13..206066ce6d00 100644 --- a/fs/nilfs2/segment.c +++ b/fs/nilfs2/segment.c @@ -519,7 +519,7 @@ static void nilfs_segctor_end_finfo(struct nilfs_sc_inf= o *sci, =20 ii =3D NILFS_I(inode); =20 - if (test_bit(NILFS_I_GCINODE, &ii->i_state)) + if (ii->i_type & NILFS_I_TYPE_GC) cno =3D ii->i_cno; else if (NILFS_ROOT_METADATA_FILE(inode->i_ino)) cno =3D 0; diff --git a/fs/nilfs2/super.c b/fs/nilfs2/super.c index 8eb8dbc9f51c..eca79cca3803 100644 --- a/fs/nilfs2/super.c +++ b/fs/nilfs2/super.c @@ -160,6 +160,7 @@ struct inode *nilfs_alloc_inode(struct super_block *sb) return NULL; ii->i_bh =3D NULL; ii->i_state =3D 0; + ii->i_type =3D 0; ii->i_cno =3D 0; ii->i_assoc_inode =3D NULL; ii->i_bmap =3D &ii->i_bmap_data; --=20 2.34.1 From nobody Sun Feb 8 03:10:30 2026 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B8E519993E; Mon, 26 Aug 2024 17:41:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724694101; cv=none; b=mPP3gSu9ubS/8JVoXFVAp23xlYgQVmQNb2PL+0yUwEt1dsgKMsyuymNxlpslngWreYzMg/Sboo+lgM4LSHPW5sSVOFY2vOev46t/s9KK+fmiTV1SmMpCvBUrnYOpxGpdzb2icsgC6YS7ojJ9IYQEB2Mf9CL1dYz7NAW8NvrbcJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724694101; c=relaxed/simple; bh=2HBsggGsl/AitU2NzdBb7heQnGUZ4t1FjGjfGF9NwdI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FbtnMkYMnST99kJ+qdCuW9/FamJu8z9n7kilgfgesGo5kqF5Er3qFvYof0/0l5aF8IVt0cerkrXhtgWjgqY5G5xcykbAx8ahIQQkwIGYlOwSbCmlaUX6MlG5jbaoMNu6Tt5lF49drSd1PsNbLCYC3xANY1IMckqC3DmFJjYMhiE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=A/jh8ie1; arc=none smtp.client-ip=209.85.210.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="A/jh8ie1" Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-714226888dfso4139795b3a.1; Mon, 26 Aug 2024 10:41:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724694100; x=1725298900; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dkzYfKwrKWY8U5r8QEB4WhkXm8xbBAJPRKpgneYz3SM=; b=A/jh8ie1JcMJrnPQ3tOFCfe8cA+Oji8ArxMJwiOL937wL0DldqJrqQfb6e1li50A6b 9r0w2T174vZQr7Cm4hhrQRiC8pAdHOvhrTYASN3eGiJU3IE2ScaU78dFJ8OSMREWIXr9 twnVAFvB7fpw2XxK0h3m9ubI+k9to/ixF+ZqlNJw2K56LOEuPoguuwKepY8MdFGhPFGS mdQSRC8zqnfkfDBY+Pv+WQvRe7jyuJlfiwtCB0WORWqP5XZLhcigpEfjpj+2frp/Yoc8 U2Adf2zUUeygWIWR2xxEnkzfymcatLW7RbJFZefJ5sMVnrOgvEo4TuOofa2vhIpKvXKN bnlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724694100; x=1725298900; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dkzYfKwrKWY8U5r8QEB4WhkXm8xbBAJPRKpgneYz3SM=; b=hShmABgeWDoGuWFaRiZbfdb06uWdkGcXmNMA996ZkrT8Ou06mTGqTcVvXV6MHaFEeG rRTlEEIjxhjI7uhHq1WbnyR6w9WIoPFhIOww/WyXArwvFrMugrOdrRbEzBXUlgGB+ahf EDIzelPuTAeN6Y4xYlY3+VOuw9AqP/h/N68QAuOIZURvNDuvFQYt45xB+dZhE4XZzt2p 8oEBs1AqcKL2tMyZnY2Q3OcD3UrQ5/qcNVu73Nn8KM2tBZZe8jNJI0n5o8qdO48u4M4Z si5yOBUO9n5yejS2u2Vjv6eJOznPNyhsDPqt0CdRLS1YylFL1iPjLdPjFJtGxpyTJ7so rA5g== X-Forwarded-Encrypted: i=1; AJvYcCVxHVyxgQqYx0GeYOOlCPYtWnnn5o+f/oaxAwYyUijlmd9ufAzwxMiC198R5r03Gqp8rMUzZL0j2ohVJog=@vger.kernel.org X-Gm-Message-State: AOJu0Yx23fWQ2k0ObEou6RPLpxGLQ2Q6pJYaQ4kFs37IdEtxcalqPjoO qULy/WaB1zHS/RoRzeUqU9Fwzbr3aBmxSIy7p38iKqhlt6ktpUjy/iluBw== X-Google-Smtp-Source: AGHT+IGMdQOOC4QIvQff/SeCQGdhJBhTtCV3dwCPgpC85Z5z1qHhhdzjLLqjY4BeQuj+M7Gkab6mYg== X-Received: by 2002:a05:6a20:439f:b0:1ca:cc16:1ebc with SMTP id adf61e73a8af0-1cc89d29a8amr12537886637.11.1724694099327; Mon, 26 Aug 2024 10:41:39 -0700 (PDT) Received: from carrot.. (i222-151-34-139.s42.a014.ap.plala.or.jp. [222.151.34.139]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855665besm70057055ad.34.2024.08.26.10.41.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 10:41:38 -0700 (PDT) From: Ryusuke Konishi To: Andrew Morton Cc: linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/8] nilfs2: eliminate the shared counter and spinlock for i_generation Date: Tue, 27 Aug 2024 02:41:12 +0900 Message-Id: <20240826174116.5008-5-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240826174116.5008-1-konishi.ryusuke@gmail.com> References: <20240826174116.5008-1-konishi.ryusuke@gmail.com> 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 Content-Type: text/plain; charset="utf-8" Use get_random_u32() as the source for inode->i_generation for new inodes, and eliminate the original source, the shared counter ns_next_generation along with its exclusive access spinlock ns_next_gen_lock. Signed-off-by: Ryusuke Konishi --- fs/nilfs2/inode.c | 6 ++---- fs/nilfs2/the_nilfs.c | 5 ----- fs/nilfs2/the_nilfs.h | 6 ------ 3 files changed, 2 insertions(+), 15 deletions(-) diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c index 35f966cb4ece..3c4a0577bc71 100644 --- a/fs/nilfs2/inode.c +++ b/fs/nilfs2/inode.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "nilfs.h" #include "btnode.h" #include "segment.h" @@ -320,7 +321,6 @@ static int nilfs_insert_inode_locked(struct inode *inod= e, struct inode *nilfs_new_inode(struct inode *dir, umode_t mode) { struct super_block *sb =3D dir->i_sb; - struct the_nilfs *nilfs =3D sb->s_fs_info; struct inode *inode; struct nilfs_inode_info *ii; struct nilfs_root *root; @@ -381,9 +381,7 @@ struct inode *nilfs_new_inode(struct inode *dir, umode_= t mode) /* ii->i_dir_acl =3D 0; */ ii->i_dir_start_lookup =3D 0; nilfs_set_inode_flags(inode); - spin_lock(&nilfs->ns_next_gen_lock); - inode->i_generation =3D nilfs->ns_next_generation++; - spin_unlock(&nilfs->ns_next_gen_lock); + inode->i_generation =3D get_random_u32(); if (nilfs_insert_inode_locked(inode, root, ino) < 0) { err =3D -EIO; goto failed_after_creation; diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c index e44dde57ab65..ac03fd3c330c 100644 --- a/fs/nilfs2/the_nilfs.c +++ b/fs/nilfs2/the_nilfs.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include "nilfs.h" @@ -69,7 +68,6 @@ struct the_nilfs *alloc_nilfs(struct super_block *sb) INIT_LIST_HEAD(&nilfs->ns_dirty_files); INIT_LIST_HEAD(&nilfs->ns_gc_inodes); spin_lock_init(&nilfs->ns_inode_lock); - spin_lock_init(&nilfs->ns_next_gen_lock); spin_lock_init(&nilfs->ns_last_segment_lock); nilfs->ns_cptree =3D RB_ROOT; spin_lock_init(&nilfs->ns_cptree_lock); @@ -754,9 +752,6 @@ int init_nilfs(struct the_nilfs *nilfs, struct super_bl= ock *sb) nilfs->ns_blocksize_bits =3D sb->s_blocksize_bits; nilfs->ns_blocksize =3D blocksize; =20 - get_random_bytes(&nilfs->ns_next_generation, - sizeof(nilfs->ns_next_generation)); - err =3D nilfs_store_disk_layout(nilfs, sbp); if (err) goto failed_sbh; diff --git a/fs/nilfs2/the_nilfs.h b/fs/nilfs2/the_nilfs.h index 1e829ed7b0ef..4776a70f01ae 100644 --- a/fs/nilfs2/the_nilfs.h +++ b/fs/nilfs2/the_nilfs.h @@ -71,8 +71,6 @@ enum { * @ns_dirty_files: list of dirty files * @ns_inode_lock: lock protecting @ns_dirty_files * @ns_gc_inodes: dummy inodes to keep live blocks - * @ns_next_generation: next generation number for inodes - * @ns_next_gen_lock: lock protecting @ns_next_generation * @ns_mount_opt: mount options * @ns_resuid: uid for reserved blocks * @ns_resgid: gid for reserved blocks @@ -161,10 +159,6 @@ struct the_nilfs { /* GC inode list */ struct list_head ns_gc_inodes; =20 - /* Inode allocator */ - u32 ns_next_generation; - spinlock_t ns_next_gen_lock; - /* Mount options */ unsigned long ns_mount_opt; =20 --=20 2.34.1 From nobody Sun Feb 8 03:10:30 2026 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7221F199E98; Mon, 26 Aug 2024 17:41:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724694103; cv=none; b=CZQmNUsiwt025jVKPJ3F9hQbw3q/Rd5KLd1aiPQjyYoXovIPyAxo148oiJ5RY/zhMDrTMNLvW5wExl3Be4VX3Fjuy8p99IyJsBNuMeyQAwE4UwXINWFMWvmeIi3ExUEW1wL6Nnu+if3c0urdHjU483rQR50+R72T7ywAEZYZtvQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724694103; c=relaxed/simple; bh=6zSzFZFe3h3eDhLBMdxRCjldoMTaVeuNKbeAxFerYFM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Jy4s6vJn3/HCQmTFSd1sL/WRrnGVS9eYICBLjY6dJRx7JYuDFChtMhWb1adBgQkoM5lTinkm8gHaJtWxzzvDPkFCzYyP0o2rR3zHozlnoXnLs+kgyg1cT0ocHRJQJdx3UM3H6ziJUgZmlWUhDBumDWacxu87TXaEh7w1YibDJzw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=g+6DJzEw; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="g+6DJzEw" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-201ee6b084bso38508605ad.2; Mon, 26 Aug 2024 10:41:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724694102; x=1725298902; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4mDuiAC/qu6w0a6uIXp9njoo4Dr+YYWiFR0sSENdoEE=; b=g+6DJzEwpssJzwmQ5tps0j6xJX1FYwlAz3MuPhV1pnIfRq1OvMtb+IH06pb4eQkoKU IXKZTnP0b6pXscyk3gVj2kE3/CmVvIrlZyCXSLkFceGiI474f9UigXN/b0l4SpxLTBof pPqb5l5jz7mG/vwbpqs+yWBMm7gS719GAqnD0At0HoYIRVI+LmQk7hpAZ1a8irZp0mxk RN+t+V0T9LmkMI37iqfrrTmMzVoQrp9+7rikxPwvGIboxJ9A5iyFaq7JoXWp5DiUmc8w lOD/Qn1SfCbg77slZlepar2OGFnFOASJJ592XZVRn/Scf1xsA2ZafNBxPKJi2QwYzf1O WK2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724694102; x=1725298902; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4mDuiAC/qu6w0a6uIXp9njoo4Dr+YYWiFR0sSENdoEE=; b=YNW3AQgIE06HBs9N7omzJ9EXvgMNh0TFQm0sXUddreJLRIQ9lQ3yCRheNq5mxjZMxt 5OfWJtSoDEz+gg2CtU/RkazwdbUEKeWsmjSiKgQ1GvmamO13Wr36D9KiGv5dlEU0J1rI oPdxkK5WWOOXTQNAECK+wk3hMdl8hOXTBPHbq2BIa7OYL+N8Ri4sFWiARqvaN7mPSPwI Q+59SCwwvm9TYCyI783paJUsUgbe7q6QjFyuuHH26IHmSkF8mBu/cp461yMPa+yMAE5J JIg8z5Lx6xc81w57iBqZBqBwh5DFqV/v4DLCcsCFrW1l+nIMtRQzJubGNQeh/lkIBh7t Js4A== X-Forwarded-Encrypted: i=1; AJvYcCWfSn/gqQ3ByMS6ArI0860XW/boT4CBOwn/mEg8Lsv1TgrapvYBSQt43ekoSdJy3fgUcY4jc+6MySuTA1k=@vger.kernel.org X-Gm-Message-State: AOJu0YzxiovXZ+AbKWa6UWJzEajtuoYtMhFs1VI3WxDnLYvzfWBGcvhT JU51asXB4HBC9G3fBOETt1ZTNd2aVQHBZ5RrGxlBrIgPk3JyK4PZ X-Google-Smtp-Source: AGHT+IFQsvLgChmY/9YM/SfmKmalDY6bnJ6mGedeMf7oyl3XF5pZSBBSTYNl1jM6mDoQyb4RKdoPwQ== X-Received: by 2002:a17:902:9892:b0:202:49ea:b6f4 with SMTP id d9443c01a7336-204df4853f0mr2460755ad.37.1724694101522; Mon, 26 Aug 2024 10:41:41 -0700 (PDT) Received: from carrot.. (i222-151-34-139.s42.a014.ap.plala.or.jp. [222.151.34.139]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855665besm70057055ad.34.2024.08.26.10.41.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 10:41:40 -0700 (PDT) From: Ryusuke Konishi To: Andrew Morton Cc: linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/8] nilfs2: do not repair reserved inode bitmap in nilfs_new_inode() Date: Tue, 27 Aug 2024 02:41:13 +0900 Message-Id: <20240826174116.5008-6-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240826174116.5008-1-konishi.ryusuke@gmail.com> References: <20240826174116.5008-1-konishi.ryusuke@gmail.com> 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 Content-Type: text/plain; charset="utf-8" After commit 93aef9eda1ce ("nilfs2: fix incorrect inode allocation from reserved inodes") is applied, the inode number returned by nilfs_ifile_create_inode() is guaranteed to always be greater than or equal to NILFS_USER_INO, so if the inode number is a reserved inode number (less than NILFS_USER_INO), the code to repair the bitmap immediately following it is no longer executed. So, delete it. Signed-off-by: Ryusuke Konishi --- fs/nilfs2/inode.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c index 3c4a0577bc71..3742baec4920 100644 --- a/fs/nilfs2/inode.c +++ b/fs/nilfs2/inode.c @@ -345,19 +345,6 @@ struct inode *nilfs_new_inode(struct inode *dir, umode= _t mode) if (unlikely(err)) goto failed_ifile_create_inode; /* reference count of i_bh inherits from nilfs_mdt_read_block() */ - - if (unlikely(ino < NILFS_USER_INO)) { - nilfs_warn(sb, - "inode bitmap is inconsistent for reserved inodes"); - do { - brelse(bh); - err =3D nilfs_ifile_create_inode(root->ifile, &ino, &bh); - if (unlikely(err)) - goto failed_ifile_create_inode; - } while (ino < NILFS_USER_INO); - - nilfs_info(sb, "repaired inode bitmap for reserved inodes"); - } ii->i_bh =3D bh; =20 atomic64_inc(&root->inodes_count); --=20 2.34.1 From nobody Sun Feb 8 03:10:30 2026 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6534C199FC9; Mon, 26 Aug 2024 17:41:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724694105; cv=none; b=cp8l3CEEzEusr8jAGT3whjDI7IBP+gIfEl4P3xyHlW6XqfpY6/UWCJVQQ09fpi5PQ4fhyCl+a3cTLW4MqBVxt03Y+V3LqChcYtSwcyiEvGe9Vr8HAI3XAp9z8N4zFXob8+wsJbJ69GQ0cEBc6ZsaxvFDeiPXEkWr/cGmcU2KURU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724694105; c=relaxed/simple; bh=ToL2x8xnfHrosgb8aQift+NPFQhBnl5Skyt2L9eY3mc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cPfY2smAaM8ByhsBDeXIlKFiVNzRDhs3zhLjF4sv6zoQyaBy5ZNBPjNQN8Go8GCzoM1u79KeogS/j7pEgBiiJTB5qaZet+yUf9Wx7iqxafANpLZD1CdplJefwbzs6mBobqm5CDG6P76XvpoFca2AexkuqwDWmDeAX8jXrbBJYvA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=jjS5I01m; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="jjS5I01m" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-713edc53429so3376547b3a.2; Mon, 26 Aug 2024 10:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724694104; x=1725298904; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/L0zziEopy1k9FRIPuSPnxsmn0iKwFK/QqP/AQhKzkw=; b=jjS5I01m/zXV45R48kIGNYn/0W1UHCE2gutbXzOQoLFd9wvCjtVny4TuM08OjzdMtG b43ltNgVSMBpX+c1/+VA0i+bSzUlbGmjhMCUP53/EacIJsWqE68DoL/Kf/b5dcWlV+eZ RXBuY0kRnROJHahoueQHLDw0sjH5LpTwCJzr7S4WBJMwcrMi41xhpMy6MuC4WUSrPX9B Z410NMqFLTWxUqaCuzJq7oVDXs0sGEh6GzWeyC+hnF3XUXtdZXj+p5U2pINBGJI9JF+G ydYluF3qR9bkpFtXrsJvQVsdxY9VgWv9+20cjqTkRogYKY/vOIfsU0ttnzD6GDMCguTm q/RA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724694104; x=1725298904; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/L0zziEopy1k9FRIPuSPnxsmn0iKwFK/QqP/AQhKzkw=; b=Q89eqK44rwx40HP3yT513ogIU+0Yueu8w07CAEwHLbtQiJ9Dq9gHVxxPVWFVmeuQ0B wlkdUpTkP6FMnYCqNYQXVPexfCTtqzhezEP+ud/7eaoyriWX2j6/k2HiGvbNCU6+v7ju 7uvsXWRu1rHVdzjE5pUtjcqfJT/BXYPJvcJr+SjWyPrhhitA9CYjrM6QClLVc66XH5Xp cW0cbJymeYp2QaQ8jxCgOIDpUysjkDQUWRjwlXOprtj1S5IrRuytrFmJurSQM+4ltg7s tCvvuCXN4p7dVtb8YVk+6oPJVEf97iSzN8CHEo6NTNWwV3OE7jbcrLk5j9chLIJN2SZw xmlg== X-Forwarded-Encrypted: i=1; AJvYcCWfUbKBNDHir1xyLyNAjrm1iasG0GagGUCjP2Ge49S7lrn7ZkG2wv/boz8Gnxmx644MwrlArIdwwpF/Uw0=@vger.kernel.org X-Gm-Message-State: AOJu0YwdAI3ZHFXtKkw7bG8nBs8ctVVHajt+8X5OLZReQdz9YXswDlfr 6z4DlsSZzn+mWiShwj+AQ1IE+3FcspJ1cKFJ0YEFt6qQ249st3mp1jVOLw== X-Google-Smtp-Source: AGHT+IFPRbF8DdghPhc67ld4MgpjA50rrPgbVagXiI6O40OgDdIbPzGFYNj6B88f6/vUgz410lmFxQ== X-Received: by 2002:a05:6a20:9e4e:b0:1cc:be05:ffe2 with SMTP id adf61e73a8af0-1ccc087617cmr408623637.18.1724694103492; Mon, 26 Aug 2024 10:41:43 -0700 (PDT) Received: from carrot.. (i222-151-34-139.s42.a014.ap.plala.or.jp. [222.151.34.139]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855665besm70057055ad.34.2024.08.26.10.41.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 10:41:42 -0700 (PDT) From: Ryusuke Konishi To: Andrew Morton Cc: linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/8] nilfs2: remove sc_timer_task Date: Tue, 27 Aug 2024 02:41:14 +0900 Message-Id: <20240826174116.5008-7-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240826174116.5008-1-konishi.ryusuke@gmail.com> References: <20240826174116.5008-1-konishi.ryusuke@gmail.com> 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 Content-Type: text/plain; charset="utf-8" After commit f5d4e04634c9 ("nilfs2: fix use-after-free of timer for log writer thread") is applied, nilfs_construct_timeout(), which is called by a timer and wakes up the log writer thread, is never called after the log writer thread has terminated. As a result, the member variable "sc_timer_task" of the "nilfs_sc_info" structure, which was added when timer_setup() was adopted to retain a reference to the log writer thread's task even after it had terminated, is no longer needed, as it should be; we can simply use "sc_task" instead, which holds a reference to the log writer thread's task for its lifetime. So, eliminate "sc_timer_task" by this means. Signed-off-by: Ryusuke Konishi --- fs/nilfs2/segment.c | 3 +-- fs/nilfs2/segment.h | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c index 206066ce6d00..225f61ef66e7 100644 --- a/fs/nilfs2/segment.c +++ b/fs/nilfs2/segment.c @@ -2504,7 +2504,7 @@ static void nilfs_construction_timeout(struct timer_l= ist *t) { struct nilfs_sc_info *sci =3D from_timer(sci, t, sc_timer); =20 - wake_up_process(sci->sc_timer_task); + wake_up_process(sci->sc_task); } =20 static void @@ -2642,7 +2642,6 @@ static int nilfs_segctor_thread(void *arg) struct the_nilfs *nilfs =3D sci->sc_super->s_fs_info; int timeout =3D 0; =20 - sci->sc_timer_task =3D current; timer_setup(&sci->sc_timer, nilfs_construction_timeout, 0); =20 /* start sync. */ diff --git a/fs/nilfs2/segment.h b/fs/nilfs2/segment.h index 2499721ebcc9..7d1160a266df 100644 --- a/fs/nilfs2/segment.h +++ b/fs/nilfs2/segment.h @@ -115,7 +115,6 @@ struct nilfs_segsum_pointer { * @sc_lseg_stime: Start time of the latest logical segment * @sc_watermark: Watermark for the number of dirty buffers * @sc_timer: Timer for segctord - * @sc_timer_task: Thread woken up by @sc_timer * @sc_task: current thread of segctord */ struct nilfs_sc_info { @@ -172,7 +171,6 @@ struct nilfs_sc_info { unsigned long sc_watermark; =20 struct timer_list sc_timer; - struct task_struct *sc_timer_task; struct task_struct *sc_task; }; =20 --=20 2.34.1 From nobody Sun Feb 8 03:10:30 2026 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 94ECD19AA5F; Mon, 26 Aug 2024 17:41:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724694108; cv=none; b=qsmrdHtQFbMFAefskCcDLbx32taGRHa8PBYwrcBm6K/2BD+E6tMm0M0NoyGcY8Yv2DvxtTOHHaCtMc/xezxTh5WUpxMeruiQapv5K9diOAbrG8rYu181Irs72x2MX0W0oXW2P59qJ5JV9our+oR/fS1uAr2HIAcv1aQcPqPc+2k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724694108; c=relaxed/simple; bh=v0gjB22Au6ZBffPsE+u+TBMr4uxhnaGhXcb+6IwJlYU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UHgE56QckgbEAp/88YPvRXDynpqca8F80KgipoE7Pc/cUh0gR0ZFpIse3Bl2OUXTiiWU8qlxpS36xVa/u24GM1jCQzsfbiX5fb72v4Vtn18CkMdrY20yb6udwOr1QEg9np3POGaX9hQvnQueO1z+CRh5VMLa+PSBZAOPBn2JrAY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=k41Qle4G; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="k41Qle4G" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2021c08b95cso42425095ad.0; Mon, 26 Aug 2024 10:41:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724694106; x=1725298906; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sxBPu0aX8e4MOrJfmUcokpiujmjulqV2zZPPRHbAgvU=; b=k41Qle4Gi74mWC3hFDbx81GAW949xtAaEJ/2SiIpu1JHM0BLHVfj/hZ+1e/eqy5pdU +0LEfiaODVwiyTTxkBCyg30tSFj+dZjHv67eobBprDEI6s4f2Wu6bVs1rAKrhN/w2oYh BSXK8Q7DxgLy/yQ6AvOhBnnw9b6IN67QiCrR7CTqoyu7LAEFxtuYVJinsEgkLT9YfXz2 DxFE5SfC40DBpcI53rsjQVEn28S/QR3Moi/hQ9HD4qglgeinfV8kqmTchD4G2l4t8y8e 57Va1x5U2vp739Bum42F8ILpzyxQjcS7qLG/GpdoguuXVkToZxH7mIrF8/eFhN3HVRJV rMcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724694106; x=1725298906; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sxBPu0aX8e4MOrJfmUcokpiujmjulqV2zZPPRHbAgvU=; b=fmpThJ2N7xgjN1y2DxhJKx+ATp1kJ7wucaKin6ruHXOO95qhruUISdazUrOm73HIWc 1g7f+meLjogMgcKsGWvTWwip52UpHBYKKIHdDgbMqu9gjX52Dkgx3NHfBs4xWQ0lWv64 1rVpX3/uPV7ZzjwzKVV9t6+UjDnsujO0ZwP5Jpy3VY4IAxUu7zlQcC9MmDM4xVjo2aEw oXz7iLFUR7MItirF22FFR78OWv1S11kr9WHKKUA+Y+Ei61nuNkZm+0paUgEQCuw1ex1+ h5JdjVj2TFaRhD03MIJZ+2ae5LBdj3xsS71iLJuGkcKuYJDaiR6OjGFeT1+AIZspawPh CgrA== X-Forwarded-Encrypted: i=1; AJvYcCUuVPS7DIZ/pgXCXdLw8t7i4NGRAkXRqq72aawweHTeuUW3a3Dxn9Tt4An13Ls/YoZqyuvdhg5IVw2Hsmw=@vger.kernel.org X-Gm-Message-State: AOJu0YyeSKO43gbmCA6KTfMPdikqWfw7SgFSI1K/H7ZhxmoIOPu6o1C3 G5De5KTy217zETtcIX938xq2KC01CNawocRWIAmJYtJC5XEL3+ZKxX3Hfw== X-Google-Smtp-Source: AGHT+IE5X+eC/iQDQoLxS2D0z0jqiOyhoF5w9vM9hw7jhYsB3Mdvm47CVzZXkq1KS6NYpCfTPJ4bQw== X-Received: by 2002:a17:902:c713:b0:1fd:6ca4:f987 with SMTP id d9443c01a7336-204ddd25f60mr4450335ad.15.1724694105501; Mon, 26 Aug 2024 10:41:45 -0700 (PDT) Received: from carrot.. (i222-151-34-139.s42.a014.ap.plala.or.jp. [222.151.34.139]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855665besm70057055ad.34.2024.08.26.10.41.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 10:41:44 -0700 (PDT) From: Ryusuke Konishi To: Andrew Morton Cc: linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 7/8] nilfs2: use kthread_create and kthread_stop for the log writer thread Date: Tue, 27 Aug 2024 02:41:15 +0900 Message-Id: <20240826174116.5008-8-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240826174116.5008-1-konishi.ryusuke@gmail.com> References: <20240826174116.5008-1-konishi.ryusuke@gmail.com> 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 Content-Type: text/plain; charset="utf-8" By using kthread_create() and kthread_stop() to start and stop the log writer thread, eliminate custom thread start and stop helpers, as well as the wait queue "sc_wait_task" on the "nilfs_sc_info" struct and NILFS_SEGCTOR_QUIT flag that exist only to implement them. Also, update the kernel doc comments of the changed functions as appropriate. Signed-off-by: Ryusuke Konishi --- fs/nilfs2/segment.c | 82 +++++++++++++++++---------------------------- fs/nilfs2/segment.h | 3 -- 2 files changed, 31 insertions(+), 54 deletions(-) diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c index 225f61ef66e7..013262ab5169 100644 --- a/fs/nilfs2/segment.c +++ b/fs/nilfs2/segment.c @@ -2630,11 +2630,15 @@ static int nilfs_segctor_flush_mode(struct nilfs_sc= _info *sci) } =20 /** - * nilfs_segctor_thread - main loop of the segment constructor thread. + * nilfs_segctor_thread - main loop of the log writer thread * @arg: pointer to a struct nilfs_sc_info. * - * nilfs_segctor_thread() initializes a timer and serves as a daemon - * to execute segment constructions. + * nilfs_segctor_thread() is the main loop function of the log writer kern= el + * thread, which determines whether log writing is necessary, and if so, + * performs the log write in the background, or waits if not. It is also + * used to decide the background writeback of the superblock. + * + * Return: Always 0. */ static int nilfs_segctor_thread(void *arg) { @@ -2642,11 +2646,6 @@ static int nilfs_segctor_thread(void *arg) struct the_nilfs *nilfs =3D sci->sc_super->s_fs_info; int timeout =3D 0; =20 - timer_setup(&sci->sc_timer, nilfs_construction_timeout, 0); - - /* start sync. */ - sci->sc_task =3D current; - wake_up(&sci->sc_wait_task); /* for nilfs_segctor_start_thread() */ nilfs_info(sci->sc_super, "segctord starting. Construction interval =3D %lu seconds, CP frequen= cy < %lu seconds", sci->sc_interval / HZ, sci->sc_mjcp_freq / HZ); @@ -2657,7 +2656,7 @@ static int nilfs_segctor_thread(void *arg) for (;;) { int mode; =20 - if (sci->sc_state & NILFS_SEGCTOR_QUIT) + if (kthread_should_stop()) goto end_thread; =20 if (timeout || sci->sc_seq_request !=3D sci->sc_seq_done) @@ -2711,41 +2710,10 @@ static int nilfs_segctor_thread(void *arg) /* end sync. */ sci->sc_task =3D NULL; timer_shutdown_sync(&sci->sc_timer); - wake_up(&sci->sc_wait_task); /* for nilfs_segctor_kill_thread() */ spin_unlock(&sci->sc_state_lock); return 0; } =20 -static int nilfs_segctor_start_thread(struct nilfs_sc_info *sci) -{ - struct task_struct *t; - - t =3D kthread_run(nilfs_segctor_thread, sci, "segctord"); - if (IS_ERR(t)) { - int err =3D PTR_ERR(t); - - nilfs_err(sci->sc_super, "error %d creating segctord thread", - err); - return err; - } - wait_event(sci->sc_wait_task, sci->sc_task !=3D NULL); - return 0; -} - -static void nilfs_segctor_kill_thread(struct nilfs_sc_info *sci) - __acquires(&sci->sc_state_lock) - __releases(&sci->sc_state_lock) -{ - sci->sc_state |=3D NILFS_SEGCTOR_QUIT; - - while (sci->sc_task) { - wake_up(&sci->sc_wait_daemon); - spin_unlock(&sci->sc_state_lock); - wait_event(sci->sc_wait_task, sci->sc_task =3D=3D NULL); - spin_lock(&sci->sc_state_lock); - } -} - /* * Setup & clean-up functions */ @@ -2766,7 +2734,6 @@ static struct nilfs_sc_info *nilfs_segctor_new(struct= super_block *sb, =20 init_waitqueue_head(&sci->sc_wait_request); init_waitqueue_head(&sci->sc_wait_daemon); - init_waitqueue_head(&sci->sc_wait_task); spin_lock_init(&sci->sc_state_lock); INIT_LIST_HEAD(&sci->sc_dirty_files); INIT_LIST_HEAD(&sci->sc_segbufs); @@ -2821,8 +2788,12 @@ static void nilfs_segctor_destroy(struct nilfs_sc_in= fo *sci) =20 up_write(&nilfs->ns_segctor_sem); =20 + if (sci->sc_task) { + wake_up(&sci->sc_wait_daemon); + kthread_stop(sci->sc_task); + } + spin_lock(&sci->sc_state_lock); - nilfs_segctor_kill_thread(sci); flag =3D ((sci->sc_state & NILFS_SEGCTOR_COMMIT) || sci->sc_flush_request || sci->sc_seq_request !=3D sci->sc_seq_done); spin_unlock(&sci->sc_state_lock); @@ -2870,14 +2841,15 @@ static void nilfs_segctor_destroy(struct nilfs_sc_i= nfo *sci) * This allocates a log writer object, initializes it, and starts the * log writer. * - * Return Value: On success, 0 is returned. On error, one of the following - * negative error code is returned. - * - * %-ENOMEM - Insufficient memory available. + * Return: 0 on success, or the following negative error code on failure. + * * %-EINTR - Log writer thread creation failed due to interruption. + * * %-ENOMEM - Insufficient memory available. */ int nilfs_attach_log_writer(struct super_block *sb, struct nilfs_root *roo= t) { struct the_nilfs *nilfs =3D sb->s_fs_info; + struct nilfs_sc_info *sci; + struct task_struct *t; int err; =20 if (nilfs->ns_writer) { @@ -2890,15 +2862,23 @@ int nilfs_attach_log_writer(struct super_block *sb,= struct nilfs_root *root) return 0; } =20 - nilfs->ns_writer =3D nilfs_segctor_new(sb, root); - if (!nilfs->ns_writer) + sci =3D nilfs_segctor_new(sb, root); + if (unlikely(!sci)) return -ENOMEM; =20 - err =3D nilfs_segctor_start_thread(nilfs->ns_writer); - if (unlikely(err)) + nilfs->ns_writer =3D sci; + t =3D kthread_create(nilfs_segctor_thread, sci, "segctord"); + if (IS_ERR(t)) { + err =3D PTR_ERR(t); + nilfs_err(sb, "error %d creating segctord thread", err); nilfs_detach_log_writer(sb); + return err; + } + sci->sc_task =3D t; + timer_setup(&sci->sc_timer, nilfs_construction_timeout, 0); =20 - return err; + wake_up_process(sci->sc_task); + return 0; } =20 /** diff --git a/fs/nilfs2/segment.h b/fs/nilfs2/segment.h index 7d1160a266df..f723f47ddc4e 100644 --- a/fs/nilfs2/segment.h +++ b/fs/nilfs2/segment.h @@ -105,7 +105,6 @@ struct nilfs_segsum_pointer { * @sc_flush_request: inode bitmap of metadata files to be flushed * @sc_wait_request: Client request queue * @sc_wait_daemon: Daemon wait queue - * @sc_wait_task: Start/end wait queue to control segctord task * @sc_seq_request: Request counter * @sc_seq_accepted: Accepted request count * @sc_seq_done: Completion counter @@ -158,7 +157,6 @@ struct nilfs_sc_info { =20 wait_queue_head_t sc_wait_request; wait_queue_head_t sc_wait_daemon; - wait_queue_head_t sc_wait_task; =20 __u32 sc_seq_request; __u32 sc_seq_accepted; @@ -191,7 +189,6 @@ enum { }; =20 /* sc_state */ -#define NILFS_SEGCTOR_QUIT 0x0001 /* segctord is being destroyed */ #define NILFS_SEGCTOR_COMMIT 0x0004 /* committed transaction exists */ =20 /* --=20 2.34.1 From nobody Sun Feb 8 03:10:30 2026 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 755B619AD73; Mon, 26 Aug 2024 17:41:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724694110; cv=none; b=mwHg7udhZDnTAVqBpJgoiOy9IKDx/eBnup2/79c8lnd4GzZWTINFLps1BfklqmKhPgAZJadcAPUalO+Myti7war80Q1rPxtSMgupiz4jETCL7I1kyKxFJ+r+/YkbrlWjfnfyM7HeZWUAKlUkgwkJpoaNyjbEx0qq/Vpz5vjWr/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724694110; c=relaxed/simple; bh=JtFDI4yYUQR700ra8I78LsXDmojzhmbA+0CKHi3GxWs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gaif3GRnxWOTecOPmY1Db7waI8oFjyov+6/ruTWGG4CXS0B9m+hzKdlK71VD4IYlrl4Hw49z66vd+nU5/6LIj/MQ6clCCRVuMSi+iLNO9b8z3g0zvMxSo5iValOwp5dzu+ZvuwVmStU4kgxYcaBPZhTzKfxe+JtoL5DCc/QjDac= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=aBXfMHec; arc=none smtp.client-ip=209.85.214.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="aBXfMHec" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-1fec34f94abso44445005ad.2; Mon, 26 Aug 2024 10:41:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724694108; x=1725298908; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=bXIcye025aQHp4YYCJd3WvJxtsBbB399iGk/S5LYEJw=; b=aBXfMHecIOKzr+NDNn3DNEm+ZN6BCy+arjxmqSBrYIF/qNp+OLuUwpysQaKK0iMXZz awWSsvOKDsbVSiZvQjV44Y1/V1kpwkNgg/tworXHv7jg2gbm00O/VuwJhMngDj55YpFV wy3XoUv3NAhZCZR/iRuKDnf3DWTStkfO+td4yT+6XQe0didN7uaNsad7fMc95NRk1jDb udib7KJNBhGsf5QuT5yEWNelKEVihb+KXBDteShxRFzMkDGe5Ikmoe0gbvwDHBMdIcU7 K3byzQlNwHvToKgtFbQHyP1lgO8pu7Gk8czy6waOSAdQ+ngpXyD7KLdqqWUPVwnpfxNB QIYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724694108; x=1725298908; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=bXIcye025aQHp4YYCJd3WvJxtsBbB399iGk/S5LYEJw=; b=TGybM8Jf0rfQNbyavgnvWpjkkmLLYqqK0EVimWaXJUfssrtR/KmxjRLDANBJJqvLNE 7LbfxYGyzuDDUZ1+UWts/tb5Kd4+SlulgLMTFA5zT3P6C2g0B3HK8b1oiooBDaSNGHDx paF7kpxID5YnrHSujqo4lQYUSoO/ZG6CDuBnyNjn4wsGDZ1NdV1rul9Q5zhFGmkg/VrN Mnw8QVOWYinvQ8NFzHrJA3XxbNrg+ei+y5Bbf3+E/CRqkBoVJKkTqLHxFaB3U0CI+8mo W+YyqvCzXQ5tghnFeaaRsnlfDkX71eRNG7bPq1pPI1dW/bSaicoSP9HPJQxcNHQ+wvKu AzVw== X-Forwarded-Encrypted: i=1; AJvYcCVg9B0I6ovmNqHAR2g2v7aqQhBwpj+6A5ZpFckswkgraq7FRMDxGxd+UpLnjGcQkye/oAdmEheGQK+GwIA=@vger.kernel.org X-Gm-Message-State: AOJu0YxGFTpyiVrNBYqZ4j+min/0QOtMcMVDVrSMVP1PURfZyaDuZ1yi JeSzV9llwr4hvIn7mLi1N54LbP24VQX10gSDWKBWZ8amArc6H9QWG4j2Ag== X-Google-Smtp-Source: AGHT+IEuHWgkuL52jNVrRqBi5Dk/bYdiYqV3bUqR8iI9vQgpPcaSTNT26tXSur1BopD7YCMV2M7gJA== X-Received: by 2002:a17:902:e812:b0:202:859:f85 with SMTP id d9443c01a7336-2039e489273mr114680635ad.24.1724694107498; Mon, 26 Aug 2024 10:41:47 -0700 (PDT) Received: from carrot.. (i222-151-34-139.s42.a014.ap.plala.or.jp. [222.151.34.139]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-203855665besm70057055ad.34.2024.08.26.10.41.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Aug 2024 10:41:46 -0700 (PDT) From: Ryusuke Konishi To: Andrew Morton Cc: linux-nilfs@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 8/8] nilfs2: refactor nilfs_segctor_thread() Date: Tue, 27 Aug 2024 02:41:16 +0900 Message-Id: <20240826174116.5008-9-konishi.ryusuke@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240826174116.5008-1-konishi.ryusuke@gmail.com> References: <20240826174116.5008-1-konishi.ryusuke@gmail.com> 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 Content-Type: text/plain; charset="utf-8" Simplify nilfs_segctor_thread(), the main loop function of the log writer thread, to make the basic structure easier to understand. In particular, the acquisition and release of the sc_state_lock spinlock was scattered throughout the function, so extract the determination of whether log writing is required into a helper function and make the spinlock lock sections clearer. Signed-off-by: Ryusuke Konishi --- fs/nilfs2/segment.c | 85 +++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 45 deletions(-) diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c index 013262ab5169..587251830897 100644 --- a/fs/nilfs2/segment.c +++ b/fs/nilfs2/segment.c @@ -2629,6 +2629,32 @@ static int nilfs_segctor_flush_mode(struct nilfs_sc_= info *sci) return SC_LSEG_SR; } =20 +/** + * nilfs_log_write_required - determine whether log writing is required + * @sci: nilfs_sc_info struct + * @modep: location for storing log writing mode + * + * Return: true if log writing is required, false otherwise. If log writi= ng + * is required, the mode is stored in the location pointed to by @modep. + */ +static bool nilfs_log_write_required(struct nilfs_sc_info *sci, int *modep) +{ + bool timedout, ret =3D true; + + spin_lock(&sci->sc_state_lock); + timedout =3D ((sci->sc_state & NILFS_SEGCTOR_COMMIT) && + time_after_eq(jiffies, sci->sc_timer.expires)); + if (timedout || sci->sc_seq_request !=3D sci->sc_seq_done) + *modep =3D SC_LSEG_SR; + else if (sci->sc_flush_request) + *modep =3D nilfs_segctor_flush_mode(sci); + else + ret =3D false; + + spin_unlock(&sci->sc_state_lock); + return ret; +} + /** * nilfs_segctor_thread - main loop of the log writer thread * @arg: pointer to a struct nilfs_sc_info. @@ -2644,70 +2670,39 @@ static int nilfs_segctor_thread(void *arg) { struct nilfs_sc_info *sci =3D (struct nilfs_sc_info *)arg; struct the_nilfs *nilfs =3D sci->sc_super->s_fs_info; - int timeout =3D 0; =20 nilfs_info(sci->sc_super, "segctord starting. Construction interval =3D %lu seconds, CP frequen= cy < %lu seconds", sci->sc_interval / HZ, sci->sc_mjcp_freq / HZ); =20 set_freezable(); - spin_lock(&sci->sc_state_lock); - loop: - for (;;) { - int mode; - - if (kthread_should_stop()) - goto end_thread; - - if (timeout || sci->sc_seq_request !=3D sci->sc_seq_done) - mode =3D SC_LSEG_SR; - else if (sci->sc_flush_request) - mode =3D nilfs_segctor_flush_mode(sci); - else - break; - - spin_unlock(&sci->sc_state_lock); - nilfs_segctor_thread_construct(sci, mode); - spin_lock(&sci->sc_state_lock); - timeout =3D 0; - } =20 - - if (freezing(current)) { - spin_unlock(&sci->sc_state_lock); - try_to_freeze(); - spin_lock(&sci->sc_state_lock); - } else { + while (!kthread_should_stop()) { DEFINE_WAIT(wait); - int should_sleep =3D 1; + bool should_write; + int mode; + + if (freezing(current)) { + try_to_freeze(); + continue; + } =20 prepare_to_wait(&sci->sc_wait_daemon, &wait, TASK_INTERRUPTIBLE); - - if (sci->sc_seq_request !=3D sci->sc_seq_done) - should_sleep =3D 0; - else if (sci->sc_flush_request) - should_sleep =3D 0; - else if (sci->sc_state & NILFS_SEGCTOR_COMMIT) - should_sleep =3D time_before(jiffies, - sci->sc_timer.expires); - - if (should_sleep) { - spin_unlock(&sci->sc_state_lock); + should_write =3D nilfs_log_write_required(sci, &mode); + if (!should_write) schedule(); - spin_lock(&sci->sc_state_lock); - } finish_wait(&sci->sc_wait_daemon, &wait); - timeout =3D ((sci->sc_state & NILFS_SEGCTOR_COMMIT) && - time_after_eq(jiffies, sci->sc_timer.expires)); =20 if (nilfs_sb_dirty(nilfs) && nilfs_sb_need_update(nilfs)) set_nilfs_discontinued(nilfs); + + if (should_write) + nilfs_segctor_thread_construct(sci, mode); } - goto loop; =20 - end_thread: /* end sync. */ + spin_lock(&sci->sc_state_lock); sci->sc_task =3D NULL; timer_shutdown_sync(&sci->sc_timer); spin_unlock(&sci->sc_state_lock); --=20 2.34.1