All of lore.kernel.org
 help / color / mirror / Atom feed
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 <Yuezhang.Mo@sony.com>
Subject: [PATCH v1 02/11] exfat: add exfat_get_empty_dentry_set() helper
Date: Fri,  8 Dec 2023 19:23:11 +0800	[thread overview]
Message-ID: <tencent_ACDA02351A05A74A2E0CA9617EC5E960E208@qq.com> (raw)
In-Reply-To: <20231208112318.1135649-1-yuezhang.mo@foxmail.com>

From: Yuezhang Mo <Yuezhang.Mo@sony.com>

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 <Yuezhang.Mo@sony.com>
Reviewed-by: Andy Wu <Andy.Wu@sony.com>
Reviewed-by: Aoyama Wataru <wataru.aoyama@sony.com>
---
 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);
 
-- 
2.25.1


  parent reply	other threads:[~2023-12-08 11:27 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20231208112318.1135649-1-yuezhang.mo@foxmail.com>
2023-12-08 11:23 ` [PATCH v1 01/11] exfat: add __exfat_get_dentry_set() helper yuezhang.mo
2023-12-22  5:05   ` Namjae Jeon
2023-12-08 11:23 ` yuezhang.mo [this message]
2023-12-08 11:23 ` [PATCH v1 03/11] exfat: covert exfat_find_empty_entry() to use dentry cache yuezhang.mo
2023-12-08 11:23 ` [PATCH v1 04/11] exfat: covert exfat_add_entry() " yuezhang.mo
2023-12-08 11:23 ` [PATCH v1 05/11] exfat: covert exfat_remove_entries() " yuezhang.mo
2023-12-22  5:07   ` Namjae Jeon
2023-12-08 11:23 ` [PATCH v1 06/11] exfat: move free cluster out of exfat_init_ext_entry() yuezhang.mo
2023-12-08 11:23 ` [PATCH v1 07/11] exfat: covert exfat_init_ext_entry() to use dentry cache yuezhang.mo
2023-12-08 11:23 ` [PATCH v1 08/11] exfat: remove __exfat_find_empty_entry() yuezhang.mo
2023-12-22  5:07   ` Namjae Jeon
2023-12-08 11:23 ` [PATCH v1 09/11] exfat: remove unused functions yuezhang.mo
2023-12-08 11:23 ` [PATCH v1 10/11] exfat: do not sync parent dir if just update timestamp yuezhang.mo
2023-12-22  5:08   ` Namjae Jeon
2023-12-24 14:58     ` Yuezhang.Mo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_ACDA02351A05A74A2E0CA9617EC5E960E208@qq.com \
    --to=yuezhang.mo@foxmail.com \
    --cc=Andy.Wu@sony.com \
    --cc=Yuezhang.Mo@sony.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=sj1557.seo@samsung.com \
    --cc=wataru.aoyama@sony.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.