From patchwork Fri Dec 8 11:23:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuezhang Mo X-Patchwork-Id: 13485310 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=foxmail.com header.i=@foxmail.com header.b="mjoU/Opw" Received: from out203-205-221-202.mail.qq.com (out203-205-221-202.mail.qq.com [203.205.221.202]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BE3110DA for ; Fri, 8 Dec 2023 03:21:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1702034489; bh=fBjHqqL/688Jd+q4DnrxTJF34FfawJT5VyX8pOqIxdE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=mjoU/Opw0ENKROLjc4OhH8Kh+FY5jfxuHqQFIFOjM71X/r/yqLMohUJT3KA2YZlkK hbeFMX38CdiYHHjf/1BpZwD6hsfv8lU3bN/FgCbmw10AQiC245D2b/pbj8FUj00cPr yRFa8enhEr1FhcKRc1hKFYGGY++Y0D8NWsJUdqI0= Received: from localhost.localdomain ([180.164.182.58]) by newxmesmtplogicsvrszc5-0.qq.com (NewEsmtp) with SMTP id 530B9A94; Fri, 08 Dec 2023 19:20:48 +0800 X-QQ-mid: xmsmtpt1702034451tylabw18y Message-ID: X-QQ-XMAILINFO: NwIPvWX4YDagzLBgX/1LcAFo6QsPqXfyFfZtRjxizTcySoZIMMp8/TIdCoEcQX spkh9OZMntSvYTu9NjmgxS0y5ME4CPccRL80MywKeM6bjNnSdUq9pEXh4R+LAyxkG7TEt+je6FdW uGO6OoqI/Q6UR8UCkDVOIstMpCrK/d8fAVBkhwJl6ysua62626v5CPjpjEhECUAcq1o8TzbDz71N cpnHu9WMQEDd5r4/5aWRmrvA3C+aCwZ+S0ZdDcVN7dY9V76CIWuPPB2Isa/vXlUpYn3DCrD1wbIB bIhZ4MyDug9Hmi1eKtSB7+81NTVDDkPOQ5w+kDuq3vc5xPYj4GMYlVkxw+1r4L/FUBVQGkvRMzYG lEvkHcPzy+v2gCXhE3956MkG00tsrC+6ACBSPJB/sWuj1C4WkXzzURKcmO2jFQFikT4oHx21D1rm ZoOPtAmHzIO+rvdasoEKa77MHH/QAw93D8Y1k0QVIiQKC5FpXxa8uJiOvtSbgCCFFs/FuqA/Kik4 qLSKcQznkZV3RV6CrZcTvMgebwaShhVMdfY80q85rq9ZknnfIQn//eltrI/smAjoIWwPmxb5NOMQ 2YTnNFot1X+w7Mdd1MnDeJCnxngbb4o5F6PAd7FII/fyDWch2hqWCy5SE6UIr+6zPvLrdt4T6bZ9 eya7z1RcaqgvFThzlkUx0QIRSwKblkh0Qf/aQinHqjpPobMvHkFOE2Gw1l0UNNAt70yvDAGObUE9 HzmiMLpVt6exrz6iLp89M9OV3diBK7c9HuYYLcOKWDJkxeVJPqVCHIg8dJDOYJPQe/io3WE4Nq/W KLJvo7HLsSUuwOH777d89uQ5152LT2pz1QCxjjsi8QvtIIMDwlF/m9VYb6UrCautEArkTxyIvzk1 /VAqFkfpazd7Ao2L/v24GOa3R/8PbGN9DUcpVGsZHOtdYoxO4hFpCWk6xhHvz+b3tMPy620XHVvH ON1TfQIokPrlm9SxPG47EFH2h95HI3 X-QQ-XMRINFO: Nq+8W0+stu50PRdwbJxPCL0= From: yuezhang.mo@foxmail.com To: linkinjeon@kernel.org, sj1557.seo@samsung.com Cc: linux-fsdevel@vger.kernel.org, Andy.Wu@sony.com, wataru.aoyama@sony.com, Yuezhang Mo Subject: [PATCH v1 01/11] exfat: add __exfat_get_dentry_set() helper Date: Fri, 8 Dec 2023 19:23:10 +0800 X-OQ-MSGID: <20231208112318.1135649-2-yuezhang.mo@foxmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231208112318.1135649-1-yuezhang.mo@foxmail.com> References: <20231208112318.1135649-1-yuezhang.mo@foxmail.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Yuezhang Mo Since exfat_get_dentry_set() invokes the validate functions of exfat_validate_entry(), it only supports getting a directory entry set of an existing file, doesn't support getting an empty entry set. To remove the limitation, add this helper. Signed-off-by: Yuezhang Mo Reviewed-by: Andy Wu Reviewed-by: Aoyama Wataru --- fs/exfat/dir.c | 61 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 21 deletions(-) diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index 9f9295847a4e..f33e40aad276 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -775,7 +775,6 @@ struct exfat_dentry *exfat_get_dentry(struct super_block *sb, } enum exfat_validate_dentry_mode { - ES_MODE_STARTED, ES_MODE_GET_FILE_ENTRY, ES_MODE_GET_STRM_ENTRY, ES_MODE_GET_NAME_ENTRY, @@ -790,11 +789,6 @@ static bool exfat_validate_entry(unsigned int type, return false; switch (*mode) { - case ES_MODE_STARTED: - if (type != TYPE_FILE && type != TYPE_DIR) - return false; - *mode = ES_MODE_GET_FILE_ENTRY; - break; case ES_MODE_GET_FILE_ENTRY: if (type != TYPE_STREAM) return false; @@ -834,7 +828,7 @@ struct exfat_dentry *exfat_get_dentry_cached( } /* - * Returns a set of dentries for a file or dir. + * Returns a set of dentries. * * Note It provides a direct pointer to bh->data via exfat_get_dentry_cached(). * User should call exfat_get_dentry_set() after setting 'modified' to apply @@ -842,22 +836,24 @@ struct exfat_dentry *exfat_get_dentry_cached( * * in: * sb+p_dir+entry: indicates a file/dir - * type: specifies how many dentries should be included. + * num_entries: specifies how many dentries should be included. + * It will be set to es->num_entries if it is not 0. + * If num_entries is 0, es->num_entries will be obtained + * from the first dentry. + * out: + * es: pointer of entry set on success. * return: - * pointer of entry set on success, - * NULL on failure. + * 0 on success + * < 0 on failure */ -int exfat_get_dentry_set(struct exfat_entry_set_cache *es, +static int __exfat_get_dentry_set(struct exfat_entry_set_cache *es, struct super_block *sb, struct exfat_chain *p_dir, int entry, - unsigned int type) + unsigned int num_entries) { int ret, i, num_bh; unsigned int off; sector_t sec; struct exfat_sb_info *sbi = EXFAT_SB(sb); - struct exfat_dentry *ep; - int num_entries; - enum exfat_validate_dentry_mode mode = ES_MODE_STARTED; struct buffer_head *bh; if (p_dir->dir == DIR_DELETED) { @@ -880,12 +876,16 @@ int exfat_get_dentry_set(struct exfat_entry_set_cache *es, return -EIO; es->bh[es->num_bh++] = bh; - ep = exfat_get_dentry_cached(es, ES_IDX_FILE); - if (!exfat_validate_entry(exfat_get_entry_type(ep), &mode)) - goto put_es; + if (num_entries == ES_ALL_ENTRIES) { + struct exfat_dentry *ep; + + ep = exfat_get_dentry_cached(es, ES_IDX_FILE); + if (ep->type == EXFAT_FILE) + num_entries = ep->dentry.file.num_ext + 1; + else + goto put_es; + } - num_entries = type == ES_ALL_ENTRIES ? - ep->dentry.file.num_ext + 1 : type; es->num_entries = num_entries; num_bh = EXFAT_B_TO_BLK_ROUND_UP(off + num_entries * DENTRY_SIZE, sb); @@ -918,8 +918,27 @@ int exfat_get_dentry_set(struct exfat_entry_set_cache *es, es->bh[es->num_bh++] = bh; } + return 0; + +put_es: + exfat_put_dentry_set(es, false); + return -EIO; +} + +int exfat_get_dentry_set(struct exfat_entry_set_cache *es, + struct super_block *sb, struct exfat_chain *p_dir, + int entry, unsigned int type) +{ + int ret, i; + struct exfat_dentry *ep; + enum exfat_validate_dentry_mode mode = ES_MODE_GET_FILE_ENTRY; + + ret = __exfat_get_dentry_set(es, sb, p_dir, entry, type); + if (ret < 0) + return ret; + /* validate cached dentries */ - for (i = ES_IDX_STREAM; i < num_entries; i++) { + for (i = ES_IDX_STREAM; i < es->num_entries; i++) { ep = exfat_get_dentry_cached(es, i); if (!exfat_validate_entry(exfat_get_entry_type(ep), &mode)) goto put_es; From patchwork Fri Dec 8 11:23:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuezhang Mo X-Patchwork-Id: 13485319 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=foxmail.com header.i=@foxmail.com header.b="acOekIFX" X-Greylist: delayed 417 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Fri, 08 Dec 2023 03:27:51 PST Received: from out203-205-221-149.mail.qq.com (out203-205-221-149.mail.qq.com [203.205.221.149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65DC01728 for ; Fri, 8 Dec 2023 03:27:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1702034869; bh=TDEZcW+cN/QurCXzzKrh9Kdn/eQHaLdTHk6ikecN9jM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=acOekIFXudarl2rCUh66HxQ/SyQzrq7dHqh0dlrZyxhcPC2jk47RCiL63kG5t9gv0 c+fu8QhXYyPjqDeFuhBqY4vQo/Qc/YZUME7DSbt6cPz0L03023tDZnTdoAqasWtvpr LrZUUfYIHQZtzSdRiuTKBiCUqU2W7xZg1ccFeDa0= Received: from localhost.localdomain ([180.164.182.58]) by newxmesmtplogicsvrszc5-0.qq.com (NewEsmtp) with SMTP id 530B9A94; Fri, 08 Dec 2023 19:20:48 +0800 X-QQ-mid: xmsmtpt1702034488tqmn5g0kc Message-ID: X-QQ-XMAILINFO: Nfm/+M6ONQ57SBF37mfK0Skp1T+DiVBWvWEqWx5AvkzQ8rGN7wzc2g5MjxXN6n ZwVaU9VmUp5GZmFXcd4Ze66Lk+XLRtp/ueAlwK4PyefjYylWq31MCN7JeFKdT8DPCY/4IMixqwr2 V7pwl2pZyzGm5Y2vXFxdInjAvIdgm7OOCu3wBhtKtMYXln5kJMxAAVNc9irIoNLxkL1MIRNbXqHj 3uV7NReOa3vAEnfG0w4BwRrWKt9hd7vu5I+VTZcmOgup4+Ei4Rr82+sdAGFkl5AqWIQ34xwEmg8t LnqheWPNA815dfs4w/tYlt8x/CcL4HJdcV2qtaJoKLc5ozBptc/M/1PnCkTIYiLyq/wzQEcxLmK3 DgU2JHunVTsUuC7TN6Iztqrot2dcW7wdNQ/pN18TFE9s09tqni1hLT/MFphTson/krJid6Zg9GuY OuM9EkM0k0qUszm8MUQ2THKQjXHrlLS0i4O305iJVWX3t9kU0hnDnAIwk6xM64IJt89VDFoBYEpu aF8bTcH2H9Eorycz9citpHYcXvMUpCKej+uDiJeXrpeCcjZpBPr5jnGRWJ2iKsogVa9bYE0MEqNi Os3o2NwtZ1WVoAQ7qdICOEJpctIYmYLhwNj/Yic5pxh0HWaixwemogowb1HXsu7d0SIgF+h1mbTX ncBywhOszIImr8D8vZGmsSgLZQLMIN6aUYaBPyW8v6Q6fsNnae3pP7c7UtWjBnGKNzfnvIKI3/zU 2NrOHL4BkL8Qrs3mjK+yTitaAGcL6c4XrJaHFo1PxhTHO6BTcwkVpmckAmPuWrnd7PyMiFk4W3aq /HlxU93Sxhqg5WMMPMtpXgtm5LNrmCFuf+fH2039Pj+avibkxHPdww+K0iQ5kWGdiuwxU4ETgisT cfTWfR4wmp+fb2BsSDy5EgfXSattiRvxiD9/GfUwuevrbT1LdSqohGlYlt9L+QjJN21r3+jK6IFL e6jgBxeSpMPIKRkwFX8x+cMlVC1MLtJw2bTBeuWSlT0UDA7nUXho+8h/vmCNtW X-QQ-XMRINFO: M/715EihBoGSf6IYSX1iLFg= From: yuezhang.mo@foxmail.com To: linkinjeon@kernel.org, sj1557.seo@samsung.com Cc: linux-fsdevel@vger.kernel.org, Andy.Wu@sony.com, wataru.aoyama@sony.com, Yuezhang Mo Subject: [PATCH v1 02/11] exfat: add exfat_get_empty_dentry_set() helper Date: Fri, 8 Dec 2023 19:23:11 +0800 X-OQ-MSGID: <20231208112318.1135649-3-yuezhang.mo@foxmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231208112318.1135649-1-yuezhang.mo@foxmail.com> References: <20231208112318.1135649-1-yuezhang.mo@foxmail.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Yuezhang Mo This helper is used to lookup empty dentry set. If there are enough empty dentries at the input location, this helper will return the number of dentries that need to be skipped for the next lookup. Signed-off-by: Yuezhang Mo Reviewed-by: Andy Wu Reviewed-by: Aoyama Wataru --- fs/exfat/dir.c | 77 +++++++++++++++++++++++++++++++++++++++++++++ fs/exfat/exfat_fs.h | 3 ++ 2 files changed, 80 insertions(+) diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index f33e40aad276..bb23585c6e7c 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -950,6 +950,83 @@ int exfat_get_dentry_set(struct exfat_entry_set_cache *es, return -EIO; } +static int exfat_validate_empty_dentry_set(struct exfat_entry_set_cache *es) +{ + struct exfat_dentry *ep; + struct buffer_head *bh; + int i, off; + bool unused_hit = false; + + for (i = 0; i < es->num_entries; i++) { + ep = exfat_get_dentry_cached(es, i); + if (ep->type == EXFAT_UNUSED) + unused_hit = true; + else if (IS_EXFAT_DELETED(ep->type)) { + if (unused_hit) + goto out; + } else { + if (unused_hit) + goto out; + + i++; + goto count_skip_entries; + } + } + + return 0; + +out: + off = es->start_off + (i << DENTRY_SIZE_BITS); + bh = es->bh[EXFAT_B_TO_BLK(off, es->sb)]; + + exfat_fs_error(es->sb, + "in sector %lld, dentry %d should be unused, but 0x%x", + bh->b_blocknr, off >> DENTRY_SIZE_BITS, ep->type); + + return -EIO; + +count_skip_entries: + es->num_entries = EXFAT_B_TO_DEN(EXFAT_BLK_TO_B(es->num_bh, es->sb) - es->start_off); + for (; i < es->num_entries; i++) { + ep = exfat_get_dentry_cached(es, i); + if (IS_EXFAT_DELETED(ep->type)) + break; + } + + return i; +} + +/* + * Get an empty dentry set. + * + * in: + * sb+p_dir+entry: indicates the empty dentry location + * num_entries: specifies how many empty dentries should be included. + * out: + * es: pointer of empty dentry set on success. + * return: + * 0 : on success + * >= 0: the dentries are not empty, the return value is the number of + * dentries to be skipped for the next lookup. + * <0 : on failure + */ +int exfat_get_empty_dentry_set(struct exfat_entry_set_cache *es, + struct super_block *sb, struct exfat_chain *p_dir, + int entry, unsigned int num_entries) +{ + int ret; + + ret = __exfat_get_dentry_set(es, sb, p_dir, entry, num_entries); + if (ret < 0) + return ret; + + ret = exfat_validate_empty_dentry_set(es); + if (ret) + exfat_put_dentry_set(es, false); + + return ret; +} + static inline void exfat_reset_empty_hint(struct exfat_hint_femp *hint_femp) { hint_femp->eidx = EXFAT_HINT_NONE; diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h index e3b1f8e022df..6dc76b3f4945 100644 --- a/fs/exfat/exfat_fs.h +++ b/fs/exfat/exfat_fs.h @@ -502,6 +502,9 @@ struct exfat_dentry *exfat_get_dentry_cached(struct exfat_entry_set_cache *es, int exfat_get_dentry_set(struct exfat_entry_set_cache *es, struct super_block *sb, struct exfat_chain *p_dir, int entry, unsigned int type); +int exfat_get_empty_dentry_set(struct exfat_entry_set_cache *es, + struct super_block *sb, struct exfat_chain *p_dir, int entry, + unsigned int num_entries); int exfat_put_dentry_set(struct exfat_entry_set_cache *es, int sync); int exfat_count_dir_entries(struct super_block *sb, struct exfat_chain *p_dir); From patchwork Fri Dec 8 11:23:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuezhang Mo X-Patchwork-Id: 13485311 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=foxmail.com header.i=@foxmail.com header.b="pPxkeGcj" Received: from out203-205-221-231.mail.qq.com (out203-205-221-231.mail.qq.com [203.205.221.231]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4599910CF for ; Fri, 8 Dec 2023 03:21:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1702034493; bh=FbtnXJicbS+oXRm4DcyjEtI+97mlthN7LzlIHvYY+hk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=pPxkeGcjq3akbSuSGvP/tzQCHZD3aPhvB/gZPMmzgFIn5Ez1bhoTrYDUu2PlxIBLb xSt1Rt4tzaLq/O2oIcvzqPxs/Wf5Mn/tt0NpX9RCOOES6Oap867xSSNkg3TnVNZ5pG nZyEJlodqlrHMMoR8JgjcytIZ6YevhqmUj7f2UnI= Received: from localhost.localdomain ([180.164.182.58]) by newxmesmtplogicsvrszc5-0.qq.com (NewEsmtp) with SMTP id 530B9A94; Fri, 08 Dec 2023 19:20:48 +0800 X-QQ-mid: xmsmtpt1702034490t1n49dn22 Message-ID: X-QQ-XMAILINFO: MW5hkHoBpWXydSCNNW9tJ3OH4KBnjaSG7SiQBr9BEDJ/XLaeo0+vMPDYMAaeLT HuAc8ktumaW4qPBVumzMQr073Xsx8QHLHK25B+k3xCz5um3LDEztfenuZkE5FvR6/2KCd5z65nde atF+/9PQ8zkPq5wxvbJcrQBxZNJQaTtUJ6kdohO+Z3ifGq07CIETv7R/13+xicbzqdnfllHLFUIB ZKKpM+4ltc5qDyAowN3lBsnft6UorYA8cznjJxR9QwPgU7GoY2byi+Og9CArVaqrmWo7HIyugrJA JPfgUSSvUFYKmRq91k94OCPSRmcIxSjsYAJjUh624ONmMxRIlWf2olPHWKUrKPBsEKX6HkXEdrf1 t7kCVk54qqSOKWZ9kh6zJEsTlrbNBosYESWy2FLIkmnjtqKyNyRxFVdHDlBWR8RnDavUq2Px73JZ NOX22cStQmYgwFcnOxLno1nIE5l9a5zFn2qxfPanOwcv+CsX22VNtLkJvgmlU8h3hq/m+hsDnK0Z uogmtH/nfXELhHrZTBpvCqhj0IL24FJUne3j59HJNqSRLPPxXvozTBokcfyq9KqoQoka+7/MR2sx xrtuDPo1eZjmbh8W3xpE1CpMAUKMBmCwkmO/9xWQBdRwy0g0IfwIIJIvwxdzH02P3+P40revydgc cFLsVYKG8baZ0u362WroSUVZ7knlhhblzv0c+xPDjBuYnuXPFKYUHfaBkwb/FDWahT+ujvCrnoLS XJpOiKHirHwkwlztC1PKrJoXA0fINat/3pb9e4XQHC93m0cY62ATeffW/m4/ZwxqvwkO4h7xmnk8 IBHXgU8pY/tukzPc2fkEVjbudpiUFQWUT0T6IVHY2rbY6esNM9DaR0t4TBisZ+pWOTFYB6oYn5Pm HeYdii4DxUt1SW8r2VpUIEZYjPmna1SAwqHPHBgOjE09Ha8Z4Kmp0z2tCRCQXdW6PTrfK4283DRv V9d8Pr6ntes0kp2nxWCtqHYzzEFF9yx36YAK4Rcq11jj30d5eC2wjZioYdur0Z X-QQ-XMRINFO: MPJ6Tf5t3I/ycC2BItcBVIA= From: yuezhang.mo@foxmail.com To: linkinjeon@kernel.org, sj1557.seo@samsung.com Cc: linux-fsdevel@vger.kernel.org, Andy.Wu@sony.com, wataru.aoyama@sony.com, Yuezhang Mo Subject: [PATCH v1 03/11] exfat: covert exfat_find_empty_entry() to use dentry cache Date: Fri, 8 Dec 2023 19:23:12 +0800 X-OQ-MSGID: <20231208112318.1135649-4-yuezhang.mo@foxmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231208112318.1135649-1-yuezhang.mo@foxmail.com> References: <20231208112318.1135649-1-yuezhang.mo@foxmail.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Yuezhang Mo Before this conversion, each dentry traversed needs to be read from the storage device or page cache. There are at least 16 dentries in a sector. This will result in frequent page cache searches. After this conversion, if all directory entries in a sector are used, the sector only needs to be read once. Signed-off-by: Yuezhang Mo Reviewed-by: Andy Wu Reviewed-by: Aoyama Wataru --- fs/exfat/namei.c | 111 ++++++++++++++++++++--------------------------- 1 file changed, 47 insertions(+), 64 deletions(-) diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c index 9c549fd11fc8..1f662296f2fa 100644 --- a/fs/exfat/namei.c +++ b/fs/exfat/namei.c @@ -204,21 +204,16 @@ const struct dentry_operations exfat_utf8_dentry_ops = { .d_compare = exfat_utf8_d_cmp, }; -/* used only in search empty_slot() */ -#define CNT_UNUSED_NOHIT (-1) -#define CNT_UNUSED_HIT (-2) /* search EMPTY CONTINUOUS "num_entries" entries */ static int exfat_search_empty_slot(struct super_block *sb, struct exfat_hint_femp *hint_femp, struct exfat_chain *p_dir, - int num_entries) + int num_entries, struct exfat_entry_set_cache *es) { - int i, dentry, num_empty = 0; + int i, dentry, ret; int dentries_per_clu; - unsigned int type; struct exfat_chain clu; - struct exfat_dentry *ep; struct exfat_sb_info *sbi = EXFAT_SB(sb); - struct buffer_head *bh; + int total_entries = EXFAT_CLU_TO_DEN(p_dir->size, sbi); dentries_per_clu = sbi->dentries_per_clu; @@ -231,7 +226,7 @@ static int exfat_search_empty_slot(struct super_block *sb, * Otherwise, and if "dentry + hint_famp->count" is also equal * to "p_dir->size * dentries_per_clu", it means ENOSPC. */ - if (dentry + hint_femp->count == p_dir->size * dentries_per_clu && + if (dentry + hint_femp->count == total_entries && num_entries > hint_femp->count) return -ENOSPC; @@ -242,69 +237,41 @@ static int exfat_search_empty_slot(struct super_block *sb, dentry = 0; } - while (clu.dir != EXFAT_EOF_CLUSTER) { + while (dentry + num_entries < total_entries && + clu.dir != EXFAT_EOF_CLUSTER) { i = dentry & (dentries_per_clu - 1); - for (; i < dentries_per_clu; i++, dentry++) { - ep = exfat_get_dentry(sb, &clu, i, &bh); - if (!ep) - return -EIO; - type = exfat_get_entry_type(ep); - brelse(bh); - - if (type == TYPE_UNUSED || type == TYPE_DELETED) { - num_empty++; - if (hint_femp->eidx == EXFAT_HINT_NONE) { - hint_femp->eidx = dentry; - hint_femp->count = CNT_UNUSED_NOHIT; - exfat_chain_set(&hint_femp->cur, - clu.dir, clu.size, clu.flags); - } - - if (type == TYPE_UNUSED && - hint_femp->count != CNT_UNUSED_HIT) - hint_femp->count = CNT_UNUSED_HIT; + ret = exfat_get_empty_dentry_set(es, sb, &clu, i, num_entries); + if (ret < 0) + return ret; + else if (ret == 0) + return dentry; + + dentry += ret; + i += ret; + + while (i >= dentries_per_clu) { + if (clu.flags == ALLOC_NO_FAT_CHAIN) { + if (--clu.size > 0) + clu.dir++; + else + clu.dir = EXFAT_EOF_CLUSTER; } else { - if (hint_femp->eidx != EXFAT_HINT_NONE && - hint_femp->count == CNT_UNUSED_HIT) { - /* unused empty group means - * an empty group which includes - * unused dentry - */ - exfat_fs_error(sb, - "found bogus dentry(%d) beyond unused empty group(%d) (start_clu : %u, cur_clu : %u)", - dentry, hint_femp->eidx, - p_dir->dir, clu.dir); + if (exfat_get_next_cluster(sb, &clu.dir)) return -EIO; - } - - num_empty = 0; - hint_femp->eidx = EXFAT_HINT_NONE; } - if (num_empty >= num_entries) { - /* found and invalidate hint_femp */ - hint_femp->eidx = EXFAT_HINT_NONE; - return (dentry - (num_entries - 1)); - } - } - - if (clu.flags == ALLOC_NO_FAT_CHAIN) { - if (--clu.size > 0) - clu.dir++; - else - clu.dir = EXFAT_EOF_CLUSTER; - } else { - if (exfat_get_next_cluster(sb, &clu.dir)) - return -EIO; + i -= dentries_per_clu; } } - hint_femp->eidx = p_dir->size * dentries_per_clu - num_empty; - hint_femp->count = num_empty; - if (num_empty == 0) + hint_femp->eidx = dentry; + hint_femp->count = 0; + if (dentry == total_entries || clu.dir == EXFAT_EOF_CLUSTER) exfat_chain_set(&hint_femp->cur, EXFAT_EOF_CLUSTER, 0, clu.flags); + else + hint_femp->cur = clu; return -ENOSPC; } @@ -324,8 +291,9 @@ static int exfat_check_max_dentries(struct inode *inode) /* find empty directory entry. * if there isn't any empty slot, expand cluster chain. */ -static int exfat_find_empty_entry(struct inode *inode, - struct exfat_chain *p_dir, int num_entries) +static int __exfat_find_empty_entry(struct inode *inode, + struct exfat_chain *p_dir, int num_entries, + struct exfat_entry_set_cache *es) { int dentry; unsigned int ret, last_clu; @@ -344,7 +312,7 @@ static int exfat_find_empty_entry(struct inode *inode, } while ((dentry = exfat_search_empty_slot(sb, &hint_femp, p_dir, - num_entries)) < 0) { + num_entries, es)) < 0) { if (dentry == -EIO) break; @@ -414,6 +382,21 @@ static int exfat_find_empty_entry(struct inode *inode, return dentry; } +static int exfat_find_empty_entry(struct inode *inode, + struct exfat_chain *p_dir, int num_entries) +{ + int entry; + struct exfat_entry_set_cache es; + + entry = __exfat_find_empty_entry(inode, p_dir, num_entries, &es); + if (entry < 0) + return entry; + + exfat_put_dentry_set(&es, false); + + return entry; +} + /* * Name Resolution Functions : * Zero if it was successful; otherwise nonzero. From patchwork Fri Dec 8 11:23:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuezhang Mo X-Patchwork-Id: 13485320 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=foxmail.com header.i=@foxmail.com header.b="whoMz1rb" Received: from out203-205-221-155.mail.qq.com (out203-205-221-155.mail.qq.com [203.205.221.155]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B2DB10F8 for ; Fri, 8 Dec 2023 03:27:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1702034869; bh=iHqxm6/z8eZr9tI87TDYsEEgs6+ViMDs61QFgckO3tk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=whoMz1rbflCPAEbFUH5YwlXHGzgzBj2xy+sUO1ebZILGyAWhS86hETzn3wVokqMCN /ny6FOPC+GhkEXX8cFS0IwcpfCMuoiC135KBLy/actzDdQvUk8uFsyoF8yVG2sdesK zdOFy1WEMgCEszhNY8Psb54rhQdp0JW0g9dPqu3c= Received: from localhost.localdomain ([180.164.182.58]) by newxmesmtplogicsvrszc5-0.qq.com (NewEsmtp) with SMTP id 530B9A94; Fri, 08 Dec 2023 19:20:48 +0800 X-QQ-mid: xmsmtpt1702034492tk11qvic2 Message-ID: X-QQ-XMAILINFO: NJ/+omVLhVgaUsRybtwRP+OXwlr1Nf8n9XgwU4fjsBubRxuKAnX//en4D40LJ6 lNKWSMKXa3P8L6F1sK2uNy/CgPw/P3uTyIeK9GgwkCCFHs+aHf5zt6NApm42eu83IPhyBMCkF0fu tZGFuELY4IWI19iIjRK57c2emPevTc65XidG4Xkp/J3TTP+SbYXm1cI3VUtB1joCz82IwncgUjIj Oup5RuTKJc3kU3M0i83pjz+rnPi0cuq7rxVoRX2GymGnqgAqKuQLkLK9pxPCe98sQB+LoRe5PP0Y UpLv2fzUT7QnYmd/sYOJjNQSm1LbdG1sNYz9aZe4+Y+BLwLQWqRTcC1Z+ZLveVNg0I4kqxSFBkrT soVHxF312gu3/OFP3ZD/VtXAyF74V7C/aV8TYalqZru66scRoz2sfOV6j+2ks/AwU96ngwRkzYKX qXfpBMALUl8ml32kTV8QkAeIKjMqlIJyGvBKmV+z8ogqc/UXiFIjp+aax6t10nHxNN9c1JADFQ+E S71aDsAxY+oG5PCpojTw34jX6ACD3a+wtnuUxwqi2VPR47F/GmIfNV6956ThBAGvCDDRGAVEISSk 8669WRRkOt20T5t1/GNyPySPfX8DV5LfzZQi1tXGeo0yLm8ZbEmw43Sq3YAi6hZmFM/fukgyAOzU 1kD7CALtl+nozhTEWCI3IdG7MfyXMGjd/Q0BN8ri+eXEPgVsGo4mTas1vA27H+kOFe3SubpCIAcL oGRcshaIxo+S7O2wPUVOIAv+U8AZtdIT8RXFYaP2r1BeOsy256iELcvxsBHemMdrz5kFoRZkD1nJ OalG4jQMOSP3WsKvz36q5JA0qv/9I/LyftwTVTn9cuiYXIYJuIZlayLkyivVbKaAJgvf0goeekRz Gqpj1IIjGYhbTmX2SEXHQ89HeltdyYT36HhYHeGz0m6yrgJml4SYFPqJGjN46h5Rzv92dVIsZYr8 wtWHCJn3DoNmR8b+HR2a2jLYg4Lu0lACaiefTkM65jtbrqlLtSn+qcy5Zm8591 X-QQ-XMRINFO: NS+P29fieYNw95Bth2bWPxk= From: yuezhang.mo@foxmail.com To: linkinjeon@kernel.org, sj1557.seo@samsung.com Cc: linux-fsdevel@vger.kernel.org, Andy.Wu@sony.com, wataru.aoyama@sony.com, Yuezhang Mo Subject: [PATCH v1 04/11] exfat: covert exfat_add_entry() to use dentry cache Date: Fri, 8 Dec 2023 19:23:13 +0800 X-OQ-MSGID: <20231208112318.1135649-5-yuezhang.mo@foxmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231208112318.1135649-1-yuezhang.mo@foxmail.com> References: <20231208112318.1135649-1-yuezhang.mo@foxmail.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Yuezhang Mo After this conversion, if "dirsync" or "sync" is enabled, the number of synchronized dentries in exfat_add_entry() will change from 2 to 1. Signed-off-by: Yuezhang Mo Reviewed-by: Andy Wu Reviewed-by: Aoyama Wataru --- fs/exfat/dir.c | 37 +++++++++---------------------------- fs/exfat/exfat_fs.h | 6 +++--- fs/exfat/namei.c | 12 ++++++++++-- 3 files changed, 22 insertions(+), 33 deletions(-) diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index bb23585c6e7c..a7eda14a57ac 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -448,53 +448,34 @@ static void exfat_init_name_entry(struct exfat_dentry *ep, } } -int exfat_init_dir_entry(struct inode *inode, struct exfat_chain *p_dir, - int entry, unsigned int type, unsigned int start_clu, - unsigned long long size) +void exfat_init_dir_entry(struct exfat_entry_set_cache *es, + unsigned int type, unsigned int start_clu, + unsigned long long size, struct timespec64 *ts) { - struct super_block *sb = inode->i_sb; + struct super_block *sb = es->sb; struct exfat_sb_info *sbi = EXFAT_SB(sb); - struct timespec64 ts = current_time(inode); struct exfat_dentry *ep; - struct buffer_head *bh; - - /* - * We cannot use exfat_get_dentry_set here because file ep is not - * initialized yet. - */ - ep = exfat_get_dentry(sb, p_dir, entry, &bh); - if (!ep) - return -EIO; + ep = exfat_get_dentry_cached(es, ES_IDX_FILE); exfat_set_entry_type(ep, type); - exfat_set_entry_time(sbi, &ts, + exfat_set_entry_time(sbi, ts, &ep->dentry.file.create_tz, &ep->dentry.file.create_time, &ep->dentry.file.create_date, &ep->dentry.file.create_time_cs); - exfat_set_entry_time(sbi, &ts, + exfat_set_entry_time(sbi, ts, &ep->dentry.file.modify_tz, &ep->dentry.file.modify_time, &ep->dentry.file.modify_date, &ep->dentry.file.modify_time_cs); - exfat_set_entry_time(sbi, &ts, + exfat_set_entry_time(sbi, ts, &ep->dentry.file.access_tz, &ep->dentry.file.access_time, &ep->dentry.file.access_date, NULL); - exfat_update_bh(bh, IS_DIRSYNC(inode)); - brelse(bh); - - ep = exfat_get_dentry(sb, p_dir, entry + 1, &bh); - if (!ep) - return -EIO; - + ep = exfat_get_dentry_cached(es, ES_IDX_STREAM); exfat_init_stream_entry(ep, start_clu, size); - exfat_update_bh(bh, IS_DIRSYNC(inode)); - brelse(bh); - - return 0; } int exfat_update_dir_chksum(struct inode *inode, struct exfat_chain *p_dir, diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h index 6dc76b3f4945..0897584d1473 100644 --- a/fs/exfat/exfat_fs.h +++ b/fs/exfat/exfat_fs.h @@ -480,9 +480,9 @@ int exfat_get_cluster(struct inode *inode, unsigned int cluster, extern const struct inode_operations exfat_dir_inode_operations; extern const struct file_operations exfat_dir_operations; unsigned int exfat_get_entry_type(struct exfat_dentry *p_entry); -int exfat_init_dir_entry(struct inode *inode, struct exfat_chain *p_dir, - int entry, unsigned int type, unsigned int start_clu, - unsigned long long size); +void exfat_init_dir_entry(struct exfat_entry_set_cache *es, + unsigned int type, unsigned int start_clu, + unsigned long long size, struct timespec64 *ts); int exfat_init_ext_entry(struct inode *inode, struct exfat_chain *p_dir, int entry, int num_entries, struct exfat_uni_name *p_uniname); int exfat_remove_entries(struct inode *inode, struct exfat_chain *p_dir, diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c index 1f662296f2fa..423cd6d505ab 100644 --- a/fs/exfat/namei.c +++ b/fs/exfat/namei.c @@ -482,6 +482,8 @@ static int exfat_add_entry(struct inode *inode, const char *path, struct exfat_sb_info *sbi = EXFAT_SB(sb); struct exfat_uni_name uniname; struct exfat_chain clu; + struct timespec64 ts = current_time(inode); + struct exfat_entry_set_cache es; int clu_size = 0; unsigned int start_clu = EXFAT_FREE_CLUSTER; @@ -514,8 +516,14 @@ static int exfat_add_entry(struct inode *inode, const char *path, /* fill the dos name directory entry information of the created file. * the first cluster is not determined yet. (0) */ - ret = exfat_init_dir_entry(inode, p_dir, dentry, type, - start_clu, clu_size); + + ret = exfat_get_empty_dentry_set(&es, sb, p_dir, dentry, num_entries); + if (ret) + goto out; + + exfat_init_dir_entry(&es, type, start_clu, clu_size, &ts); + + ret = exfat_put_dentry_set(&es, IS_DIRSYNC(inode)); if (ret) goto out; From patchwork Fri Dec 8 11:23:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuezhang Mo X-Patchwork-Id: 13485324 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=foxmail.com header.i=@foxmail.com header.b="yDem2e7h" Received: from out162-62-57-252.mail.qq.com (out162-62-57-252.mail.qq.com [162.62.57.252]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADF1A171F for ; Fri, 8 Dec 2023 03:30:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1702035001; bh=+/pN+pgmxf4tGRuEeHxpF9JmqCk/0LPE9fuycvif25I=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=yDem2e7hVO5E5R83H3cRaY42FPE5oo6axyHFPGLFwWfeDfQkZo5IFY5oWqLEJa8+z PXqJTfHnAlI+vCLhAg5yYloV71II7f9m8RsBsKDPO1o8beexQyFtLrVbUPa3IccONt bxmtqfIxdfjYOFiYSss/MNSvRkY6B5CysHLQcaJ0= Received: from localhost.localdomain ([180.164.182.58]) by newxmesmtplogicsvrszc5-0.qq.com (NewEsmtp) with SMTP id 530B9A94; Fri, 08 Dec 2023 19:20:48 +0800 X-QQ-mid: xmsmtpt1702034495tjj64rn0g Message-ID: X-QQ-XMAILINFO: NnA3IMNPwBd+ji1cITXbS2GOU1gnuGjHkwF3/LYL+DNhgfwKY74vj7Wmt3PUqM LHFhosfchvve5FjFvmfIJqAV9tZzr0NsSlFphvX6eHuHYy0t4yNQMmA4TurIyYExBIV5APN5xkYs 0nUKpfIHB485Syq1VgHYYCF3X6GlxmBkLYTLo9twLs6tPzlue/IQyDeNzp9errU3B5dsmNfmFyPo rZH3You5JtkGFJbTWj2VxcWRlP0mGfApZ1B3etL7Fqdz05vpiUIS07MSHRxpSmsObd1gzFRVrOsd vD8y8q2nbrpeyBoIpRyDpyMVuVlw5YLGk4lv2NZHGJ3H2rYE7KXjxfx/GWypFgr2xPQJuuLIa1Ah UquUYsxYvNaUg6DCOPtPmmk9QQ53Jw2OSLdaBg2sbkyqCLyMEaJlAEgJX6OfBOZ5m9Kr9sIvJE0v 0BNFwxdeuqMsSsY6GiVC6xXe+ZJummAvagcdj956T1L77Wr+BwqlzKaZ0Nr21HrhczM9S9u21sL1 vK2HpAHOLWSgFsY6cBzEZhluOQdLe+2A4ZGXCmIBJc0hZufE5fv38kF1ULzAn6vlUjfsHXftmsuO c4XTsoiBc8MUH0U/FIzs/lb8WkwB9nE2qY7n78RnUGIeWH4LjMoa+lW8RJLWvZwcG7uDmQPeGdqA 48qQpTCOAcckPBssIAi1vG5mnjfx2tWvr6nmDuRf3eb7KirVoDC3qkjUY76CVKKsHSyvJ8Z5pTFA utoTGV+XxCJu5teSMnKpNU3XkmOtkYBauEyseZGI/GouldMhawwfrGVXXmh7gpyhhSM08YZjc92Q dD3hIOGxBSpgAQhreJfMgO7KLMaNnP/j3dcsQFB8U0IJoSm9Rx5qF7HKNJLl3AR2p+BKNa1Qptkn TfK7JQ61w/KADTieITZdp1Jq458/QyBVrDGAx5MG20IQlH2oGHXr8+PKEH3FwOgM9ulJRZltO28R 6Y8mRjdXyikwSkVnrtwEbY6cUpsPC5hnGHwW+9pHksq52nIS/c/3v7PrIq1jiKqPlASkMNbDGk8P 8Q3dAlAw== X-QQ-XMRINFO: OD9hHCdaPRBwq3WW+NvGbIU= From: yuezhang.mo@foxmail.com To: linkinjeon@kernel.org, sj1557.seo@samsung.com Cc: linux-fsdevel@vger.kernel.org, Andy.Wu@sony.com, wataru.aoyama@sony.com, Yuezhang Mo Subject: [PATCH v1 05/11] exfat: covert exfat_remove_entries() to use dentry cache Date: Fri, 8 Dec 2023 19:23:14 +0800 X-OQ-MSGID: <20231208112318.1135649-6-yuezhang.mo@foxmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231208112318.1135649-1-yuezhang.mo@foxmail.com> References: <20231208112318.1135649-1-yuezhang.mo@foxmail.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Yuezhang Mo Before this conversion, in exfat_remove_entries(), to mark the dentries in a dentry set as deleted, the sync times is equals the dentry numbers if 'dirsync' or 'sync' is enabled. That affects not only performance but also device life. After this conversion, only needs to be synchronized once if 'dirsync' or 'sync' is enabled. Signed-off-by: Yuezhang Mo Reviewed-by: Andy Wu Reviewed-by: Aoyama Wataru --- fs/exfat/dir.c | 17 ++-- fs/exfat/exfat_fs.h | 4 +- fs/exfat/namei.c | 184 ++++++++++++++++++++------------------------ 3 files changed, 90 insertions(+), 115 deletions(-) diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index a7eda14a57ac..2a002b01f1dc 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -577,28 +577,23 @@ int exfat_init_ext_entry(struct inode *inode, struct exfat_chain *p_dir, return 0; } -int exfat_remove_entries(struct inode *inode, struct exfat_chain *p_dir, - int entry, int order, int num_entries) +void exfat_remove_entries(struct inode *inode, struct exfat_entry_set_cache *es, + int order) { - struct super_block *sb = inode->i_sb; int i; struct exfat_dentry *ep; - struct buffer_head *bh; - for (i = order; i < num_entries; i++) { - ep = exfat_get_dentry(sb, p_dir, entry + i, &bh); - if (!ep) - return -EIO; + for (i = order; i < es->num_entries; i++) { + ep = exfat_get_dentry_cached(es, i); if (exfat_get_entry_type(ep) & TYPE_BENIGN_SEC) exfat_free_benign_secondary_clusters(inode, ep); exfat_set_entry_type(ep, TYPE_DELETED); - exfat_update_bh(bh, IS_DIRSYNC(inode)); - brelse(bh); } - return 0; + if (order < es->num_entries) + es->modified = true; } void exfat_update_dir_chksum_with_entry_set(struct exfat_entry_set_cache *es) diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h index 0897584d1473..46031e77f58b 100644 --- a/fs/exfat/exfat_fs.h +++ b/fs/exfat/exfat_fs.h @@ -485,8 +485,8 @@ void exfat_init_dir_entry(struct exfat_entry_set_cache *es, unsigned long long size, struct timespec64 *ts); int exfat_init_ext_entry(struct inode *inode, struct exfat_chain *p_dir, int entry, int num_entries, struct exfat_uni_name *p_uniname); -int exfat_remove_entries(struct inode *inode, struct exfat_chain *p_dir, - int entry, int order, int num_entries); +void exfat_remove_entries(struct inode *inode, struct exfat_entry_set_cache *es, + int order); int exfat_update_dir_chksum(struct inode *inode, struct exfat_chain *p_dir, int entry); void exfat_update_dir_chksum_with_entry_set(struct exfat_entry_set_cache *es); diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c index 423cd6d505ab..6a85b6707a7e 100644 --- a/fs/exfat/namei.c +++ b/fs/exfat/namei.c @@ -786,12 +786,11 @@ static struct dentry *exfat_lookup(struct inode *dir, struct dentry *dentry, static int exfat_unlink(struct inode *dir, struct dentry *dentry) { struct exfat_chain cdir; - struct exfat_dentry *ep; struct super_block *sb = dir->i_sb; struct inode *inode = dentry->d_inode; struct exfat_inode_info *ei = EXFAT_I(inode); - struct buffer_head *bh; - int num_entries, entry, err = 0; + struct exfat_entry_set_cache es; + int entry, err = 0; mutex_lock(&EXFAT_SB(sb)->s_lock); exfat_chain_dup(&cdir, &ei->dir); @@ -802,26 +801,20 @@ static int exfat_unlink(struct inode *dir, struct dentry *dentry) goto unlock; } - ep = exfat_get_dentry(sb, &cdir, entry, &bh); - if (!ep) { - err = -EIO; - goto unlock; - } - num_entries = exfat_count_ext_entries(sb, &cdir, entry, ep); - if (num_entries < 0) { + err = exfat_get_dentry_set(&es, sb, &cdir, entry, ES_ALL_ENTRIES); + if (err) { err = -EIO; - brelse(bh); goto unlock; } - num_entries++; - brelse(bh); exfat_set_volume_dirty(sb); + /* update the directory entry */ - if (exfat_remove_entries(dir, &cdir, entry, 0, num_entries)) { - err = -EIO; + exfat_remove_entries(inode, &es, ES_IDX_FILE); + + err = exfat_put_dentry_set(&es, IS_DIRSYNC(inode)); + if (err) goto unlock; - } /* This doesn't modify ei */ ei->dir.dir = DIR_DELETED; @@ -937,13 +930,12 @@ static int exfat_check_dir_empty(struct super_block *sb, static int exfat_rmdir(struct inode *dir, struct dentry *dentry) { struct inode *inode = dentry->d_inode; - struct exfat_dentry *ep; struct exfat_chain cdir, clu_to_free; struct super_block *sb = inode->i_sb; struct exfat_sb_info *sbi = EXFAT_SB(sb); struct exfat_inode_info *ei = EXFAT_I(inode); - struct buffer_head *bh; - int num_entries, entry, err; + struct exfat_entry_set_cache es; + int entry, err; mutex_lock(&EXFAT_SB(inode->i_sb)->s_lock); @@ -967,27 +959,20 @@ static int exfat_rmdir(struct inode *dir, struct dentry *dentry) goto unlock; } - ep = exfat_get_dentry(sb, &cdir, entry, &bh); - if (!ep) { - err = -EIO; - goto unlock; - } - - num_entries = exfat_count_ext_entries(sb, &cdir, entry, ep); - if (num_entries < 0) { + err = exfat_get_dentry_set(&es, sb, &cdir, entry, ES_ALL_ENTRIES); + if (err) { err = -EIO; - brelse(bh); goto unlock; } - num_entries++; - brelse(bh); exfat_set_volume_dirty(sb); - err = exfat_remove_entries(dir, &cdir, entry, 0, num_entries); - if (err) { - exfat_err(sb, "failed to exfat_remove_entries : err(%d)", err); + + exfat_remove_entries(inode, &es, ES_IDX_FILE); + + err = exfat_put_dentry_set(&es, IS_DIRSYNC(dir)); + if (err) goto unlock; - } + ei->dir.dir = DIR_DELETED; inode_inc_iversion(dir); @@ -1013,36 +998,40 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir, int oldentry, struct exfat_uni_name *p_uniname, struct exfat_inode_info *ei) { - int ret, num_old_entries, num_new_entries; + int ret, num_new_entries; struct exfat_dentry *epold, *epnew; struct super_block *sb = inode->i_sb; - struct buffer_head *new_bh, *old_bh; + struct buffer_head *new_bh; + struct exfat_entry_set_cache old_es; int sync = IS_DIRSYNC(inode); - epold = exfat_get_dentry(sb, p_dir, oldentry, &old_bh); - if (!epold) - return -EIO; - - num_old_entries = exfat_count_ext_entries(sb, p_dir, oldentry, epold); - if (num_old_entries < 0) - return -EIO; - num_old_entries++; - num_new_entries = exfat_calc_num_entries(p_uniname); if (num_new_entries < 0) return num_new_entries; - if (num_old_entries < num_new_entries) { + ret = exfat_get_dentry_set(&old_es, sb, p_dir, oldentry, ES_ALL_ENTRIES); + if (ret) { + ret = -EIO; + return ret; + } + + epold = exfat_get_dentry_cached(&old_es, ES_IDX_FILE); + + if (old_es.num_entries < num_new_entries) { int newentry; newentry = exfat_find_empty_entry(inode, p_dir, num_new_entries); - if (newentry < 0) - return newentry; /* -EIO or -ENOSPC */ + if (newentry < 0) { + ret = newentry; /* -EIO or -ENOSPC */ + goto put_old_es; + } epnew = exfat_get_dentry(sb, p_dir, newentry, &new_bh); - if (!epnew) - return -EIO; + if (!epnew) { + ret = -EIO; + goto put_old_es; + } *epnew = *epold; if (exfat_get_entry_type(epnew) == TYPE_FILE) { @@ -1050,30 +1039,25 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir, ei->attr |= EXFAT_ATTR_ARCHIVE; } exfat_update_bh(new_bh, sync); - brelse(old_bh); brelse(new_bh); - epold = exfat_get_dentry(sb, p_dir, oldentry + 1, &old_bh); - if (!epold) - return -EIO; + epold = exfat_get_dentry_cached(&old_es, ES_IDX_STREAM); epnew = exfat_get_dentry(sb, p_dir, newentry + 1, &new_bh); if (!epnew) { - brelse(old_bh); - return -EIO; + ret = -EIO; + goto put_old_es; } *epnew = *epold; exfat_update_bh(new_bh, sync); - brelse(old_bh); brelse(new_bh); ret = exfat_init_ext_entry(inode, p_dir, newentry, num_new_entries, p_uniname); if (ret) - return ret; + goto put_old_es; - exfat_remove_entries(inode, p_dir, oldentry, 0, - num_old_entries); + exfat_remove_entries(inode, &old_es, ES_IDX_FILE); ei->dir = *p_dir; ei->entry = newentry; } else { @@ -1081,37 +1065,29 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir, epold->dentry.file.attr |= cpu_to_le16(EXFAT_ATTR_ARCHIVE); ei->attr |= EXFAT_ATTR_ARCHIVE; } - exfat_update_bh(old_bh, sync); - brelse(old_bh); ret = exfat_init_ext_entry(inode, p_dir, oldentry, num_new_entries, p_uniname); if (ret) - return ret; + goto put_old_es; - exfat_remove_entries(inode, p_dir, oldentry, num_new_entries, - num_old_entries); + exfat_remove_entries(inode, &old_es, num_new_entries); } - return 0; + return exfat_put_dentry_set(&old_es, sync); + +put_old_es: + exfat_put_dentry_set(&old_es, false); + return ret; } static int exfat_move_file(struct inode *inode, struct exfat_chain *p_olddir, int oldentry, struct exfat_chain *p_newdir, struct exfat_uni_name *p_uniname, struct exfat_inode_info *ei) { - int ret, newentry, num_new_entries, num_old_entries; + int ret, newentry, num_new_entries; struct exfat_dentry *epmov, *epnew; struct super_block *sb = inode->i_sb; - struct buffer_head *mov_bh, *new_bh; - - epmov = exfat_get_dentry(sb, p_olddir, oldentry, &mov_bh); - if (!epmov) - return -EIO; - - num_old_entries = exfat_count_ext_entries(sb, p_olddir, oldentry, - epmov); - if (num_old_entries < 0) - return -EIO; - num_old_entries++; + struct buffer_head *new_bh; + struct exfat_entry_set_cache mov_es; num_new_entries = exfat_calc_num_entries(p_uniname); if (num_new_entries < 0) @@ -1121,31 +1097,35 @@ static int exfat_move_file(struct inode *inode, struct exfat_chain *p_olddir, if (newentry < 0) return newentry; /* -EIO or -ENOSPC */ - epnew = exfat_get_dentry(sb, p_newdir, newentry, &new_bh); - if (!epnew) + ret = exfat_get_dentry_set(&mov_es, sb, p_olddir, oldentry, + ES_ALL_ENTRIES); + if (ret) return -EIO; + epmov = exfat_get_dentry_cached(&mov_es, ES_IDX_FILE); + epnew = exfat_get_dentry(sb, p_newdir, newentry, &new_bh); + if (!epnew) { + ret = -EIO; + goto put_mov_es; + } + *epnew = *epmov; if (exfat_get_entry_type(epnew) == TYPE_FILE) { epnew->dentry.file.attr |= cpu_to_le16(EXFAT_ATTR_ARCHIVE); ei->attr |= EXFAT_ATTR_ARCHIVE; } exfat_update_bh(new_bh, IS_DIRSYNC(inode)); - brelse(mov_bh); brelse(new_bh); - epmov = exfat_get_dentry(sb, p_olddir, oldentry + 1, &mov_bh); - if (!epmov) - return -EIO; + epmov = exfat_get_dentry_cached(&mov_es, ES_IDX_STREAM); epnew = exfat_get_dentry(sb, p_newdir, newentry + 1, &new_bh); if (!epnew) { - brelse(mov_bh); - return -EIO; + ret = -EIO; + goto put_mov_es; } *epnew = *epmov; exfat_update_bh(new_bh, IS_DIRSYNC(inode)); - brelse(mov_bh); brelse(new_bh); ret = exfat_init_ext_entry(inode, p_newdir, newentry, num_new_entries, @@ -1153,13 +1133,18 @@ static int exfat_move_file(struct inode *inode, struct exfat_chain *p_olddir, if (ret) return ret; - exfat_remove_entries(inode, p_olddir, oldentry, 0, num_old_entries); + exfat_remove_entries(inode, &mov_es, ES_IDX_FILE); exfat_chain_set(&ei->dir, p_newdir->dir, p_newdir->size, p_newdir->flags); ei->entry = newentry; - return 0; + return exfat_put_dentry_set(&mov_es, IS_DIRSYNC(inode)); + +put_mov_es: + exfat_put_dentry_set(&mov_es, false); + + return ret; } /* rename or move a old file into a new file */ @@ -1177,7 +1162,6 @@ static int __exfat_rename(struct inode *old_parent_inode, struct exfat_sb_info *sbi = EXFAT_SB(sb); const unsigned char *new_path = new_dentry->d_name.name; struct inode *new_inode = new_dentry->d_inode; - int num_entries; struct exfat_inode_info *new_ei = NULL; unsigned int new_entry_type = TYPE_UNUSED; int new_entry = 0; @@ -1248,25 +1232,21 @@ static int __exfat_rename(struct inode *old_parent_inode, &newdir, &uni_name, ei); if (!ret && new_inode) { + struct exfat_entry_set_cache es; + /* delete entries of new_dir */ - ep = exfat_get_dentry(sb, p_dir, new_entry, &new_bh); - if (!ep) { + ret = exfat_get_dentry_set(&es, sb, p_dir, new_entry, + ES_ALL_ENTRIES); + if (ret) { ret = -EIO; goto del_out; } - num_entries = exfat_count_ext_entries(sb, p_dir, new_entry, ep); - if (num_entries < 0) { - ret = -EIO; - goto del_out; - } - brelse(new_bh); + exfat_remove_entries(new_inode, &es, ES_IDX_FILE); - if (exfat_remove_entries(new_inode, p_dir, new_entry, 0, - num_entries + 1)) { - ret = -EIO; + ret = exfat_put_dentry_set(&es, IS_DIRSYNC(new_inode)); + if (ret) goto del_out; - } /* Free the clusters if new_inode is a dir(as if exfat_rmdir) */ if (new_entry_type == TYPE_DIR && From patchwork Fri Dec 8 11:23:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuezhang Mo X-Patchwork-Id: 13485321 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=foxmail.com header.i=@foxmail.com header.b="fA3uF2D9" Received: from out203-205-221-205.mail.qq.com (out203-205-221-205.mail.qq.com [203.205.221.205]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B5D7171F for ; Fri, 8 Dec 2023 03:27:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1702034869; bh=nUoXBiMK9GjTeJ57U1BCOL/XGHy02XwaHGE2p0xi2K0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=fA3uF2D9D2RfCPyAcfM+TW1mq/iGRjca4TUGIZBETcNSa6g/MvI4M/PociiIEZaXO UK3mvI/QZ6pK0Qcwngom6uqHDSu3B1RBd7nb+aMI0/A5tkNYCZ8WZzPDWKfsBQ1A+6 tbwSMwq69FZHxiREPDnbOd7azalpa3BgkNk8OH1c= Received: from localhost.localdomain ([180.164.182.58]) by newxmesmtplogicsvrszc5-0.qq.com (NewEsmtp) with SMTP id 530B9A94; Fri, 08 Dec 2023 19:20:48 +0800 X-QQ-mid: xmsmtpt1702034497tl7orebkx Message-ID: X-QQ-XMAILINFO: NQR8mRxMnur9lBseoUVoM6+7sWh/JjCRu9axUiEM516VajAtc0l5bwBWWVDAwK pOwNTPz7cYHMBJplVc7myNRMYlmNh4bL1el6+RzMcIk2A1u6Ts7CB7680DQnYts2ktoa0Lau1nOj Wg41JibmCxoOg8FxpXkkQv3p9Xb6HjzLcUlhoh/WN6Hd7dXYOmrxZ9ewzmmcuOdYRaLuoO3yL9aH knSnbfbI1VWmAkGqFKFlF5+rvfL6SbsenlVkvccxCJJknFOwJ5+ndJgvfqzAjOpGmGGVh8lYO1st /mV9x2tPcNocpJvkB8jat33ylEEGaLkf7y2TATo+dj3Ub+T8F9tiSdBON68wxjjFsJujQG9hgNnC nTO0Fw36JouHspAQXeCgBaYx+FD0rbw00EsDMCS9qm2LCVftzwdZlAXZQUSKy2aChUPDpdBP3EiL q82CDhpDZ22S4jZSYXhXVqStKCWQLj1ocJjvTj1SI/TrNdICcPfCRrA1M9OIr8utWnwlpfns2OLC OVVhOJdT4ZMdQZPQxr2cM9og1h1Wv8vGiQY+McVuAJatAG7zS40v6P6F2eGcbfsvncklXeRAa2pd G+l4dCV+uKwbQgQqWoD5XK22AZS0wpXxg7+tct4hrpGfudhBn4yCOzMMMnDZXgNOAsQ4BBDvQWVa sDArSFxxmwkOfv1/Q7yw1UlLD2wNCnJ/bpAXmCdrG7i9Y9a5dS44lm9aW1uhRNgez3FdW4zaNd8z 4rKI0iXNXuO+j0H9x3gfCexC33hRQYUKAxnLl0vZpK3vmffp+ugOObK5DWO6BHavN5cKaPXQs+my qDystvnvge3E4ec0vLIv8wEoskHbKxW4fejBfp8HPNmvj6aIL47DAJNwSjEFvVB1tTnWsWs+T5Ci O0hBRtNvQHlLMzr4xd2l2obk/L3M5zdObS5n7+7tQKdQ37LHRRyqC6MBYH3M8Uq2NvTRqBneHxnI 4Xe6JjTmFIM+lNvNf6jYC/WtgjQ/q5 X-QQ-XMRINFO: Mp0Kj//9VHAxr69bL5MkOOs= From: yuezhang.mo@foxmail.com To: linkinjeon@kernel.org, sj1557.seo@samsung.com Cc: linux-fsdevel@vger.kernel.org, Andy.Wu@sony.com, wataru.aoyama@sony.com, Yuezhang Mo Subject: [PATCH v1 06/11] exfat: move free cluster out of exfat_init_ext_entry() Date: Fri, 8 Dec 2023 19:23:15 +0800 X-OQ-MSGID: <20231208112318.1135649-7-yuezhang.mo@foxmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231208112318.1135649-1-yuezhang.mo@foxmail.com> References: <20231208112318.1135649-1-yuezhang.mo@foxmail.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Yuezhang Mo exfat_init_ext_entry() is an init function, it's a bit strange to free cluster in it. And the argument 'inode' will be removed from exfat_init_ext_entry(). So this commit changes to free the cluster in exfat_remove_entries(). Code refinement, no functional changes. Signed-off-by: Yuezhang Mo Reviewed-by: Andy Wu Reviewed-by: Aoyama Wataru --- fs/exfat/dir.c | 3 --- fs/exfat/namei.c | 5 +++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index 2a002b01f1dc..8965bb2c99ae 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -564,9 +564,6 @@ int exfat_init_ext_entry(struct inode *inode, struct exfat_chain *p_dir, if (!ep) return -EIO; - if (exfat_get_entry_type(ep) & TYPE_BENIGN_SEC) - exfat_free_benign_secondary_clusters(inode, ep); - exfat_init_name_entry(ep, uniname); exfat_update_bh(bh, sync); brelse(bh); diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c index 6a85b6707a7e..9a0d8f2deea6 100644 --- a/fs/exfat/namei.c +++ b/fs/exfat/namei.c @@ -1065,12 +1065,13 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir, epold->dentry.file.attr |= cpu_to_le16(EXFAT_ATTR_ARCHIVE); ei->attr |= EXFAT_ATTR_ARCHIVE; } + + exfat_remove_entries(inode, &old_es, ES_IDX_FIRST_FILENAME + 1); + ret = exfat_init_ext_entry(inode, p_dir, oldentry, num_new_entries, p_uniname); if (ret) goto put_old_es; - - exfat_remove_entries(inode, &old_es, num_new_entries); } return exfat_put_dentry_set(&old_es, sync); From patchwork Fri Dec 8 11:23:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuezhang Mo X-Patchwork-Id: 13485312 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=foxmail.com header.i=@foxmail.com header.b="Ww3Z6KM+" Received: from out162-62-58-211.mail.qq.com (out162-62-58-211.mail.qq.com [162.62.58.211]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 349C310CA for ; Fri, 8 Dec 2023 03:21:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1702034501; bh=+QeCqnUl3Zvl3kLwf+D8OZ4mle50KHBxwSgY62XS3SI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Ww3Z6KM+SsWFBYP1LwGDyNDt2p8bI68l3DGgGAcaytspA2A8pycdVRnyN3GQv6Iii PR1ZTlN1EeH1aryEQbMiVO9zmmlYoeRP3QrlDWfh1wcVd7IW51naHT5R6lyUk0Claq FrIkkgW/V+vMsR0ILwZB2AAsOftBzgipk5NwVsV8= Received: from localhost.localdomain ([180.164.182.58]) by newxmesmtplogicsvrszc5-0.qq.com (NewEsmtp) with SMTP id 530B9A94; Fri, 08 Dec 2023 19:20:48 +0800 X-QQ-mid: xmsmtpt1702034499t1z09xkmu Message-ID: X-QQ-XMAILINFO: Nfm/+M6ONQ57SBF37mfK0SmLAsrop4F25W7X6rEQSu1Vo1CcOFSZDeQ++P/MWm lOABzWg6ytfWOYkRPo+va8JiGP1Fmcrp+RWo5er5nXTYvqt/o/JXUmeJXlgiXHu5wbVDXz1C7OIb dEKjBbY51MJ/t/L5uUKZXzw84ZoQiZo5dq66CB1QroybbdClDH7M36HnTqB6MkuoL4079zi3eeNY g9mqr3+S/TTOgITHd4/H1W2pwrSLCQzzwX2JHuld+/odG91vkY0MQ7fOcQuR5SL3sGpQTOwSVnu2 y6DlmG96TJnbxzcMSvXJpkILuEXfeakf5dJPB3S21uQmlNJPfAi7xX4oNlokIJd/RKYr2cBRs9zA M6q3x19tYoTzjM4otTtYLDAU6+ng9sHM9G9ZWPtKzrGMa/BAUBizQ2tG29whZ0GqP2dRinH78Ljh 9AciO9y8xRzZkfr8LoRluNLICI0YqIpPoWrEC0V4Ax/0RJoeRJLXgxTjxlVKSL/2YwfuETHG0Yrd ptZiF0b2UyyNLv7x6LXtCenyFHmoZmghtEqYC6iRv5SnU68zZQF9SGrgxTnniEsRPPdsOKc1qT/F ZfPVhmjxorbRimCBhH6ykZwWE0XY4RCyPKxYcknJtGAxCmnYoR4/VDUlkPVPcNrWPSdWbl7ZSTXF 6tyrMQT+63AgJtHOC5rxuyJlDItiZP2JIk+9nEr+KkSbM9/c8qWVfE84QDwRkvQ6kl+1pwXC3aVd jYN1ZgYYMq12ct0l4fSOPe1LwD/gtNr4rFCzVUAs2LCSb3NX/37G5wS/7gp8ZatHnEcEGrnM6YDA p/ax8yggnakfHWuhrkOhmHysgvCelMR7fd2MYyi5iDXzozDqN8i2JBF5MLbL8xu8mkwBSwdAlIfu b+9EQEhHwij9+8/Vfu85fJZhje6QZmnDIix92iNgjJBIEJwi2CVTODwk1o3p/mlm5KwegwMkDaSi LOGdHNnoFvuP66f54G7EXBbTZ23zIa0B9/YoeNgvUrUtW6MYZhVYkK3tLTmhPD X-QQ-XMRINFO: NyFYKkN4Ny6FSmKK/uo/jdU= From: yuezhang.mo@foxmail.com To: linkinjeon@kernel.org, sj1557.seo@samsung.com Cc: linux-fsdevel@vger.kernel.org, Andy.Wu@sony.com, wataru.aoyama@sony.com, Yuezhang Mo Subject: [PATCH v1 07/11] exfat: covert exfat_init_ext_entry() to use dentry cache Date: Fri, 8 Dec 2023 19:23:16 +0800 X-OQ-MSGID: <20231208112318.1135649-8-yuezhang.mo@foxmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231208112318.1135649-1-yuezhang.mo@foxmail.com> References: <20231208112318.1135649-1-yuezhang.mo@foxmail.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Yuezhang Mo Before this conversion, in exfat_init_ext_entry(), to init the dentries in a dentry set, the sync times is equals the dentry number if 'dirsync' or 'sync' is enabled. That affects not only performance but also device life. After this conversion, only needs to be synchronized once if 'dirsync' or 'sync' is enabled. Signed-off-by: Yuezhang Mo Reviewed-by: Andy Wu Reviewed-by: Aoyama Wataru --- fs/exfat/dir.c | 33 +++++--------------- fs/exfat/exfat_fs.h | 4 +-- fs/exfat/namei.c | 73 +++++++++++++++------------------------------ 3 files changed, 33 insertions(+), 77 deletions(-) diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index 8965bb2c99ae..94cedc145291 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -532,46 +532,27 @@ static void exfat_free_benign_secondary_clusters(struct inode *inode, exfat_free_cluster(inode, &dir); } -int exfat_init_ext_entry(struct inode *inode, struct exfat_chain *p_dir, - int entry, int num_entries, struct exfat_uni_name *p_uniname) +void exfat_init_ext_entry(struct exfat_entry_set_cache *es, int num_entries, + struct exfat_uni_name *p_uniname) { - struct super_block *sb = inode->i_sb; int i; unsigned short *uniname = p_uniname->name; struct exfat_dentry *ep; - struct buffer_head *bh; - int sync = IS_DIRSYNC(inode); - - ep = exfat_get_dentry(sb, p_dir, entry, &bh); - if (!ep) - return -EIO; + ep = exfat_get_dentry_cached(es, ES_IDX_FILE); ep->dentry.file.num_ext = (unsigned char)(num_entries - 1); - exfat_update_bh(bh, sync); - brelse(bh); - - ep = exfat_get_dentry(sb, p_dir, entry + 1, &bh); - if (!ep) - return -EIO; + ep = exfat_get_dentry_cached(es, ES_IDX_STREAM); ep->dentry.stream.name_len = p_uniname->name_len; ep->dentry.stream.name_hash = cpu_to_le16(p_uniname->name_hash); - exfat_update_bh(bh, sync); - brelse(bh); - - for (i = EXFAT_FIRST_CLUSTER; i < num_entries; i++) { - ep = exfat_get_dentry(sb, p_dir, entry + i, &bh); - if (!ep) - return -EIO; + for (i = ES_IDX_FIRST_FILENAME; i < num_entries; i++) { + ep = exfat_get_dentry_cached(es, i); exfat_init_name_entry(ep, uniname); - exfat_update_bh(bh, sync); - brelse(bh); uniname += EXFAT_FILE_NAME_LEN; } - exfat_update_dir_chksum(inode, p_dir, entry); - return 0; + exfat_update_dir_chksum_with_entry_set(es); } void exfat_remove_entries(struct inode *inode, struct exfat_entry_set_cache *es, diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h index 46031e77f58b..0280a975586c 100644 --- a/fs/exfat/exfat_fs.h +++ b/fs/exfat/exfat_fs.h @@ -483,8 +483,8 @@ unsigned int exfat_get_entry_type(struct exfat_dentry *p_entry); void exfat_init_dir_entry(struct exfat_entry_set_cache *es, unsigned int type, unsigned int start_clu, unsigned long long size, struct timespec64 *ts); -int exfat_init_ext_entry(struct inode *inode, struct exfat_chain *p_dir, - int entry, int num_entries, struct exfat_uni_name *p_uniname); +void exfat_init_ext_entry(struct exfat_entry_set_cache *es, int num_entries, + struct exfat_uni_name *p_uniname); void exfat_remove_entries(struct inode *inode, struct exfat_entry_set_cache *es, int order); int exfat_update_dir_chksum(struct inode *inode, struct exfat_chain *p_dir, diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c index 9a0d8f2deea6..ee7d5fd0b16f 100644 --- a/fs/exfat/namei.c +++ b/fs/exfat/namei.c @@ -522,15 +522,12 @@ static int exfat_add_entry(struct inode *inode, const char *path, goto out; exfat_init_dir_entry(&es, type, start_clu, clu_size, &ts); + exfat_init_ext_entry(&es, num_entries, &uniname); ret = exfat_put_dentry_set(&es, IS_DIRSYNC(inode)); if (ret) goto out; - ret = exfat_init_ext_entry(inode, p_dir, dentry, num_entries, &uniname); - if (ret) - goto out; - info->dir = *p_dir; info->entry = dentry; info->flags = ALLOC_NO_FAT_CHAIN; @@ -1001,8 +998,7 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir, int ret, num_new_entries; struct exfat_dentry *epold, *epnew; struct super_block *sb = inode->i_sb; - struct buffer_head *new_bh; - struct exfat_entry_set_cache old_es; + struct exfat_entry_set_cache old_es, new_es; int sync = IS_DIRSYNC(inode); num_new_entries = exfat_calc_num_entries(p_uniname); @@ -1027,33 +1023,25 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir, goto put_old_es; } - epnew = exfat_get_dentry(sb, p_dir, newentry, &new_bh); - if (!epnew) { - ret = -EIO; + ret = exfat_get_empty_dentry_set(&new_es, sb, p_dir, newentry, + num_new_entries); + if (ret) goto put_old_es; - } + epnew = exfat_get_dentry_cached(&new_es, ES_IDX_FILE); *epnew = *epold; if (exfat_get_entry_type(epnew) == TYPE_FILE) { epnew->dentry.file.attr |= cpu_to_le16(EXFAT_ATTR_ARCHIVE); ei->attr |= EXFAT_ATTR_ARCHIVE; } - exfat_update_bh(new_bh, sync); - brelse(new_bh); epold = exfat_get_dentry_cached(&old_es, ES_IDX_STREAM); - epnew = exfat_get_dentry(sb, p_dir, newentry + 1, &new_bh); - if (!epnew) { - ret = -EIO; - goto put_old_es; - } - + epnew = exfat_get_dentry_cached(&new_es, ES_IDX_STREAM); *epnew = *epold; - exfat_update_bh(new_bh, sync); - brelse(new_bh); - ret = exfat_init_ext_entry(inode, p_dir, newentry, - num_new_entries, p_uniname); + exfat_init_ext_entry(&new_es, num_new_entries, p_uniname); + + ret = exfat_put_dentry_set(&new_es, sync); if (ret) goto put_old_es; @@ -1067,11 +1055,7 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir, } exfat_remove_entries(inode, &old_es, ES_IDX_FIRST_FILENAME + 1); - - ret = exfat_init_ext_entry(inode, p_dir, oldentry, - num_new_entries, p_uniname); - if (ret) - goto put_old_es; + exfat_init_ext_entry(&old_es, num_new_entries, p_uniname); } return exfat_put_dentry_set(&old_es, sync); @@ -1087,8 +1071,7 @@ static int exfat_move_file(struct inode *inode, struct exfat_chain *p_olddir, int ret, newentry, num_new_entries; struct exfat_dentry *epmov, *epnew; struct super_block *sb = inode->i_sb; - struct buffer_head *new_bh; - struct exfat_entry_set_cache mov_es; + struct exfat_entry_set_cache mov_es, new_es; num_new_entries = exfat_calc_num_entries(p_uniname); if (num_new_entries < 0) @@ -1103,43 +1086,35 @@ static int exfat_move_file(struct inode *inode, struct exfat_chain *p_olddir, if (ret) return -EIO; - epmov = exfat_get_dentry_cached(&mov_es, ES_IDX_FILE); - epnew = exfat_get_dentry(sb, p_newdir, newentry, &new_bh); - if (!epnew) { - ret = -EIO; + ret = exfat_get_empty_dentry_set(&new_es, sb, p_newdir, newentry, + num_new_entries); + if (ret) goto put_mov_es; - } + epmov = exfat_get_dentry_cached(&mov_es, ES_IDX_FILE); + epnew = exfat_get_dentry_cached(&new_es, ES_IDX_FILE); *epnew = *epmov; if (exfat_get_entry_type(epnew) == TYPE_FILE) { epnew->dentry.file.attr |= cpu_to_le16(EXFAT_ATTR_ARCHIVE); ei->attr |= EXFAT_ATTR_ARCHIVE; } - exfat_update_bh(new_bh, IS_DIRSYNC(inode)); - brelse(new_bh); epmov = exfat_get_dentry_cached(&mov_es, ES_IDX_STREAM); - epnew = exfat_get_dentry(sb, p_newdir, newentry + 1, &new_bh); - if (!epnew) { - ret = -EIO; - goto put_mov_es; - } - + epnew = exfat_get_dentry_cached(&new_es, ES_IDX_STREAM); *epnew = *epmov; - exfat_update_bh(new_bh, IS_DIRSYNC(inode)); - brelse(new_bh); - - ret = exfat_init_ext_entry(inode, p_newdir, newentry, num_new_entries, - p_uniname); - if (ret) - return ret; + exfat_init_ext_entry(&new_es, num_new_entries, p_uniname); exfat_remove_entries(inode, &mov_es, ES_IDX_FILE); exfat_chain_set(&ei->dir, p_newdir->dir, p_newdir->size, p_newdir->flags); ei->entry = newentry; + + ret = exfat_put_dentry_set(&new_es, IS_DIRSYNC(inode)); + if (ret) + goto put_mov_es; + return exfat_put_dentry_set(&mov_es, IS_DIRSYNC(inode)); put_mov_es: From patchwork Fri Dec 8 11:23:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuezhang Mo X-Patchwork-Id: 13485322 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=foxmail.com header.i=@foxmail.com header.b="wgrry+vw" Received: from out203-205-221-209.mail.qq.com (out203-205-221-209.mail.qq.com [203.205.221.209]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD442172C for ; Fri, 8 Dec 2023 03:27:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1702034872; bh=efnKlWPIgV+aCUly4gyc3WFDYD3OwkbfwJMA+1xkW9A=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=wgrry+vwcH/0BZ+daEKla63IRw39ZONldl/dGQN07HJclwPnGm9ct3/3n9Zp1xu4S KYu2QOG9jnKlNA5fVOEF2SIaQAecZscp9gcglsTk/I6d2mrL/AQ8lfIicpVBAgy/WI Qt7QYL+BgTno+lHGaPAB1pZITm1k095iSFTpdqKY= Received: from localhost.localdomain ([180.164.182.58]) by newxmesmtplogicsvrszc5-0.qq.com (NewEsmtp) with SMTP id 530B9A94; Fri, 08 Dec 2023 19:20:48 +0800 X-QQ-mid: xmsmtpt1702034501tv5pwhro8 Message-ID: X-QQ-XMAILINFO: N7h1OCCDntuj0JKncji42R9whlDJAn9T6+OtACvN2IBltKvBdkwsNa1R7DyE5f regx2+CRiIMH9mdl7v3AHbdwOXDai/j5N8PYJe2U+CmUoYPyhdF2EC3jFxB11EpdXa3ZpLvwMUWF b5haSHGo3ljAXKUJps2ZlAwpHr6nj5I8rU4GGeRYN/5bBPiL414GBBCkj2imjAGspCXytFLb7ed0 g/XTymvhEkSpNpcBW2TkpgahhHaqkDzo7KLDwVzuZOk/Otp1O+Vgt97wqpN9q881xtvajVhLafjT lHak0fclrNBLoKyq/tHuOevr5xDSK5fz2jKKItaCY5J1nc7o5qtNDrn+zTUUvnsBHsAJtqHsyHa0 rBSV7yIvOMhnoE0maL4UCQTV699LZ9mpkdqGyCqxWZUQb8kzALTq2hRHJTouIPfALdSobdDiwtoQ i8OIPatUrj1OBFNzeWm+yFiksnPLBzVM/m3wdaMuYKJNk564Big7vMAYs7XNxaiPrsL/JUmBhtbi Bpm5BtQ10C/HxDM1HaW5qvXerQI3DbQO2NZ8zY0VNp73Lr0bgY0KDdP0X465Irr7zhdIJh8As83s 1Ouap90egB9OUuyE+lLLgAMxjjDC02arfpudtDcKO8MrGMo11Lfl4a31mU4j87oS5IraOQPCtXR8 JenHFv1bq4cYIWTR9gBsQJgvrRWHsqQ8vokHSEZlvEohRjI5TBACi7uJZcCV/An+gaMlmt/zSLWe gUUGfRi2v6YDCco+5ixVkn1cDFvWrJf7s4edZCRb6XrvvUPqHGmlAtuMa41UgTIdAv9LAa3Ih48C EI6Z2iyNFSvoyOUmc3lrLCpRpWTmGsEoIeQYqWC6PsVMulj/SidAdVdBNAw0UoYy/8nVMJaDATbu mYigR4xrdNVxD+fCEHfJeKcBgbjKuo1K4x8qn4fXQOUvK8pUa/leVKmK7OMx+sXn2vCiATq+2CFQ peLJS4HxQt38aEdJjxJqXj5W3ZvqhBt6Z9Fp5vQwo= X-QQ-XMRINFO: OD9hHCdaPRBwq3WW+NvGbIU= From: yuezhang.mo@foxmail.com To: linkinjeon@kernel.org, sj1557.seo@samsung.com Cc: linux-fsdevel@vger.kernel.org, Andy.Wu@sony.com, wataru.aoyama@sony.com, Yuezhang Mo Subject: [PATCH v1 08/11] exfat: remove __exfat_find_empty_entry() Date: Fri, 8 Dec 2023 19:23:17 +0800 X-OQ-MSGID: <20231208112318.1135649-9-yuezhang.mo@foxmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231208112318.1135649-1-yuezhang.mo@foxmail.com> References: <20231208112318.1135649-1-yuezhang.mo@foxmail.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Yuezhang Mo This commit removes exfat_find_empty_entry() and renames __exfat_find_empty_entry() to exfat_find_empty_entry(). Signed-off-by: Yuezhang Mo Reviewed-by: Andy Wu Reviewed-by: Aoyama Wataru --- fs/exfat/namei.c | 49 ++++++++++++------------------------------------ 1 file changed, 12 insertions(+), 37 deletions(-) diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c index ee7d5fd0b16f..79e3fc9d6e19 100644 --- a/fs/exfat/namei.c +++ b/fs/exfat/namei.c @@ -291,7 +291,7 @@ static int exfat_check_max_dentries(struct inode *inode) /* find empty directory entry. * if there isn't any empty slot, expand cluster chain. */ -static int __exfat_find_empty_entry(struct inode *inode, +static int exfat_find_empty_entry(struct inode *inode, struct exfat_chain *p_dir, int num_entries, struct exfat_entry_set_cache *es) { @@ -382,21 +382,6 @@ static int __exfat_find_empty_entry(struct inode *inode, return dentry; } -static int exfat_find_empty_entry(struct inode *inode, - struct exfat_chain *p_dir, int num_entries) -{ - int entry; - struct exfat_entry_set_cache es; - - entry = __exfat_find_empty_entry(inode, p_dir, num_entries, &es); - if (entry < 0) - return entry; - - exfat_put_dentry_set(&es, false); - - return entry; -} - /* * Name Resolution Functions : * Zero if it was successful; otherwise nonzero. @@ -498,7 +483,7 @@ static int exfat_add_entry(struct inode *inode, const char *path, } /* exfat_find_empty_entry must be called before alloc_cluster() */ - dentry = exfat_find_empty_entry(inode, p_dir, num_entries); + dentry = exfat_find_empty_entry(inode, p_dir, num_entries, &es); if (dentry < 0) { ret = dentry; /* -EIO or -ENOSPC */ goto out; @@ -506,8 +491,10 @@ static int exfat_add_entry(struct inode *inode, const char *path, if (type == TYPE_DIR && !sbi->options.zero_size_dir) { ret = exfat_alloc_new_dir(inode, &clu); - if (ret) + if (ret) { + exfat_put_dentry_set(&es, false); goto out; + } start_clu = clu.dir; clu_size = sbi->cluster_size; } @@ -516,11 +503,6 @@ static int exfat_add_entry(struct inode *inode, const char *path, /* fill the dos name directory entry information of the created file. * the first cluster is not determined yet. (0) */ - - ret = exfat_get_empty_dentry_set(&es, sb, p_dir, dentry, num_entries); - if (ret) - goto out; - exfat_init_dir_entry(&es, type, start_clu, clu_size, &ts); exfat_init_ext_entry(&es, num_entries, &uniname); @@ -1016,18 +998,13 @@ static int exfat_rename_file(struct inode *inode, struct exfat_chain *p_dir, if (old_es.num_entries < num_new_entries) { int newentry; - newentry = - exfat_find_empty_entry(inode, p_dir, num_new_entries); + newentry = exfat_find_empty_entry(inode, p_dir, num_new_entries, + &new_es); if (newentry < 0) { ret = newentry; /* -EIO or -ENOSPC */ goto put_old_es; } - ret = exfat_get_empty_dentry_set(&new_es, sb, p_dir, newentry, - num_new_entries); - if (ret) - goto put_old_es; - epnew = exfat_get_dentry_cached(&new_es, ES_IDX_FILE); *epnew = *epold; if (exfat_get_entry_type(epnew) == TYPE_FILE) { @@ -1077,19 +1054,17 @@ static int exfat_move_file(struct inode *inode, struct exfat_chain *p_olddir, if (num_new_entries < 0) return num_new_entries; - newentry = exfat_find_empty_entry(inode, p_newdir, num_new_entries); - if (newentry < 0) - return newentry; /* -EIO or -ENOSPC */ - ret = exfat_get_dentry_set(&mov_es, sb, p_olddir, oldentry, ES_ALL_ENTRIES); if (ret) return -EIO; - ret = exfat_get_empty_dentry_set(&new_es, sb, p_newdir, newentry, - num_new_entries); - if (ret) + newentry = exfat_find_empty_entry(inode, p_newdir, num_new_entries, + &new_es); + if (newentry < 0) { + ret = newentry; /* -EIO or -ENOSPC */ goto put_mov_es; + } epmov = exfat_get_dentry_cached(&mov_es, ES_IDX_FILE); epnew = exfat_get_dentry_cached(&new_es, ES_IDX_FILE); From patchwork Fri Dec 8 11:23:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuezhang Mo X-Patchwork-Id: 13485323 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=foxmail.com header.i=@foxmail.com header.b="u2DBbl8K" Received: from out203-205-221-155.mail.qq.com (out203-205-221-155.mail.qq.com [203.205.221.155]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2156F10DA for ; Fri, 8 Dec 2023 03:28:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1702034880; bh=4GBoC0gYPldUjUEGpilpruyOmY/wrXDXA2dEFhgCO2c=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=u2DBbl8KBGS8XktnaVcZl0EBJbffcBCgantODOY1BFY7esm7Y6VCy3B8kbdAtCSiN Lir6rJuNhx4YSGbEIndpiA1OZFg6aKPTSERIwLa1uH5tl55K9dN6fQ1IDLZ6LDZG1U N4UfCK4vxbQMMJq9355GH87umV0FfJu5RETZtFsA= Received: from localhost.localdomain ([180.164.182.58]) by newxmesmtplogicsvrszc5-0.qq.com (NewEsmtp) with SMTP id 530B9A94; Fri, 08 Dec 2023 19:20:48 +0800 X-QQ-mid: xmsmtpt1702034503te7cs98g6 Message-ID: X-QQ-XMAILINFO: MFWpArBVhhGT0AaG2QyKGAXauDJzuTNtMN/SuQSJEUUOr9cpFAniT0CuljEzTr XOf9zP8RIAbr07KJrEeyTir0Yf73r4SuauhxJAtQ3qmEIpSxTwLW/h54eFv/jJznlOeq0uqdwrXJ 0FDvhQ9FeDQuIfQFOlWl/LFphQ4YIKfw7h47jKpN++zKNplZUZS/ViRLlkGLTPjkf3YLQlmEjC/c Q/14qcG+6ezPN178zLTbHQE4RaADnb1TDvjBAFXe4l9b6jZ9yz1Gz5WywDvsVZfnuK0lygmZj1FB Ni57YPwvu8EjXQdp8sC4DgwResykt3iRIaNV4v4uuyeWTC5QA3NSyalbAgpDIK8ZoDxUWLXd5WM8 DqFSVvluqqmc1jpUrn9p7xUxPy4pZn5ozmJhVlT1AJREkchTn1rS5pifX5oZ97TVDCQEdoZYBNJh 7ZywCvUVYEMQEbijhQi+RtZL9/iQvyHPHizBzRAvBfFtx1bKz7r76jBFKOfL/6H9JO4GY1oeyTlG FU2KNaVdOjrNcm9zoNEGtiwhsIV+T7MHfbbMWk0znUFUOwdaqYruAkRtiRoUd5HWS6YUuAtovcqx 8Gwqf2iqGOymT95TNbO3yauOlM+POmNgLnDF89PO+jLZGq1V94IfhWuDOuF92bBYWnUxMxzF19nk QLZVWzNvhNhI0iJa7qrGwBGPDjWmp+MbTfAhngCueedcAV1VhTSQ3CWdqRyfVt2v4u85i2bsnwbL QLSYuBzkB7ddiBUc0FxntPD0scg9A5Dht6O4R1C2BIYJ3gYV+6q9vUkysG2bmDQRtiSPBBX8NN8j Sgm65lv8PiWRxFzBo5vLBMKtJrvkw8MqGTfJ+ogylGJcj7v78+zHKKt/MUt4mtSihQ8QAd8VqwVW +XlidOszP8R20+jRmmrfaAv0vdoOYNQTvpLW554qyc3GDWjhgqm6FJzMPFzyiUatSiKgC8ujDggl w4T+zp5ajxoGQq/fIJlFCOmCdenboGrcDViefv4s3HqVWJq/zv7ipsrn0TlnGoMa0i0x9/L0s= X-QQ-XMRINFO: Mp0Kj//9VHAxr69bL5MkOOs= From: yuezhang.mo@foxmail.com To: linkinjeon@kernel.org, sj1557.seo@samsung.com Cc: linux-fsdevel@vger.kernel.org, Andy.Wu@sony.com, wataru.aoyama@sony.com, Yuezhang Mo Subject: [PATCH v1 09/11] exfat: remove unused functions Date: Fri, 8 Dec 2023 19:23:18 +0800 X-OQ-MSGID: <20231208112318.1135649-10-yuezhang.mo@foxmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231208112318.1135649-1-yuezhang.mo@foxmail.com> References: <20231208112318.1135649-1-yuezhang.mo@foxmail.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Yuezhang Mo exfat_count_ext_entries() is no longer called, remove it. exfat_update_dir_chksum() is no longer called, remove it and rename exfat_update_dir_chksum_with_entry_set() to it. Signed-off-by: Yuezhang Mo Reviewed-by: Andy Wu Reviewed-by: Aoyama Wataru --- fs/exfat/dir.c | 60 ++------------------------------------------- fs/exfat/exfat_fs.h | 6 +---- fs/exfat/inode.c | 2 +- 3 files changed, 4 insertions(+), 64 deletions(-) diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index 94cedc145291..c57a727d5285 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -478,41 +478,6 @@ void exfat_init_dir_entry(struct exfat_entry_set_cache *es, exfat_init_stream_entry(ep, start_clu, size); } -int exfat_update_dir_chksum(struct inode *inode, struct exfat_chain *p_dir, - int entry) -{ - struct super_block *sb = inode->i_sb; - int ret = 0; - int i, num_entries; - u16 chksum; - struct exfat_dentry *ep, *fep; - struct buffer_head *fbh, *bh; - - fep = exfat_get_dentry(sb, p_dir, entry, &fbh); - if (!fep) - return -EIO; - - num_entries = fep->dentry.file.num_ext + 1; - chksum = exfat_calc_chksum16(fep, DENTRY_SIZE, 0, CS_DIR_ENTRY); - - for (i = 1; i < num_entries; i++) { - ep = exfat_get_dentry(sb, p_dir, entry + i, &bh); - if (!ep) { - ret = -EIO; - goto release_fbh; - } - chksum = exfat_calc_chksum16(ep, DENTRY_SIZE, chksum, - CS_DEFAULT); - brelse(bh); - } - - fep->dentry.file.checksum = cpu_to_le16(chksum); - exfat_update_bh(fbh, IS_DIRSYNC(inode)); -release_fbh: - brelse(fbh); - return ret; -} - static void exfat_free_benign_secondary_clusters(struct inode *inode, struct exfat_dentry *ep) { @@ -552,7 +517,7 @@ void exfat_init_ext_entry(struct exfat_entry_set_cache *es, int num_entries, uniname += EXFAT_FILE_NAME_LEN; } - exfat_update_dir_chksum_with_entry_set(es); + exfat_update_dir_chksum(es); } void exfat_remove_entries(struct inode *inode, struct exfat_entry_set_cache *es, @@ -574,7 +539,7 @@ void exfat_remove_entries(struct inode *inode, struct exfat_entry_set_cache *es, es->modified = true; } -void exfat_update_dir_chksum_with_entry_set(struct exfat_entry_set_cache *es) +void exfat_update_dir_chksum(struct exfat_entry_set_cache *es) { int chksum_type = CS_DIR_ENTRY, i; unsigned short chksum = 0; @@ -1237,27 +1202,6 @@ int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei, return dentry - num_ext; } -int exfat_count_ext_entries(struct super_block *sb, struct exfat_chain *p_dir, - int entry, struct exfat_dentry *ep) -{ - int i, count = 0; - unsigned int type; - struct exfat_dentry *ext_ep; - struct buffer_head *bh; - - for (i = 0, entry++; i < ep->dentry.file.num_ext; i++, entry++) { - ext_ep = exfat_get_dentry(sb, p_dir, entry, &bh); - if (!ext_ep) - return -EIO; - - type = exfat_get_entry_type(ext_ep); - brelse(bh); - if (type & TYPE_CRITICAL_SEC || type & TYPE_BENIGN_SEC) - count++; - } - return count; -} - int exfat_count_dir_entries(struct super_block *sb, struct exfat_chain *p_dir) { int i, count = 0; diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h index 0280a975586c..a2c70b3a27bd 100644 --- a/fs/exfat/exfat_fs.h +++ b/fs/exfat/exfat_fs.h @@ -431,8 +431,6 @@ int exfat_ent_get(struct super_block *sb, unsigned int loc, unsigned int *content); int exfat_ent_set(struct super_block *sb, unsigned int loc, unsigned int content); -int exfat_count_ext_entries(struct super_block *sb, struct exfat_chain *p_dir, - int entry, struct exfat_dentry *p_entry); int exfat_chain_cont_cluster(struct super_block *sb, unsigned int chain, unsigned int len); int exfat_zeroed_cluster(struct inode *dir, unsigned int clu); @@ -487,9 +485,7 @@ void exfat_init_ext_entry(struct exfat_entry_set_cache *es, int num_entries, struct exfat_uni_name *p_uniname); void exfat_remove_entries(struct inode *inode, struct exfat_entry_set_cache *es, int order); -int exfat_update_dir_chksum(struct inode *inode, struct exfat_chain *p_dir, - int entry); -void exfat_update_dir_chksum_with_entry_set(struct exfat_entry_set_cache *es); +void exfat_update_dir_chksum(struct exfat_entry_set_cache *es); int exfat_calc_num_entries(struct exfat_uni_name *p_uniname); int exfat_find_dir_entry(struct super_block *sb, struct exfat_inode_info *ei, struct exfat_chain *p_dir, struct exfat_uni_name *p_uniname, diff --git a/fs/exfat/inode.c b/fs/exfat/inode.c index 522edcbb2ce4..0614bccfbe76 100644 --- a/fs/exfat/inode.c +++ b/fs/exfat/inode.c @@ -94,7 +94,7 @@ int __exfat_write_inode(struct inode *inode, int sync) ep2->dentry.stream.start_clu = EXFAT_FREE_CLUSTER; } - exfat_update_dir_chksum_with_entry_set(&es); + exfat_update_dir_chksum(&es); return exfat_put_dentry_set(&es, sync); } From patchwork Fri Dec 8 11:23:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yuezhang Mo X-Patchwork-Id: 13485325 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=foxmail.com header.i=@foxmail.com header.b="LQb5RX09" Received: from out162-62-57-49.mail.qq.com (out162-62-57-49.mail.qq.com [162.62.57.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79B3410F7 for ; Fri, 8 Dec 2023 03:30:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1702035009; bh=cv3cK8vQYwCgVCck4+KMVVaFBdsPTiUNyCcJ325ZB/A=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=LQb5RX09HfxZWireVsoQaeBY8Gyb+8+mCyL4WaUFpeGkye+Jx7FkePKPDWQBJn+6s ONW2A0VWTtnRCD76W05U5zswyZMxtDCN1guDTKMtpFWkHScmPUttonq1bRlIrAMxiG a60w84nLBwZN1Ns6u5O2Z3kDcin+MwmCWRY1L+LM= Received: from localhost.localdomain ([180.164.182.58]) by newxmesmtplogicsvrszc5-0.qq.com (NewEsmtp) with SMTP id 530B9A94; Fri, 08 Dec 2023 19:20:48 +0800 X-QQ-mid: xmsmtpt1702034505t4l6op3qg Message-ID: X-QQ-XMAILINFO: NQR8mRxMnur9lBseoUVoM6+eakXSWLsAZ5Hil6AnwLXUjH5cYV7w9Xgsy8K098 TjZF+fon1dOUWNke0ZYhnvuaYtSnvNLDKYR464MW4LjEB57YagXAXUkTkkzIQp49vNOvOmQ5I0bK VDheK3Lg8V2Kkmq1EXzUizMu+53HVze1G6/ojjSmdMD5COE20PhdBIRutYHXWeyiwsdDnd6fDFbE CjEe2fFo189POK/8lQ3d/HjKPnQVYiPS7pKL+kClxpxvQtXW2sEOxBiAK0yvMq+Jdy41tqYZojtK ew9jyG9fB7V4UZMds326+R7TZXqkk85DuXFLZUbyCv8dYqMWc9uSpee/mARs/6bJ/5PgbrsM43r3 H+1DmOHp4aH5MCdeXwTsNp5XZK4gcaeU/Rq0raJStdLnA5nbhR6YAzhEwyxfiHQaG9kBQBMV0QjA 3SpfVa6/xwhR4Jmx6L+wmyvro9K/Xj2eU8Nawp0vTiRXPwDbDZ1B6sk71v9XFBrPy83KPmAaQY4T gZvDTevFnmpNkKfM1pUYpPy0MedaO8sVOskHuE0+AriVh+/wdoOC4+wCrn/sqbpl4H5HN9pXEOoy igcx5b+om43vW9eFmRlSanJfOlmrfBCnrC3ExjB+ftJD/t73sNJMqtAL047mYGAoaDkRvAJvNgpj 7df/oiphqHosMuYSVRjN9WJvHQDL8NRBUAkzKDibfjhGOFmDrJCzWKRGKXIGx8gyxbnGS9yy95At /5W2s76mhullqfhJT4NRHHb1iYcyn6xX8bhOaO+deza9vvaQ0UTedcEjIkly8HE3ny4aMtBJbsNQ wGaVNWNoXkH3Jg3NViDXlmmuy9cn4M01QZlLwmYDCMPVCWaTLP5HOmcWwOguW+gjzmeKfZ3SHHJG lp39MJoXUpiqIPhrMzh3j/YlIZnjnUzf8yXupYj//BgOPSAC9ItbtkSuGu9kqitr/1FukIsmEv0m gcSDjjf/c21Ku/pEpQzhzDgW1zDBPVWguKKElpE4JaJ24hPDAbkQJoTbBWDT8M X-QQ-XMRINFO: OD9hHCdaPRBwq3WW+NvGbIU= From: yuezhang.mo@foxmail.com To: linkinjeon@kernel.org, sj1557.seo@samsung.com Cc: linux-fsdevel@vger.kernel.org, Andy.Wu@sony.com, wataru.aoyama@sony.com, Yuezhang Mo Subject: [PATCH v1 10/11] exfat: do not sync parent dir if just update timestamp Date: Fri, 8 Dec 2023 19:23:19 +0800 X-OQ-MSGID: <20231208112318.1135649-11-yuezhang.mo@foxmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231208112318.1135649-1-yuezhang.mo@foxmail.com> References: <20231208112318.1135649-1-yuezhang.mo@foxmail.com> Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Yuezhang Mo When sync or dir_sync is enabled, there is no need to sync the parent directory's inode if only for updating its timestamp. 1. If an unexpected power failure occurs, the timestamp of the parent directory is not updated to the storage, which has no impact on the user. 2. The number of writes will be greatly reduced, which can not only improve performance, but also prolong device life. Signed-off-by: Yuezhang Mo Reviewed-by: Andy Wu Reviewed-by: Aoyama Wataru --- fs/exfat/namei.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c index 79e3fc9d6e19..b33497845a06 100644 --- a/fs/exfat/namei.c +++ b/fs/exfat/namei.c @@ -547,6 +547,7 @@ static int exfat_create(struct mnt_idmap *idmap, struct inode *dir, struct exfat_dir_entry info; loff_t i_pos; int err; + loff_t size = i_size_read(dir); mutex_lock(&EXFAT_SB(sb)->s_lock); exfat_set_volume_dirty(sb); @@ -557,7 +558,7 @@ static int exfat_create(struct mnt_idmap *idmap, struct inode *dir, inode_inc_iversion(dir); inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); - if (IS_DIRSYNC(dir)) + if (IS_DIRSYNC(dir) && size != i_size_read(dir)) exfat_sync_inode(dir); else mark_inode_dirty(dir); @@ -801,10 +802,7 @@ static int exfat_unlink(struct inode *dir, struct dentry *dentry) inode_inc_iversion(dir); simple_inode_init_ts(dir); exfat_truncate_inode_atime(dir); - if (IS_DIRSYNC(dir)) - exfat_sync_inode(dir); - else - mark_inode_dirty(dir); + mark_inode_dirty(dir); clear_nlink(inode); simple_inode_init_ts(inode); @@ -825,6 +823,7 @@ static int exfat_mkdir(struct mnt_idmap *idmap, struct inode *dir, struct exfat_chain cdir; loff_t i_pos; int err; + loff_t size = i_size_read(dir); mutex_lock(&EXFAT_SB(sb)->s_lock); exfat_set_volume_dirty(sb); @@ -835,7 +834,7 @@ static int exfat_mkdir(struct mnt_idmap *idmap, struct inode *dir, inode_inc_iversion(dir); inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); - if (IS_DIRSYNC(dir)) + if (IS_DIRSYNC(dir) && size != i_size_read(dir)) exfat_sync_inode(dir); else mark_inode_dirty(dir); @@ -1239,6 +1238,7 @@ static int exfat_rename(struct mnt_idmap *idmap, struct super_block *sb = old_dir->i_sb; loff_t i_pos; int err; + loff_t size = i_size_read(new_dir); /* * The VFS already checks for existence, so for local filesystems @@ -1260,7 +1260,7 @@ static int exfat_rename(struct mnt_idmap *idmap, simple_rename_timestamp(old_dir, old_dentry, new_dir, new_dentry); EXFAT_I(new_dir)->i_crtime = current_time(new_dir); exfat_truncate_inode_atime(new_dir); - if (IS_DIRSYNC(new_dir)) + if (IS_DIRSYNC(new_dir) && size != i_size_read(new_dir)) exfat_sync_inode(new_dir); else mark_inode_dirty(new_dir); @@ -1281,10 +1281,7 @@ static int exfat_rename(struct mnt_idmap *idmap, } inode_inc_iversion(old_dir); - if (IS_DIRSYNC(old_dir)) - exfat_sync_inode(old_dir); - else - mark_inode_dirty(old_dir); + mark_inode_dirty(old_dir); if (new_inode) { exfat_unhash_inode(new_inode);