From: Tao Ma <tm@tao.ma>
To: linux-ext4@vger.kernel.org
Cc: tytso@mit.edu, linux-kernel@vger.kernel.org, adilger@dilger.ca
Subject: [PATCH V1 11/17] ext4: Let ext4_readdir handle inline data.
Date: Wed, 26 Oct 2011 15:34:22 +0800 [thread overview]
Message-ID: <1319614468-11227-11-git-send-email-tm@tao.ma> (raw)
In-Reply-To: <1319614468-11227-1-git-send-email-tm@tao.ma>
From: Tao Ma <boyu.mt@taobao.com>
Signed-off-by: Tao Ma <boyu.mt@taobao.com>
---
fs/ext4/dir.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 101 insertions(+), 0 deletions(-)
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index 6c2199e..8b88cfa 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -27,6 +27,7 @@
#include <linux/slab.h>
#include <linux/rbtree.h>
#include "ext4.h"
+#include "xattr.h"
static unsigned char ext4_filetype_table[] = {
DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK
@@ -64,6 +65,9 @@ static unsigned char get_dtype(struct super_block *sb, int filetype)
* Return 0 if the directory entry is OK, and 1 if there is a problem
*
* Note: this is the opposite of what ext2 and ext3 historically returned...
+ *
+ * bh passed here can be an inode block or a dir data block, depending
+ * on the inode inline data flag.
*/
int __ext4_check_dir_entry(const char *function, unsigned int line,
struct inode *dir, struct file *filp,
@@ -107,6 +111,100 @@ int __ext4_check_dir_entry(const char *function, unsigned int line,
return 1;
}
+static int ext4_read_inline_dir(struct file *filp,
+ void *dirent, filldir_t filldir)
+{
+ int error = 0;
+ unsigned int offset;
+ int i, stored;
+ struct ext4_dir_entry_2 *de;
+ struct super_block *sb;
+ struct inode *inode = filp->f_path.dentry->d_inode;
+ int ret, inline_size;
+ void *inline_pos;
+ struct ext4_iloc iloc;
+
+ ret = ext4_get_inode_loc(inode, &iloc);
+ if (ret)
+ return ret;
+
+ sb = inode->i_sb;
+ stored = 0;
+ offset = filp->f_pos & (sb->s_blocksize - 1);
+ inline_pos = ext4_get_inline_data_pos(inode, &iloc);
+ inline_size = ext4_get_max_inline_size(inode);
+
+ ext4_show_inline_dir(inode, iloc.bh, inline_pos, inline_size);
+
+ while (!error && !stored && filp->f_pos < inode->i_size) {
+revalidate:
+ /* If the version has changed since the last call to
+ * readdir(2), then we might be pointing to an invalid
+ * dirent right now. Scan from the start of the block
+ * to make sure. */
+ if (filp->f_version != inode->i_version) {
+ for (i = 0; i < inode->i_size && i < offset; ) {
+ de = (struct ext4_dir_entry_2 *)
+ (inline_pos + i);
+ /* It's too expensive to do a full
+ * dirent test each time round this
+ * loop, but we do have to test at
+ * least that it is non-zero. A
+ * failure will be detected in the
+ * dirent test below. */
+ if (ext4_rec_len_from_disk(de->rec_len,
+ inline_size) < EXT4_DIR_REC_LEN(1))
+ break;
+ i += ext4_rec_len_from_disk(de->rec_len,
+ inline_size);
+ }
+ offset = i;
+ filp->f_pos = offset;
+ filp->f_version = inode->i_version;
+ }
+
+ while (!error && filp->f_pos < inode->i_size
+ && offset < inline_size) {
+ de = (struct ext4_dir_entry_2 *) (inline_pos + offset);
+ if (ext4_check_dir_entry(inode, filp, de,
+ iloc.bh, inline_pos,
+ inline_size, offset)) {
+ ret = stored;
+ goto out;
+ }
+ offset += ext4_rec_len_from_disk(de->rec_len,
+ inline_size);
+ if (le32_to_cpu(de->inode)) {
+ /* We might block in the next section
+ * if the data destination is
+ * currently swapped out. So, use a
+ * version stamp to detect whether or
+ * not the directory has been modified
+ * during the copy operation.
+ */
+ u64 version = filp->f_version;
+
+ error = filldir(dirent, de->name,
+ de->name_len,
+ filp->f_pos,
+ le32_to_cpu(de->inode),
+ get_dtype(sb, de->file_type));
+ if (error)
+ break;
+ if (version != filp->f_version)
+ goto revalidate;
+ stored++;
+ }
+ filp->f_pos += ext4_rec_len_from_disk(de->rec_len,
+ inline_size);
+ }
+ offset = 0;
+ }
+out:
+ brelse(iloc.bh);
+ return ret;
+}
+
static int ext4_readdir(struct file *filp,
void *dirent, filldir_t filldir)
{
@@ -122,6 +220,9 @@ static int ext4_readdir(struct file *filp,
sb = inode->i_sb;
+ if (ext4_has_inline_data(inode))
+ return ext4_read_inline_dir(filp, dirent, filldir);
+
if (EXT4_HAS_COMPAT_FEATURE(inode->i_sb,
EXT4_FEATURE_COMPAT_DIR_INDEX) &&
((ext4_test_inode_flag(inode, EXT4_INODE_INDEX)) ||
--
1.7.0.4
next prev parent reply other threads:[~2011-10-26 7:41 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-26 7:32 [PATCH V1 00/17] ext4: Add inline data support Tao Ma
2011-10-26 7:34 ` [PATCH V1 01/17] ext4: Move extra inode read to a new function Tao Ma
2011-10-26 7:34 ` [PATCH V1 02/17] ext4: Add the basic function for inline data support Tao Ma
2011-10-26 8:36 ` Andreas Dilger
2011-10-26 14:38 ` Tao Ma
2011-10-26 22:28 ` Andreas Dilger
2011-10-27 0:51 ` Tao Ma
2011-10-27 0:51 ` Tao Ma
2011-10-27 9:57 ` Andreas Dilger
2011-10-27 14:53 ` Tao Ma
2011-11-02 21:16 ` Andreas Dilger
2011-11-03 4:23 ` Tao Ma
2011-10-26 7:34 ` [PATCH V1 03/17] ext4: Add read support for inline data Tao Ma
2011-10-26 7:34 ` [PATCH V1 04/17] ext4: Add normal write " Tao Ma
2011-10-26 7:34 ` [PATCH V1 05/17] ext4: Add journalled " Tao Ma
2011-10-26 7:34 ` [PATCH V1 06/17] ext4: Add delalloc " Tao Ma
2011-10-26 7:34 ` [PATCH V1 07/17] ext4: Create a new function ext4_init_new_dir Tao Ma
2011-10-26 7:34 ` [PATCH V1 08/17] ext4: Refactor __ext4_check_dir_entry to accepts start and size Tao Ma
2011-10-26 7:34 ` [PATCH V1 09/17] ext4: Create __ext4_insert_dentry for dir entry insertion Tao Ma
2011-10-26 7:34 ` [PATCH V1 10/17] ext4: let add_dir_entry handle inline data properly Tao Ma
2011-10-26 7:34 ` Tao Ma [this message]
2011-10-26 7:34 ` [PATCH V1 12/17] ext4: Create a new function search_dir Tao Ma
2011-10-26 7:34 ` [PATCH V1 13/17] ext4: let ext4_find_entry handle inline data Tao Ma
2011-10-26 7:34 ` [PATCH V1 14/17] ext4: let ext4_delete_entry " Tao Ma
2011-10-26 7:34 ` [PATCH V1 15/17] ext4: let empty_dir handle inline dir Tao Ma
2011-10-26 7:34 ` [PATCH V1 16/17] ext4: let ext4_rename " Tao Ma
2011-10-26 7:34 ` [PATCH V1 17/17] ext4: Enable ext4 inline support Tao Ma
[not found] ` <CAOQ4uxgpkd5WwwwkuxTupYRS-2Nf7mu=V5JCO2CTYQN3k0BCCg@mail.gmail.com>
2011-10-26 8:17 ` [PATCH V1 00/17] ext4: Add inline data support Tao Ma
2011-10-27 7:10 ` Valdis.Kletnieks
2011-10-27 13:54 ` Tao Ma
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=1319614468-11227-11-git-send-email-tm@tao.ma \
--to=tm@tao.ma \
--cc=adilger@dilger.ca \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tytso@mit.edu \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).