Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751723AbdF2Ehb (ORCPT ); Thu, 29 Jun 2017 00:37:31 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:33279 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751545AbdF2Eh1 (ORCPT ); Thu, 29 Jun 2017 00:37:27 -0400 From: William Koh To: Andreas Dilger CC: "Theodore Ts'o" , linux-ext4 , lkml , Kernel Team , "J. Bruce Fields" , linux-fsdevel , Trond Myklebust Subject: Re: [PATCH] fs: ext4: inode->i_generation not assigned 0. Thread-Topic: [PATCH] fs: ext4: inode->i_generation not assigned 0. Thread-Index: AQHS8Frhf5zD+VA+OkO552aALR7fE6I7HxsA//+tlgA= Date: Thu, 29 Jun 2017 04:37:14 +0000 Message-ID: <7CD38230-D961-428F-B2E9-2C0E28CAF442@fb.com> References: <20A40B3C-E179-432B-B56F-BDAAF0CD2E1F@dilger.ca> In-Reply-To: <20A40B3C-E179-432B-B56F-BDAAF0CD2E1F@dilger.ca> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: dilger.ca; dkim=none (message not signed) header.d=none;dilger.ca; dmarc=none action=none header.from=fb.com; x-originating-ip: [2620:10d:c090:180::1:4632] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;CY4PR15MB1607;20:gkER3NbvbX0CsuYFU7b2163sP182jd/8W9rCXngIYZNBp0c59k/3W7O3mQ8vHVBMbFjbWEb0FylgBf2VdjSVGuFD4/xBEo4k9a4PSofIobavnClAEsMFfppNcz1YIyTOOAuEsbp0voOy4key3lGejLTfa1+G6gI4998jKYhR9fY= x-ms-office365-filtering-correlation-id: 69bc5e3b-ec88-4d7c-a9d2-08d4bea8841a x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(2017030254075)(300000503095)(300135400095)(201703131423075)(201703031133081)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095);SRVR:CY4PR15MB1607; x-ms-traffictypediagnostic: CY4PR15MB1607: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(236129657087228)(67672495146484)(148574349560750); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(5005006)(8121501046)(93006095)(93001095)(100000703101)(100105400095)(10201501046)(3002001)(6041248)(20161123555025)(20161123558100)(20161123560025)(20161123562025)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(100000704101)(100105200095)(100000705101)(100105500095);SRVR:CY4PR15MB1607;BCL:0;PCL:0;RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095);SRVR:CY4PR15MB1607; x-forefront-prvs: 0353563E2B x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(39410400002)(39840400002)(39450400003)(39400400002)(39850400002)(24454002)(43544003)(377454003)(229853002)(53546010)(2900100001)(38730400002)(82746002)(3660700001)(110136004)(305945005)(2906002)(33656002)(6246003)(4326008)(8936002)(6436002)(3280700002)(6916009)(2950100002)(83716003)(5660300001)(478600001)(7736002)(14454004)(86362001)(189998001)(8676002)(53936002)(99286003)(6486002)(54906002)(77096006)(6512007)(54356999)(76176999)(81166006)(6506006)(25786009)(50986999)(102836003)(36756003)(6116002);DIR:OUT;SFP:1102;SCL:1;SRVR:CY4PR15MB1607;H:CY4PR15MB1606.namprd15.prod.outlook.com;FPR:;SPF:None;MLV:sfv;LANG:en; spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="utf-8" Content-ID: <8A81596E499CC54E8AAC53CE7D405AA9@namprd15.prod.outlook.com> MIME-Version: 1.0 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Jun 2017 04:37:14.2002 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR15MB1607 X-OriginatorOrg: fb.com X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-06-29_03:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id v5T4bhZW031607 Content-Length: 3275 Lines: 89 On 6/28/17, 7:32 PM, "Andreas Dilger" wrote: On Jun 28, 2017, at 4:06 PM, Kyungchan Koh wrote: > > In fs/ext4/super.c, the function ext4_nfs_get_inode takes as input > "generation" that can be used to specify the generation of the inode to > be returned. When 0 is given as input, then inodes of any generation can > be returned. Therefore, generation 0 is a special case that should be > avoided when assigning generation to inodes. I'd agree with this change to avoid assigning generation == 0 to real inodes. Also, the separate question arises about whether we need to allow file handle lookup with generation == 0? That allows FID guessing easily, while requiring a non-zero generation makes that a lot harder. What are the cases where generation == 0 are used? Honestly, I’m not too sure. I just noticed that generation 0 was a special case from reading the code. > A new inline function, ext4_inode_set_gen, will take care of the > problem. Now, inodes cannot have a generation of 0, so this patch fixes > the issue. > > Signed-off-by: Kyungchan Koh > > diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h > index 3219154..74c6677 100644 > --- a/fs/ext4/ext4.h > +++ b/fs/ext4/ext4.h > @@ -1549,6 +1549,14 @@ static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino) > ino <= le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count)); > } > > +static inline void ext4_inode_set_gen(struct inode *inode, > + struct ext4_sb_info *sbi) > +{ > + inode->i_generation = sbi->s_next_generation++; > + if (!inode->i_generation) This should be marked "unlikely()" since it happens at most once every 4B file creations (though likely even less since it is unlikely that so many files will be created in a single mount). Got it. > + inode->i_generation = sbi->s_next_generation++; > +} > + > > diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c > index 98ac2f1..d33f6f0 100644 > --- a/fs/ext4/ialloc.c > +++ b/fs/ext4/ialloc.c > @@ -1072,7 +1072,7 @@ struct inode *__ext4_new_inode(handle_t *handle, struct inode } > spin_lock(&sbi->s_next_gen_lock); > - inode->i_generation = sbi->s_next_generation++; > + ext4_inode_set_gen(inode, sbi); > spin_unlock(&sbi->s_next_gen_lock); > > diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c > index 0c21e22..d52a467 100644 > --- a/fs/ext4/ioctl.c > +++ b/fs/ext4/ioctl.c > @@ -160,8 +160,8 @@ static long swap_inode_boot_loader(struct super_block *sb, > > spin_lock(&sbi->s_next_gen_lock); > - inode->i_generation = sbi->s_next_generation++; > - inode_bl->i_generation = sbi->s_next_generation++; > + ext4_inode_set_gen(inode, sbi); > + ext4_inode_set_gen(inode_bl, sbi); > spin_unlock(&sbi->s_next_gen_lock); > Cheers, Andreas This is applicable to many fs, including ext2, ext4, exofs, jfs, and f2fs. Therefore, a shared helper in linux/fs.h will allow for easy changes in all fs. Is there any reason that might be a bad idea? Best, Kyungchan Koh