ocfs2: Directory indexing support
cover ocfs2: Directory indexing support
The following patches implement indexed directory support in Ocfs2, mostly according to the design doc I wrote up a while ago:
http://oss.oracle.com/osswiki/OCFS2/DesignDocs/IndexedDirectories
The patches have been rebased on top of 2.6.29-rc2. It should be trivial to put them into merge_window. Things are what I'd call complete now. I'd like to get these into the merge_window branch sooner rather than later, so any reviews are appreciated :)
Changes from last time:
- Added inline indexing support. This turned out to be a good idea - many directories just keep their index inlined.
- Rebased so it fully complies with metaecc and quota requirements.
- Lots of bugs fixed.
There's a 'dx_dirs' branch in ocfs2.git:
git pull git://git.kernel.org/pub/scm/linux/kernel/git/mfasheh/ocfs2.git dx_dirs
I've tested this batch of patches with kernel builds, and various bash loops to create large numbers of files. Last time around, it survived a two day exorcist run. I'll schedule another one for the weekend.
Tools support for this is available in ocfs2-tools.git:
git pull git://oss.oracle.com/git/ocfs2-tools.git dx_dirs
I won't post the exact tools patches just yet. There's enough support in there that we can mkfs, tunefs (only turning the feature on) and debugfs. I need to add better write support and of course things like fsck, etc. The good news is tha the debugfs.ocfs2 support is what I'd call complete - it should allow us to fully debug and visualize the on-disk structures in question.
--Mark
--
Mark Fasheh
PATCH 1/7 ocfs2: Introduce dir lookup helper struct
Many directory manipulation calls pass around a tuple of dirent, and it's containing buffer_head. Dir indexing has a bit more state, but instead of adding yet more arguments to functions, we introduce 'struct ocfs2_dir_lookup_result'. In this patch, it simply holds the same tuple, but future patches will add more state.
--- fs/ocfs2/dir.c | 99 +++++++++++++++++++---------------- fs/ocfs2/dir.h | 30 ++++++----- fs/ocfs2/namei.c | 150 ++++++++++++++++++++++++++++-------------------------- 3 files changed, 148 insertions(+), 131 deletions(-)
fs/ocfs2/dir.c +54 -45
@@ -152,6 +152,11 @@ static void ocfs2_init_dir_trailer(struct inode *inode, trailer->db_blkno =cpu_to_le64 (bh->b_blocknr); } +void ocfs2_free_dir_lookup_result (struct ocfs2_dir_lookup_result *res) +{ +brelse (res->dl_leaf_bh); +} +/* * bh passed here can be an inode block or a dir data block, depending * on the inode inline data flag.
@@ -483,36 +488,46 @@ cleanup_and_exit:/* * Try to find an entry of the provided name within 'dir'. * -* If nothing was found, NULL is returned. Otherwise, a buffer_head -* and pointer to the dir entry are passed back. +* If nothing was found, -ENOENT is returned. Otherwise, zero is +* returned and the struct 'res' will contain information useful to +* other directory manipulation functions. * * Caller can NOT assume anything about the contents of the -* buffer_head - it is passed back only so that it can be passed into +* buffer_heads - they are passed back only so that it can be passed into * any one of the manipulation functions (add entry, delete entry, * etc). As an example, bh in the extent directory case is a data * block, in the inline-data case it actually points to an inode. */ -struct buffer_head *ocfs2_find_entry (const char *name,int namelen, -struct inode *dir, -struct ocfs2_dir_entry **res_dir) +int ocfs2_find_entry (const char *name,int namelen, +struct inode *dir,struct ocfs2_dir_lookup_result *lookup) { - *res_dir =NULL ; +struct buffer_head *bh; +struct ocfs2_dir_entry *res_dir =NULL ;if (OCFS2_I (dir)->ip_dyn_features &OCFS2_INLINE_DATA_FL ) -return ocfs2_find_entry_id (name, namelen, dir, res_dir); + bh =ocfs2_find_entry_id (name, namelen, dir, &res_dir); +else + bh =ocfs2_find_entry_el (name, namelen, dir, &res_dir); -return ocfs2_find_entry_el (name, namelen, dir, res_dir); +if (bh ==NULL ) +return -ENOENT ; + + lookup->dl_leaf_bh = bh; + lookup->dl_entry = res_dir; +return 0 ; }/* * Update inode number and type of a previously found directory entry. */ int ocfs2_update_entry (struct inode *dir,handle_t *handle, -struct buffer_head *de_bh,struct ocfs2_dir_entry *de, +struct ocfs2_dir_lookup_result *res,struct inode *new_entry_inode) {int ret;ocfs2_journal_access_func access = ocfs2_journal_access_db; +struct ocfs2_dir_entry *de = res->dl_entry; +struct buffer_head *de_bh = res->dl_leaf_bh;/* * The same code works fine for both inline-data and extent
@@ -629,13 +644,14 @@ static inline int ocfs2_delete_entry_el(handle_t *handle,*/ int ocfs2_delete_entry (handle_t *handle,struct inode *dir, -struct ocfs2_dir_entry *de_del, -struct buffer_head *bh) +struct ocfs2_dir_lookup_result *res) {if (OCFS2_I (dir)->ip_dyn_features &OCFS2_INLINE_DATA_FL ) -return ocfs2_delete_entry_id (handle, dir, de_del, bh); +return ocfs2_delete_entry_id (handle, dir, res->dl_entry, + res->dl_leaf_bh); -return ocfs2_delete_entry_el (handle, dir, de_del, bh); +return ocfs2_delete_entry_el (handle, dir, res->dl_entry, + res->dl_leaf_bh); }/*
@@ -666,15 +682,15 @@ static inline int ocfs2_dirent_would_fit(struct ocfs2_dir_entry *de,/* we don't always have a dentry for what we want to add, so people * like orphan dir can call this instead. * -* If you pass me insert_bh, I'll skip the search of the other dir -* blocks and put the record in there. +* The lookup context must have been filled from +* ocfs2_prepare_dir_for_insert. */ int __ocfs2_add_entry (handle_t *handle,struct inode *dir,const char *name,int namelen,struct inode *inode,u64 blkno,struct buffer_head *parent_fe_bh, -struct buffer_head *insert_bh) +struct ocfs2_dir_lookup_result *lookup) {unsigned long offset;unsigned short rec_len;
@@ -683,6 +699,7 @@ int __ocfs2_add_entry(handle_t *handle,struct super_block *sb = dir->i_sb;int retval, status;unsigned int size = sb->s_blocksize; +struct buffer_head *insert_bh = lookup->dl_leaf_bh;char *data_start = insert_bh->b_data;mlog_entry_void ();
@@ -1071,31 +1088,22 @@ int ocfs2_find_files_on_disk(const char *name,int namelen, u64 *blkno, struct inode *inode, - struct buffer_head **dirent_bh, - struct ocfs2_dir_entry **dirent) + struct ocfs2_dir_lookup_result *lookup) { int status = -ENOENT; -mlog_entry ("(name=%.*s, blkno=%p, inode=%p, dirent_bh=%p, dirent=%p)\n" , - namelen, name, blkno, inode, dirent_bh, dirent); +mlog (0 ,"name=%.*s, blkno=%p, inode=%llu\n" , namelen, name, blkno, + (unsigned long long )OCFS2_I (inode)->ip_blkno); - *dirent_bh =ocfs2_find_entry (name, namelen, inode, dirent); -if (!*dirent_bh || !*dirent) { - status = -ENOENT ; + status =ocfs2_find_entry (name, namelen, inode, lookup); +if (status) goto leave; - } - *blkno =le64_to_cpu ((*dirent)->inode); + *blkno =le64_to_cpu (lookup->dl_entry->inode); status =0 ; leave: -if (status <0 ) { - *dirent =NULL ; -brelse (*dirent_bh); - *dirent_bh =NULL ; - } -mlog_exit (status);return status; }
@@ -1107,11 +1115,10 @@ int ocfs2_lookup_ino_from_name(struct inode *dir, const char *name, int namelen, u64 *blkno) { int ret; -struct buffer_head *bh =NULL ; -struct ocfs2_dir_entry *dirent =NULL ; +struct ocfs2_dir_lookup_result lookup = {NULL , }; - ret =ocfs2_find_files_on_disk (name, namelen, blkno, dir, &bh, &dirent); -brelse (bh); + ret =ocfs2_find_files_on_disk (name, namelen, blkno, dir, &lookup); +ocfs2_free_dir_lookup_result (&lookup);return ret; }
@@ -1128,20 +1135,18 @@ int ocfs2_check_dir_for_entry(struct inode *dir, int namelen) {int ret; -struct buffer_head *dirent_bh =NULL ; -struct ocfs2_dir_entry *dirent =NULL ; +struct ocfs2_dir_lookup_result lookup = {NULL , };mlog_entry ("dir %llu, name '%.*s'\n" , (unsigned long long )OCFS2_I (dir)->ip_blkno, namelen, name); ret = -EEXIST ; - dirent_bh =ocfs2_find_entry (name, namelen, dir, &dirent); -if (dirent_bh) +if (ocfs2_find_entry (name, namelen, dir, &lookup) ==0 ) goto bail; ret =0 ; bail: -brelse (dirent_bh); +ocfs2_free_dir_lookup_result (&lookup);mlog_exit (ret);return ret;
@@ -1970,12 +1975,18 @@ bail:return status; } +/* +* Get a directory ready for insert. Any directory allocation required +* happens here. Success returns zero, and enough context in the dir +* lookup result that ocfs2_add_entry() will be able complete the task +* with minimal performance impact. +*/ int ocfs2_prepare_dir_for_insert (struct ocfs2_super *osb,struct inode *dir,struct buffer_head *parent_fe_bh,const char *name,int namelen, -struct buffer_head **ret_de_bh) +struct ocfs2_dir_lookup_result *lookup) {int ret;unsigned int blocks_wanted =1 ;
@@ -1984,8 +1995,6 @@ int ocfs2_prepare_dir_for_insert(struct ocfs2_super *osb,mlog (0 ,"getting ready to insert namelen %d into dir %llu\n" , namelen, (unsigned long long )OCFS2_I (dir)->ip_blkno); - *ret_de_bh =NULL ; -if (!namelen) { ret = -EINVAL ;mlog_errno (ret);
@@ -2020,7 +2029,7 @@ int ocfs2_prepare_dir_for_insert(struct ocfs2_super *osb,BUG_ON (!bh); } - *ret_de_bh = bh; + lookup->dl_leaf_bh = bh; bh =NULL ; out:brelse (bh);
fs/ocfs2/dir.h +17 -13
@@ -26,44 +26,48 @@#ifndef OCFS2_DIR_H #define OCFS2_DIR_H -struct buffer_head *ocfs2_find_entry (const char *name, -int namelen, -struct inode *dir, -struct ocfs2_dir_entry **res_dir); +struct ocfs2_dir_lookup_result { +struct buffer_head *dl_leaf_bh; +struct ocfs2_dir_entry *dl_entry; +}; +void ocfs2_free_dir_lookup_result (struct ocfs2_dir_lookup_result *res); + +int ocfs2_find_entry (const char *name,int namelen, +struct inode *dir, +struct ocfs2_dir_lookup_result *lookup);int ocfs2_delete_entry (handle_t *handle,struct inode *dir, -struct ocfs2_dir_entry *de_del, -struct buffer_head *bh); +struct ocfs2_dir_lookup_result *res);int __ocfs2_add_entry (handle_t *handle,struct inode *dir,const char *name,int namelen,struct inode *inode,u64 blkno,struct buffer_head *parent_fe_bh, -struct buffer_head *insert_bh); +struct ocfs2_dir_lookup_result *lookup);static inline int ocfs2_add_entry (handle_t *handle,struct dentry *dentry,struct inode *inode,u64 blkno,struct buffer_head *parent_fe_bh, -struct buffer_head *insert_bh) +struct ocfs2_dir_lookup_result *lookup) {return __ocfs2_add_entry (handle, dentry->d_parent->d_inode, dentry->d_name.name, dentry->d_name.len, - inode, blkno, parent_fe_bh, insert_bh); + inode, blkno, parent_fe_bh, lookup); }int ocfs2_update_entry (struct inode *dir,handle_t *handle, -struct buffer_head *de_bh,struct ocfs2_dir_entry *de, +struct ocfs2_dir_lookup_result *res,struct inode *new_entry_inode);int ocfs2_check_dir_for_entry (struct inode *dir,const char *name,int namelen);int ocfs2_empty_dir (struct inode *inode); +int ocfs2_find_files_on_disk (const char *name,int namelen,u64 *blkno,struct inode *inode, -struct buffer_head **dirent_bh, -struct ocfs2_dir_entry **dirent); +struct ocfs2_dir_lookup_result *res);int ocfs2_lookup_ino_from_name (struct inode *dir,const char *name,int namelen,u64 *blkno);int ocfs2_readdir (struct file *filp,void *dirent,filldir_t filldir);
@@ -74,7 +78,7 @@ int ocfs2_prepare_dir_for_insert(struct ocfs2_super *osb,struct buffer_head *parent_fe_bh, const char *name, int namelen, - struct buffer_head **ret_de_bh); + struct ocfs2_dir_lookup_result *lookup);struct ocfs2_alloc_context ; int ocfs2_fill_new_dir(struct ocfs2_super *osb, handle_t *handle,
fs/ocfs2/namei.c +77 -73
448 lines not on this page · raw message
Signature · 1 line
1.5.6
PATCH 1/7 ocfs2: Introduce dir lookup helper struct
Quoted 7 lines · Mark Fasheh
Many directory manipulation calls pass around a tuple of dirent, and it's containing
buffer_head. Dir indexing has a bit more state, but instead of adding yet more arguments to functions, we introduce 'structocfs2_dir_lookup_result'. In this patch, it simply holds the same tuple, but future patches will add more state.Signed-off-by Mark Fasheh <[email protected]>
I really like this.
(I wish it didn't explode the stack of ocfs2_rename(), but, well, it's rename).
Signature · 9 lines
Life's Little Instruction Book #306 "Take a nap on Sunday afternoons." Joel Becker Principal Software Developer Oracle E-mail: joel.becker at oracle.com Phone: (650) 506-8127
PATCH 2/7 ocfs2: Add a name indexed b-tree to directory inodes
In reply to Mark FashehThis patch makes use of Ocfs2's flexible btree code to add an additional tree to directory inodes. The new tree stores an array of small, fixed-length records in each leaf block. Each record stores a hash value, and pointer to a block in the traditional (unindexed) directory tree where a dirent with the given name hash resides. Lookup exclusively uses this tree to find dirents, thus providing us with constant time name lookups.
Some of the hashing code was copied from ext3. Unfortunately, it has lots of unfixed checkpatch errors. I left that as-is so that tracking changes would be easier.
--- fs/ocfs2/alloc.c | 57 ++ fs/ocfs2/alloc.h | 3 + fs/ocfs2/dir.c | 1906 +++++++++++++++++++++++++++++++++++++++++++++++++-- fs/ocfs2/dir.h | 21 +- fs/ocfs2/inode.c | 12 +- fs/ocfs2/journal.c | 30 + fs/ocfs2/journal.h | 51 +- fs/ocfs2/namei.c | 45 +- fs/ocfs2/ocfs2.h | 16 + fs/ocfs2/ocfs2_fs.h | 102 +++- fs/ocfs2/super.c | 6 + fs/ocfs2/xattr.c | 8 +- fs/ocfs2/xattr.h | 2 +- 13 files changed, 2155 insertions(+), 104 deletions(-)
fs/ocfs2/alloc.c +57 -0
@@ -293,6 +293,55 @@ static struct ocfs2_extent_tree_operations ocfs2_xattr_tree_et_ops = { .eo_fill_max_leaf_clusters = ocfs2_xattr_tree_fill_max_leaf_clusters, }; +static void ocfs2_dx_root_set_last_eb_blk (struct ocfs2_extent_tree *et, +u64 blkno) +{ +struct ocfs2_dx_root_block *dx_root = et->et_object; + + dx_root->dr_last_eb_blk =cpu_to_le64 (blkno); +} + +static u64 ocfs2_dx_root_get_last_eb_blk (struct ocfs2_extent_tree *et) +{ +struct ocfs2_dx_root_block *dx_root = et->et_object; + +return le64_to_cpu (dx_root->dr_last_eb_blk); +} + +static void ocfs2_dx_root_update_clusters (struct inode *inode, +struct ocfs2_extent_tree *et, +u32 clusters) +{ +struct ocfs2_dx_root_block *dx_root = et->et_object; + +le32_add_cpu (&dx_root->dr_clusters, clusters); +} + +static int ocfs2_dx_root_sanity_check (struct inode *inode, +struct ocfs2_extent_tree *et) +{ +struct ocfs2_dx_root_block *dx_root = et->et_object; + +BUG_ON (!OCFS2_IS_VALID_DX_ROOT (dx_root)); + +return 0 ; +} + +static void ocfs2_dx_root_fill_root_el (struct ocfs2_extent_tree *et) +{ +struct ocfs2_dx_root_block *dx_root = et->et_object; + + et->et_root_el = &dx_root->dr_list; +} + +static struct ocfs2_extent_tree_operations ocfs2_dx_root_et_ops = { + .eo_set_last_eb_blk = ocfs2_dx_root_set_last_eb_blk, + .eo_get_last_eb_blk = ocfs2_dx_root_get_last_eb_blk, + .eo_update_clusters = ocfs2_dx_root_update_clusters, + .eo_sanity_check = ocfs2_dx_root_sanity_check, + .eo_fill_root_el = ocfs2_dx_root_fill_root_el, +}; + static void __ocfs2_init_extent_tree(struct ocfs2_extent_tree *et, struct inode *inode, struct buffer_head *bh,
@@ -338,6 +387,14 @@ void ocfs2_init_xattr_value_extent_tree(struct ocfs2_extent_tree *et, &ocfs2_xattr_value_et_ops); } +void ocfs2_init_dx_root_extent_tree (struct ocfs2_extent_tree *et, +struct inode *inode, +struct buffer_head *bh) +{ +__ocfs2_init_extent_tree (et, inode, bh, ocfs2_journal_access_dr, +NULL , &ocfs2_dx_root_et_ops); +} +static inline void ocfs2_et_set_last_eb_blk (struct ocfs2_extent_tree *et,u64 new_last_eb_blk) {
fs/ocfs2/alloc.h +3 -0
@@ -75,6 +75,9 @@ struct ocfs2_xattr_value_buf;void ocfs2_init_xattr_value_extent_tree (struct ocfs2_extent_tree *et,struct inode *inode,struct ocfs2_xattr_value_buf *vb); +void ocfs2_init_dx_root_extent_tree (struct ocfs2_extent_tree *et, +struct inode *inode, +struct buffer_head *bh);/* * Read an extent block into *bh. If *bh is NULL, a bh will be
fs/ocfs2/dir.c +1843 -63
2,164 lines not on this page · raw message
fs/ocfs2/dir.h +18 -3
@@ -26,9 +26,21 @@#ifndef OCFS2_DIR_H #define OCFS2_DIR_H +struct ocfs2_dx_hinfo { +u32 major_hash; +u32 minor_hash; +}; +struct ocfs2_dir_lookup_result { -struct buffer_head *dl_leaf_bh; -struct ocfs2_dir_entry *dl_entry; +struct buffer_head *dl_leaf_bh;/* Unindexed leaf +* block */ +struct ocfs2_dir_entry *dl_entry;/* Target dirent in +* unindexed leaf */ + +struct buffer_head *dl_dx_leaf_bh;/* Indexed leaf block */ +struct ocfs2_dx_entry *dl_dx_entry;/* Target dx_entry in +* indexed leaf */ +struct ocfs2_dx_hinfo dl_hinfo;/* Name hash results */ };void ocfs2_free_dir_lookup_result (struct ocfs2_dir_lookup_result *res);
@@ -85,7 +97,10 @@ int ocfs2_fill_new_dir(struct ocfs2_super *osb,struct inode *parent, struct inode *inode, struct buffer_head *fe_bh, - struct ocfs2_alloc_context *data_ac); + struct ocfs2_alloc_context *data_ac, + struct ocfs2_alloc_context *meta_ac); + +int ocfs2_dx_dir_truncate (struct inode *dir,struct buffer_head *di_bh);struct ocfs2_dir_block_trailer *ocfs2_dir_trailer_from_size (int blocksize,void *data);
fs/ocfs2/inode.c +11 -1
@@ -38,6 +38,7 @@#include "ocfs2.h" #include "alloc.h" +#include "dir.h" #include "blockcheck.h" #include "dlmglue.h" #include "extent_map.h"
@@ -606,7 +607,7 @@ static int ocfs2_remove_inode(struct inode *inode, } handle =ocfs2_start_trans (osb,OCFS2_DELETE_INODE_CREDITS + -ocfs2_quota_trans_credits (inode->i_sb)); +ocfs2_quota_trans_credits (inode->i_sb));if (IS_ERR (handle)) { status =PTR_ERR (handle);mlog_errno (status);
@@ -740,6 +741,15 @@ static int ocfs2_wipe_inode(struct inode *inode, goto bail_unlock_dir; } +/* Remove any dir index tree */ +if (S_ISDIR (inode->i_mode)) { + status =ocfs2_dx_dir_truncate (inode, di_bh); +if (status) { +mlog_errno (status); + goto bail_unlock_dir; + } + } +/*Free extended attribute resources associated with this inode.*/ status =ocfs2_xattr_remove (inode, di_bh);if (status <0 ) {
fs/ocfs2/journal.c +30 -0
@@ -496,6 +496,22 @@ static struct ocfs2_triggers dq_triggers = { }, }; +static struct ocfs2_triggers dr_triggers = { + .ot_triggers = { + .t_commit = ocfs2_commit_trigger, + .t_abort = ocfs2_abort_trigger, + }, + .ot_offset = offsetof(struct ocfs2_dx_root_block , dr_check), +}; + +static struct ocfs2_triggers dl_triggers = { + .ot_triggers = { + .t_commit = ocfs2_commit_trigger, + .t_abort = ocfs2_abort_trigger, + }, + .ot_offset = offsetof(struct ocfs2_dx_leaf , dl_check), +}; + static int __ocfs2_journal_access(handle_t *handle, struct inode *inode, struct buffer_head *bh,
@@ -600,6 +616,20 @@ int ocfs2_journal_access_dq(handle_t *handle, struct inode *inode, type); } +int ocfs2_journal_access_dr (handle_t *handle,struct inode *inode, +struct buffer_head *bh,int type) +{ +return __ocfs2_journal_access (handle, inode, bh, &dr_triggers, + type); +} + +int ocfs2_journal_access_dl (handle_t *handle,struct inode *inode, +struct buffer_head *bh,int type) +{ +return __ocfs2_journal_access (handle, inode, bh, &dl_triggers, + type); +} +int ocfs2_journal_access (handle_t *handle,struct inode *inode,struct buffer_head *bh,int type) {
fs/ocfs2/journal.h +38 -13
99 lines not on this page · raw message
fs/ocfs2/namei.c +31 -14
110 lines not on this page · raw message
fs/ocfs2/ocfs2.h +16 -0
@@ -335,6 +335,9 @@ struct ocfs2_superstruct ocfs2_node_map osb_recovering_orphan_dirs;unsigned int *osb_orphan_wipes;wait_queue_head_t osb_wipe_event; + +unsigned int osb_dx_mask; +u32 osb_dx_seed[4 ]; };#define OCFS2_SB (sb) ((struct ocfs2_super *)(sb)->s_fs_info)
@@ -393,6 +396,13 @@ static inline int ocfs2_meta_ecc(struct ocfs2_super *osb)return 0 ; } +static inline int ocfs2_supports_indexed_dirs (struct ocfs2_super *osb) +{ +if (osb->s_feature_incompat &OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS ) +return 1 ; +return 0 ; +} +/* set / clear functions because cluster events can make these happen * in parallel so we want the transitions to be atomic. this also * means that any future flags osb_flags must be protected by spinlock
@@ -473,6 +483,12 @@ static inline int ocfs2_uses_extended_slot_map(struct ocfs2_super *osb)#define OCFS2_IS_VALID_DIR_TRAILER (ptr) \ (!strcmp((ptr)->db_signature, OCFS2_DIR_TRAILER_SIGNATURE)) +#define OCFS2_IS_VALID_DX_ROOT (ptr) \ + (!strcmp((ptr)->dr_signature, OCFS2_DX_ROOT_SIGNATURE)) + +#define OCFS2_IS_VALID_DX_LEAF (ptr) \ + (!strcmp((ptr)->dl_signature, OCFS2_DX_LEAF_SIGNATURE)) +static inline unsigned long ino_from_blkno (struct super_block *sb,u64 blkno) {
fs/ocfs2/ocfs2_fs.h +99 -3
144 lines not on this page · raw message
fs/ocfs2/super.c +6 -0
@@ -1735,6 +1735,12 @@ static int ocfs2_initialize_super(struct super_block *sb, bbits =le32_to_cpu (di->id2.i_super.s_blocksize_bits); sb->s_maxbytes =ocfs2_max_file_offset (bbits, cbits); + osb->osb_dx_mask = (1 << (cbits - bbits)) -1 ; + +for (i =0 ; i <3 ; i++) + osb->osb_dx_seed[i] =le32_to_cpu (di->id2.i_super.s_dx_seed[i]); + osb->osb_dx_seed[3 ] =le32_to_cpu (di->id2.i_super.s_uuid_hash); + osb->sb = sb;/* Save off for ocfs2_rw_direct */ osb->s_sectsize_bits =blksize_bits (sector_size);
fs/ocfs2/xattr.c +2 -6
@@ -507,7 +507,7 @@ int ocfs2_calc_xattr_init(struct inode *dir,struct ocfs2_security_xattr_info *si, int *want_clusters, int *xattr_credits, - struct ocfs2_alloc_context **xattr_ac) + int *want_meta) { int ret = 0;struct ocfs2_super *osb =OCFS2_SB (dir->i_sb);
@@ -545,11 +545,7 @@ int ocfs2_calc_xattr_init(struct inode *dir,*/ if (dir->i_sb->s_blocksize ==OCFS2_MIN_BLOCKSIZE || (s_size + a_size) >OCFS2_XATTR_FREE_IN_IBODY ) { - ret =ocfs2_reserve_new_metadata_blocks (osb,1 , xattr_ac); -if (ret) { -mlog_errno (ret); -return ret; - } + *want_meta = *want_meta +1 ; *xattr_credits +=OCFS2_XATTR_BLOCK_CREATE_CREDITS ; }
fs/ocfs2/xattr.h +1 -1
@@ -68,7 +68,7 @@ int ocfs2_calc_security_init(struct inode *, int *, int *, struct ocfs2_alloc_context **);int ocfs2_calc_xattr_init (struct inode *,struct buffer_head *,int ,struct ocfs2_security_xattr_info *, -int *,int *,struct ocfs2_alloc_context **); +int *,int *,int *);/* * xattrs can live inside an inode, as part of an external xattr block,
Signature · 1 line
1.5.6
PATCH 2/7 ocfs2: Add a name indexed b-tree to directory inodes
Quoted 7 lines · Mark Fasheh
This patch makes use of Ocfs2's flexible btree code to add an additional tree to directory inodes. The new tree stores an array of small, fixed-length records in each leaf block. Each record stores a hash value, and pointer to a block in the traditional (unindexed) directory tree where a dirent with the given name hash resides. Lookup exclusively uses this tree to find dirents, thus providing us with constant time name lookups.
Quoted 5 lines
Some of the hashing code was copied from ext3. Unfortunately, it has lots of unfixed checkpatch errors. I left that as-is so that tracking changes would be easier.
Signed-off-by Mark Fasheh <[email protected]>
Big patch to review. Whew! But overall it looks very good.
Comments inline.
Quoted 20 lines
fs/ocfs2/dir.c +20
-0+/* +* Read the block at 'phys' which belongs to this directory +* inode. This function does no virtual->physical block translation - +* what's passed in is assumed to be a valid directory block. +*/ +static int ocfs2_read_dir_block_direct (struct inode *dir,u64 phys, +struct buffer_head **bh) +{ +int ret; +struct buffer_head *tmp = *bh; + + ret =ocfs2_read_block (dir, phys, &tmp, ocfs2_validate_dir_block); +if (ret) { +mlog_errno (ret); + goto out; + } + + ret =ocfs2_check_dir_trailer (dir, tmp); +if (ret) { +if (!*bh)
fs/ocfs2/dir.c out: · line 528
Quoted 10 lines
fs/ocfs2/dir.c +10
-0+brelse (tmp); +mlog_errno (ret); + goto out; + } + +if (!ret && !*bh) + *bh = tmp; +out: +return ret; +}
I think you need the same guard check as ocfs2_read_dir_block():
if (!(flags & OCFS2_BH_READAHEAD) &&
ocfs2_dir_has_trailer(inode)) {because otherwise ocfs2_check_dir_trailer() will run unconditionally. I realize that the current code doesn't call ocfs2_read_dir_block_direct() except in the indexed case, but that's just for now.
Alternatively, you could BUG_ON(!ocfs2_dir_has_trailer()).
fs/ocfs2/dir.c static int ocfs2_empty_dir_filldir(void *priv, const char *name, int name_len, · line 1856
Quoted 9 lines
fs/ocfs2/dir.c +2
-0@@ -1184,6 +1849,8 @@ static int ocfs2_empty_dir_filldir(void *priv, const char *name, int name_len,* routine to check that the specified directory is empty (for rmdir) * * Returns 1 if dir is empty, zero otherwise. +* +* XXX: This is a performance problem */ int ocfs2_empty_dir (struct inode *inode) {
Why can't an indexed directory store the directory's child count
in the dx_root? That way we can just read the dx_root and ocfs2_empty_dir() gets much faster. You already have the dx_root in memory for all link/unlink operations anyway.
While we're at it, the two places that call ocfs2_empty_dir()
should reorder their checks. If they check (i_nlink != 2) first, they can skip calling ocfs2_empty_dir() altogether when i_nlink has a subdirectory.
Quoted 19 lines
fs/ocfs2/dir.c +6
-3@@ -1401,29 +2435,57 @@ static void ocfs2_expand_last_dirent(char *start, unsigned int old_size,*/ static int ocfs2_expand_inline_dir (struct inode *dir,struct buffer_head *di_bh,unsigned int blocks_wanted, +struct ocfs2_dir_lookup_result *lookup,struct buffer_head **first_block_bh) { -u32 alloc, bit_off, len; +u32 alloc, dx_alloc, bit_off, len;struct super_block *sb = dir->i_sb; -int ret, credits =ocfs2_inline_to_extents_credits (sb); -u64 blkno, bytes = blocks_wanted << sb->s_blocksize_bits; +int ret, i, num_dx_leaves =0 , + credits =ocfs2_inline_to_extents_credits (sb); +u64 dx_insert_blkno, blkno, + bytes = blocks_wanted << sb->s_blocksize_bits;struct ocfs2_super *osb =OCFS2_SB (dir->i_sb);struct ocfs2_inode_info *oi =OCFS2_I (dir);struct ocfs2_alloc_context *data_ac;
fs/ocfs2/dir.c static void ocfs2_expand_last_dirent(char *start, unsigned int old_size, · line 2458
Quoted 10 lines
fs/ocfs2/dir.c +5
-1+struct ocfs2_alloc_context *meta_ac =NULL ;struct buffer_head *dirdata_bh =NULL ; +struct buffer_head *dx_root_bh =NULL ; +struct buffer_head **dx_leaves =NULL ;struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data;handle_t *handle;struct ocfs2_extent_tree et; -int did_quota =0 ; +struct ocfs2_extent_tree dx_et; +int did_quota =0 , bytes_allocated =0 ;
Holy bejeezus we have a lot on the stack here? Can we factor
this function into a couple of subfunctions somewhere? That said, I don't think it's needed for the initial merge. So not right now.
fs/ocfs2/dir.c out: · line 3756
Quoted 5 lines
fs/ocfs2/dir.c +5
-0+int ocfs2_dx_dir_truncate (struct inode *dir,struct buffer_head *di_bh) +{ +int ret; +unsigned int uninitialized_var (clen ); +u32 major_hash =UINT_MAX , p_cpos,uninitialized_var (cpos );
I suppose I would have used U32_MAX instead of UINT_MAX, just to
match the u32 type, but in the end it is obviously the same value.
Joel
Signature · 9 lines
Life's Little Instruction Book #173 "Be kinder than necessary." Joel Becker Principal Software Developer Oracle E-mail: joel.becker at oracle.com Phone: (650) 506-8127
PATCH 3/7 ocfs2: Store dir index records inline
In reply to Mark FashehAllow us to store a small number of directory index records in the ocfs2_dx_root_block. This saves us a disk read on small to medium sized directories (less than about 250 entries). The inline root is automatically turned into a root block with extents if the directory size increases beyond it's capacity.
--- fs/ocfs2/dir.c | 574 ++++++++++++++++++++++++++++++++++++++------------- fs/ocfs2/dir.h | 2 + fs/ocfs2/journal.h | 10 + fs/ocfs2/namei.c | 4 +- fs/ocfs2/ocfs2_fs.h | 28 +++- 5 files changed, 469 insertions(+), 149 deletions(-)
fs/ocfs2/dir.c +432 -142
@@ -151,6 +151,7 @@ static void ocfs2_init_dir_trailer(struct inode *inode,void ocfs2_free_dir_lookup_result (struct ocfs2_dir_lookup_result *res) { +brelse (res->dl_dx_root_bh);brelse (res->dl_leaf_bh);brelse (res->dl_dx_leaf_bh); }
@@ -162,6 +163,11 @@ static int ocfs2_dir_indexed(struct inode *inode)return 0 ; } +static inline int ocfs2_dx_root_inline (struct ocfs2_dx_root_block *dx_root) +{ +return dx_root->dr_flags &OCFS2_DX_FLAG_INLINE ; +} +/* * Hashing code adapted from ext3 */
@@ -797,13 +803,18 @@ out:* Returns the block index, from the start of the cluster which this * hash belongs too. */ -static unsigned int ocfs2_dx_dir_hash_idx (struct ocfs2_super *osb, -struct ocfs2_dx_hinfo *hinfo) +static inline unsigned int __ocfs2_dx_dir_hash_idx (struct ocfs2_super *osb, +u32 minor_hash) { -u32 minor_hash = hinfo->minor_hash;return minor_hash & osb->osb_dx_mask; } +static inline unsigned int ocfs2_dx_dir_hash_idx (struct ocfs2_super *osb, +struct ocfs2_dx_hinfo *hinfo) +{ +return __ocfs2_dx_dir_hash_idx (osb, hinfo->minor_hash); +} + static int ocfs2_dx_dir_lookup(struct inode *inode, struct ocfs2_extent_list *el, struct ocfs2_dx_hinfo *hinfo,
@@ -853,7 +864,7 @@ out:static int ocfs2_dx_dir_search (const char *name,int namelen,struct inode *dir, -struct ocfs2_extent_list *dr_el, +struct ocfs2_dx_root_block *dx_root,struct ocfs2_dir_lookup_result *res) {int ret, i, found;
@@ -864,9 +875,18 @@ static int ocfs2_dx_dir_search(const char *name, int namelen,struct buffer_head *dir_ent_bh =NULL ;struct ocfs2_dir_entry *dir_ent =NULL ;struct ocfs2_dx_hinfo *hinfo = &res->dl_hinfo; +struct ocfs2_extent_list *dr_el; +struct ocfs2_dx_entry_list *entry_list;ocfs2_dx_dir_name_hash (dir, name, namelen, &res->dl_hinfo); +if (ocfs2_dx_root_inline (dx_root)) { + entry_list = &dx_root->dr_entries; + goto search; + } + + dr_el = &dx_root->dr_list; + ret =ocfs2_dx_dir_lookup (dir, dr_el, hinfo,NULL , &phys);if (ret) {mlog_errno (ret);
@@ -891,12 +911,15 @@ static int ocfs2_dx_dir_search(const char *name, int namelen,le16_to_cpu (dx_leaf->dl_list.de_num_used), le16_to_cpu(dx_leaf->dl_list.de_count)); + entry_list = &dx_leaf->dl_list; + +search:/* * Empty leaf is legal, so no need to check for that. */ found =0 ; -for (i =0 ; i <le16_to_cpu (dx_leaf->dl_list.de_num_used); i++) { - dx_entry = &dx_leaf->dl_list.de_entries[i]; +for (i =0 ; i <le16_to_cpu (entry_list->de_num_used); i++) { + dx_entry = &entry_list->de_entries[i];if (hinfo->major_hash !=le32_to_cpu (dx_entry->dx_major_hash) || hinfo->minor_hash !=le32_to_cpu (dx_entry->dx_minor_hash))
@@ -980,14 +1003,15 @@ static int ocfs2_find_entry_dx(const char *name, int namelen, } dx_root = (struct ocfs2_dx_root_block *) dx_root_bh->b_data; - ret =ocfs2_dx_dir_search (name, namelen, dir, &dx_root->dr_list, - lookup); + ret =ocfs2_dx_dir_search (name, namelen, dir, dx_root, lookup);if (ret) {if (ret != -ENOENT )mlog_errno (ret); goto out; } + lookup->dl_dx_root_bh = dx_root_bh; + dx_root_bh =NULL ; out:brelse (di_bh);brelse (dx_root_bh);
@@ -1124,64 +1148,88 @@ bail:return status; } -static void ocfs2_dx_leaf_remove_entry (struct ocfs2_dx_leaf *dx_leaf,int index) +static void ocfs2_dx_list_remove_entry (struct ocfs2_dx_entry_list *entry_list, +int index) { -struct ocfs2_dx_entry_list *dl_list = &dx_leaf->dl_list; -int num_used =le16_to_cpu (dl_list->de_num_used); +int num_used =le16_to_cpu (entry_list->de_num_used);if (num_used ==1 || index == (num_used -1 )) goto clear; -memmove (&dl_list->de_entries[index], &dl_list->de_entries[index +1 ], +memmove (&entry_list->de_entries[index], + &entry_list->de_entries[index +1 ], (num_used - index -1 )*sizeof (struct ocfs2_dx_entry )); clear: num_used--; -memset (&dl_list->de_entries[num_used],0 , +memset (&entry_list->de_entries[num_used],0 ,sizeof (struct ocfs2_dx_entry )); - dl_list->de_num_used =cpu_to_le16 (num_used); + entry_list->de_num_used =cpu_to_le16 (num_used); }static int ocfs2_delete_entry_dx (handle_t *handle,struct inode *dir,struct ocfs2_dir_lookup_result *lookup) {int ret, index; +struct buffer_head *dx_root_bh = lookup->dl_dx_root_bh;struct buffer_head *leaf_bh = lookup->dl_leaf_bh;struct ocfs2_dx_leaf *dx_leaf;struct ocfs2_dx_entry *dx_entry = lookup->dl_dx_entry; +struct ocfs2_dx_root_block *dx_root; +struct ocfs2_dx_entry_list *entry_list; + + dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data; +if (ocfs2_dx_root_inline (dx_root)) { + entry_list = &dx_root->dr_entries; + }else { + dx_leaf = (struct ocfs2_dx_leaf *) lookup->dl_dx_leaf_bh->b_data; + entry_list = &dx_leaf->dl_list; + } - dx_leaf = (struct ocfs2_dx_leaf *) lookup->dl_dx_leaf_bh->b_data;/* Neither of these are a disk corruption - that should have * been caught by lookup, before we got here. */ -BUG_ON (le16_to_cpu (dx_leaf->dl_list.de_count) <=0 ); -BUG_ON (le16_to_cpu (dx_leaf->dl_list.de_num_used) <=0 ); +BUG_ON (le16_to_cpu (entry_list->de_count) <=0 ); +BUG_ON (le16_to_cpu (entry_list->de_num_used) <=0 ); - index = (char *)dx_entry - (char *)dx_leaf->dl_list.de_entries; + index = (char *)dx_entry - (char *)entry_list->de_entries; index /=sizeof (*dx_entry); -if (index >=le16_to_cpu (dx_leaf->dl_list.de_num_used)) { +if (index >=le16_to_cpu (entry_list->de_num_used)) {mlog (ML_ERROR ,"Dir %llu: Bad dx_entry ptr idx %d, (%p, %p)\n" , - (unsigned long long )OCFS2_I (dir)->ip_blkno, index, dx_leaf, - dx_entry); + (unsigned long long )OCFS2_I (dir)->ip_blkno, index, + entry_list, dx_entry);return -EIO ; } -mlog (0 ,"Dir %llu: delete entry at index: %d\n" , - (unsigned long long )OCFS2_I (dir)->ip_blkno, index); -/* -* Add the index leaf into the journal before removing the -* unindexed entry. If we get an error return from -* __ocfs2_delete_entry(), then it hasn't removed the entry -* yet. Likewise, successful return means we *must* remove the -* indexed entry. +* Add the block holding our index into the journal before +* removing the unindexed entry. If we get an error return +* from __ocfs2_delete_entry(), then it hasn't removed the +* entry yet. Likewise, successful return means we *must* +* remove the indexed entry. +* +* We're also careful to journal the root tree block here if +* we're going to be adding to the start of the free list. */ - ret =ocfs2_journal_access_dl (handle, dir, lookup->dl_dx_leaf_bh, -OCFS2_JOURNAL_ACCESS_WRITE ); -if (ret) { -mlog_errno (ret); - goto out; +if (ocfs2_dx_root_inline (dx_root)) { + ret =ocfs2_journal_access_dr (handle, dir, dx_root_bh, +OCFS2_JOURNAL_ACCESS_WRITE ); +if (ret) { +mlog_errno (ret); + goto out; + } + }else { + ret =ocfs2_journal_access_dl (handle, dir, + lookup->dl_dx_leaf_bh, +OCFS2_JOURNAL_ACCESS_WRITE ); +if (ret) { +mlog_errno (ret); + goto out; + } } +mlog (0 ,"Dir %llu: delete entry at index: %d\n" , + (unsigned long long )OCFS2_I (dir)->ip_blkno, index); + ret =__ocfs2_delete_entry (handle, dir, lookup->dl_entry, leaf_bh, leaf_bh->b_data, leaf_bh->b_size);if (ret) {
@@ -1189,9 +1237,12 @@ static int ocfs2_delete_entry_dx(handle_t *handle, struct inode *dir, goto out; } -ocfs2_dx_leaf_remove_entry (dx_leaf, index); +ocfs2_dx_list_remove_entry (entry_list, index); -ocfs2_journal_dirty (handle, lookup->dl_dx_leaf_bh); +if (ocfs2_dx_root_inline (dx_root)) +ocfs2_journal_dirty (handle, dx_root_bh); +else +ocfs2_journal_dirty (handle, lookup->dl_dx_leaf_bh); out:return ret;
@@ -1288,13 +1339,30 @@ static void ocfs2_dx_dir_leaf_insert_tail(struct ocfs2_dx_leaf *dx_leaf,le16_add_cpu (&dx_leaf->dl_list.de_num_used,1 ); } +static void ocfs2_dx_entry_list_insert (struct ocfs2_dx_entry_list *entry_list, +struct ocfs2_dx_hinfo *hinfo, +u64 dirent_blk) +{ +int i; +struct ocfs2_dx_entry *dx_entry; + + i =le16_to_cpu (entry_list->de_num_used); + dx_entry = &entry_list->de_entries[i]; + +memset (dx_entry,0 ,sizeof (*dx_entry)); + dx_entry->dx_major_hash =cpu_to_le32 (hinfo->major_hash); + dx_entry->dx_minor_hash =cpu_to_le32 (hinfo->minor_hash); + dx_entry->dx_dirent_blk =cpu_to_le64 (dirent_blk); + +le16_add_cpu (&entry_list->de_num_used,1 ); +} +static int __ocfs2_dx_dir_leaf_insert (struct inode *dir,handle_t *handle,struct ocfs2_dx_hinfo *hinfo,u64 dirent_blk,struct buffer_head *dx_leaf_bh) { -int ret, i; -struct ocfs2_dx_entry *dx_entry; +int ret;struct ocfs2_dx_leaf *dx_leaf; ret = ocfs2_journal_access_dl(handle, dir, dx_leaf_bh,
@@ -1305,25 +1373,48 @@ static int __ocfs2_dx_dir_leaf_insert(struct inode *dir, handle_t *handle, } dx_leaf = (struct ocfs2_dx_leaf *)dx_leaf_bh->b_data; - i =le16_to_cpu (dx_leaf->dl_list.de_num_used); - dx_entry = &dx_leaf->dl_list.de_entries[i]; +ocfs2_dx_entry_list_insert (&dx_leaf->dl_list, hinfo, dirent_blk); +ocfs2_journal_dirty (handle, dx_leaf_bh); -memset (dx_entry,0 ,sizeof (*dx_entry)); - dx_entry->dx_major_hash =cpu_to_le32 (hinfo->major_hash); - dx_entry->dx_minor_hash =cpu_to_le32 (hinfo->minor_hash); - dx_entry->dx_dirent_blk =cpu_to_le64 (dirent_blk); +out: +return ret; +} -le16_add_cpu (&dx_leaf->dl_list.de_num_used,1 ); +static int ocfs2_dx_inline_root_insert (struct inode *dir,handle_t *handle, +struct ocfs2_dx_hinfo *hinfo, +u64 dirent_blk, +struct buffer_head *dx_root_bh) +{ +int ret; +struct ocfs2_dx_root_block *dx_root; -ocfs2_journal_dirty (handle, dx_leaf_bh); + ret =ocfs2_journal_access_dr (handle, dir, dx_root_bh, +OCFS2_JOURNAL_ACCESS_WRITE ); +if (ret) { +mlog_errno (ret); + goto out; + } + + dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data; +ocfs2_dx_entry_list_insert (&dx_root->dr_entries, hinfo, dirent_blk); +ocfs2_journal_dirty (handle, dx_root_bh); out:return ret; } -static int ocfs2_dx_dir_leaf_insert (struct inode *dir,handle_t *handle, -struct ocfs2_dir_lookup_result *lookup) +static int ocfs2_dx_dir_insert (struct inode *dir,handle_t *handle, +struct ocfs2_dir_lookup_result *lookup) { +struct ocfs2_dx_root_block *dx_root; + + dx_root = (struct ocfs2_dx_root_block *)lookup->dl_dx_root_bh->b_data; +if (ocfs2_dx_root_inline (dx_root)) +return ocfs2_dx_inline_root_insert (dir, handle, + &lookup->dl_hinfo, + lookup->dl_leaf_bh->b_blocknr, + lookup->dl_dx_root_bh); +return __ocfs2_dx_dir_leaf_insert (dir, handle, &lookup->dl_hinfo, lookup->dl_leaf_bh->b_blocknr, lookup->dl_dx_leaf_bh);
@@ -1407,14 +1498,14 @@ int __ocfs2_add_entry(handle_t *handle,else { status =ocfs2_journal_access_db (handle, dir, insert_bh, -OCFS2_JOURNAL_ACCESS_WRITE ); -if (ocfs2_dir_indexed (dir)) { - status =ocfs2_dx_dir_leaf_insert (dir, - handle, - lookup); -if (status) { -mlog_errno (status); - goto bail; +OCFS2_JOURNAL_ACCESS_WRITE ); + +if (ocfs2_dir_indexed (dir)) { + status =ocfs2_dx_dir_insert (dir, handle, + lookup); +if (status) { +mlog_errno (status); + goto bail; } } }
@@ -2017,6 +2108,7 @@ static int ocfs2_dx_dir_attach_index(struct ocfs2_super *osb, handle_t *handle, struct inode *dir, struct buffer_head *di_bh, struct ocfs2_alloc_context *meta_ac, + int dx_inline, struct buffer_head **ret_dx_root_bh) { int ret;
@@ -2060,8 +2152,15 @@ static int ocfs2_dx_dir_attach_index(struct ocfs2_super *osb, dx_root->dr_fs_generation =cpu_to_le32 (osb->fs_generation); dx_root->dr_blkno =cpu_to_le64 (dr_blkno); dx_root->dr_dir_blkno =cpu_to_le64 (OCFS2_I (dir)->ip_blkno); - dx_root->dr_list.l_count = -cpu_to_le16 (ocfs2_extent_recs_per_dx_root (osb->sb)); + +if (dx_inline) { + dx_root->dr_flags |=OCFS2_DX_FLAG_INLINE ; + dx_root->dr_entries.de_count = +cpu_to_le16 (ocfs2_dx_entries_per_root (osb->sb)); + }else { + dx_root->dr_list.l_count = +cpu_to_le16 (ocfs2_extent_recs_per_dx_root (osb->sb)); + } ret =ocfs2_journal_dirty (handle, dx_root_bh);if (ret)
@@ -2234,20 +2333,12 @@ static int ocfs2_fill_new_dir_dx(struct ocfs2_super *osb,struct ocfs2_alloc_context *data_ac, struct ocfs2_alloc_context *meta_ac) { - int ret, num_dx_leaves, i; + int ret;struct buffer_head *leaf_bh =NULL ;struct buffer_head *dx_root_bh =NULL ; -struct buffer_head **dx_leaves =NULL ; -struct ocfs2_extent_tree et;struct ocfs2_dx_hinfo hinfo; -u64 insert_blkno; - - dx_leaves =ocfs2_dx_dir_kmalloc_leaves (osb->sb, &num_dx_leaves); -if (!dx_leaves) { - ret = -ENOMEM ; -mlog_errno (ret); - goto out; - } +struct ocfs2_dx_root_block *dx_root; +struct ocfs2_dx_entry_list *entry_list;/* * Our strategy is to create the directory as though it were
@@ -2256,7 +2347,8 @@ static int ocfs2_fill_new_dir_dx(struct ocfs2_super *osb,* very well known quantity. * * Essentially, we have two dirents ("." and ".."), in the 1st -* block which need indexing. +* block which need indexing. These are easily inserted into +* the index block. */ ret = ocfs2_fill_new_dir_el(osb, handle, parent, inode, di_bh,
@@ -2266,61 +2358,22 @@ static int ocfs2_fill_new_dir_dx(struct ocfs2_super *osb, goto out; } -/* -* Allocate and format the index leaf first, before attaching -* the index root. That way we're sure that the main bitmap -* won't -enospc on us with a half-created dir index. -* -* The meta data allocation for our index block will not -* -enospc on us unless there is a disk corruption. -*/ - - ret =__ocfs2_dx_dir_new_cluster (inode,0 , handle, data_ac, dx_leaves, - num_dx_leaves, &insert_blkno); + ret =ocfs2_dx_dir_attach_index (osb, handle, inode, di_bh, + meta_ac,1 , &dx_root_bh);if (ret) {mlog_errno (ret); goto out; } + dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data; + entry_list = &dx_root->dr_entries; -ocfs2_dx_dir_name_hash (inode,"." ,1 , &hinfo); - i =ocfs2_dx_dir_hash_idx (osb, &hinfo); - ret =__ocfs2_dx_dir_leaf_insert (inode, handle, &hinfo, - leaf_bh->b_blocknr, dx_leaves[i]); -if (ret) { -mlog_errno (ret); - goto out; - } +/* Buffer has been journaled for us by ocfs2_dx_dir_attach_index */ +ocfs2_dx_entry_list_insert (entry_list, &hinfo, leaf_bh->b_blocknr);ocfs2_dx_dir_name_hash (inode,".." ,2 , &hinfo); - i =ocfs2_dx_dir_hash_idx (osb, &hinfo); - ret =__ocfs2_dx_dir_leaf_insert (inode, handle, &hinfo, - leaf_bh->b_blocknr, dx_leaves[i]); -if (ret) { -mlog_errno (ret); - goto out; - } - - ret =ocfs2_dx_dir_attach_index (osb, handle, inode, di_bh, meta_ac, - &dx_root_bh); -if (ret) { -mlog_errno (ret); - goto out; - } - -/* This should never fail considering we start with an empty -* dx_root. */ -ocfs2_init_dx_root_extent_tree (&et, inode, dx_root_bh); - ret =ocfs2_insert_extent (osb, handle, inode, &et,0 , - insert_blkno,1 ,0 ,NULL ); -if (ret) -mlog_errno (ret); +ocfs2_dx_entry_list_insert (entry_list, &hinfo, leaf_bh->b_blocknr); out: -if (dx_leaves) { -for (i =0 ; i < num_dx_leaves; i++) -brelse (dx_leaves[i]); -kfree (dx_leaves); - }brelse (dx_root_bh);brelse (leaf_bh);return ret;
@@ -2390,6 +2443,74 @@ inc: out:return ret; } +/* +* XXX: This expects dx_root_bh to already be part of the transaction. +*/ +static void ocfs2_dx_dir_index_root_block (struct inode *dir, +struct buffer_head *dx_root_bh, +struct buffer_head *dirent_bh) +{ +char *de_buf, *limit; +struct ocfs2_dx_root_block *dx_root; +struct ocfs2_dir_entry *de; +struct ocfs2_dx_hinfo hinfo; +u64 dirent_blk = dirent_bh->b_blocknr; + + dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data; + + de_buf = dirent_bh->b_data; + limit = de_buf + dir->i_sb->s_blocksize; + +while (de_buf < limit) { + de = (struct ocfs2_dir_entry *)de_buf; + +if (!de->name_len || !de->inode) + goto inc; + +ocfs2_dx_dir_name_hash (dir, de->name, de->name_len, &hinfo); + +mlog (0 , +"dir: %llu, major: 0x%x minor: 0x%x, index: %u, name: %.*s\n" , + (unsigned long long )dir->i_ino, hinfo.major_hash, + hinfo.minor_hash, +le16_to_cpu (dx_root->dr_entries.de_num_used), + de->name_len, de->name); + +ocfs2_dx_entry_list_insert (&dx_root->dr_entries, &hinfo, + dirent_blk); +inc: + de_buf +=le16_to_cpu (de->rec_len); + } +} + +/* +* Count the number of inline directory entries in di_bh and compare +* them against the number of entries we can hold in an inline dx root +* block. +*/ +static int ocfs2_new_dx_should_be_inline (struct inode *dir, +struct buffer_head *di_bh) +{ +int dirent_count =0 ; +char *de_buf, *limit; +struct ocfs2_dir_entry *de; +struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; + + de_buf = di->id2.i_data.id_data; + limit = de_buf +i_size_read (dir); + +while (de_buf < limit) { + de = (struct ocfs2_dir_entry *)de_buf; + +if (de->name_len && de->inode) + dirent_count++; + + de_buf +=le16_to_cpu (de->rec_len); + } + +/* We are careful to leave room for one extra record. */ +return dirent_count <ocfs2_dx_entries_per_root (dir->i_sb); +}/* * Expand rec_len of the rightmost dirent in a directory block so that it
@@ -2440,7 +2561,7 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh, {u32 alloc, dx_alloc, bit_off, len;struct super_block *sb = dir->i_sb; -int ret, i, num_dx_leaves =0 , +int ret, i, num_dx_leaves =0 , dx_inline =0 , credits =ocfs2_inline_to_extents_credits (sb);u64 dx_insert_blkno, blkno, bytes = blocks_wanted << sb->s_blocksize_bits;
@@ -2463,15 +2584,19 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh, dx_alloc =0 ;if (ocfs2_supports_indexed_dirs (osb)) { -/* Add one more cluster for an index leaf */ - dx_alloc++; credits +=ocfs2_add_dir_index_credits (sb); - dx_leaves =ocfs2_dx_dir_kmalloc_leaves (sb, &num_dx_leaves); -if (!dx_leaves) { - ret = -ENOMEM ; -mlog_errno (ret); - goto out; + dx_inline =ocfs2_new_dx_should_be_inline (dir, di_bh); +if (!dx_inline) { +/* Add one more cluster for an index leaf */ + dx_alloc++; + dx_leaves =ocfs2_dx_dir_kmalloc_leaves (sb, + &num_dx_leaves); +if (!dx_leaves) { + ret = -ENOMEM ; +mlog_errno (ret); + goto out; + } }/* This gets us the dx_root */
@@ -2522,7 +2647,7 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh, } did_quota =1 ; -if (ocfs2_supports_indexed_dirs (osb)) { +if (ocfs2_supports_indexed_dirs (osb) && !dx_inline) {/* * Allocate our index cluster first, to maximize the * possibility that unindexed leaves grow
@@ -2585,7 +2710,12 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh, goto out_commit; } -if (ocfs2_supports_indexed_dirs (osb)) { +if (ocfs2_supports_indexed_dirs (osb) && !dx_inline) { +/* +* Dx dirs with an external cluster need to do this up +* front. Inline dx root's get handled later, after +* we've allocated our root block. +*/ ret =ocfs2_dx_dir_index_block (dir, handle, dx_leaves, num_dx_leaves, dirdata_bh);if (ret) {
@@ -2648,17 +2778,23 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,if (ocfs2_supports_indexed_dirs (osb)) { ret =ocfs2_dx_dir_attach_index (osb, handle, dir, di_bh, - meta_ac, &dx_root_bh); + meta_ac, dx_inline, + &dx_root_bh);if (ret) {mlog_errno (ret); goto out_commit; } -ocfs2_init_dx_root_extent_tree (&dx_et, dir, dx_root_bh); - ret =ocfs2_insert_extent (osb, handle, dir, &dx_et,0 , - dx_insert_blkno,1 ,0 ,NULL ); -if (ret) -mlog_errno (ret); +if (dx_inline) { +ocfs2_dx_dir_index_root_block (dir, dx_root_bh, + dirdata_bh); + }else { +ocfs2_init_dx_root_extent_tree (&dx_et, dir, dx_root_bh); + ret =ocfs2_insert_extent (osb, handle, dir, &dx_et,0 , + dx_insert_blkno,1 ,0 ,NULL ); +if (ret) +mlog_errno (ret); + } }/*
@@ -2688,14 +2824,18 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,if (ocfs2_supports_indexed_dirs (osb)) {unsigned int off; -/* -* We need to return the correct block within the -* cluster which should hold our entry. -*/ - off =ocfs2_dx_dir_hash_idx (OCFS2_SB (dir->i_sb), - &lookup->dl_hinfo); -get_bh (dx_leaves[off]); - lookup->dl_dx_leaf_bh = dx_leaves[off]; +if (!dx_inline) { +/* +* We need to return the correct block within the +* cluster which should hold our entry. +*/ + off =ocfs2_dx_dir_hash_idx (OCFS2_SB (dir->i_sb), + &lookup->dl_hinfo); +get_bh (dx_leaves[off]); + lookup->dl_dx_leaf_bh = dx_leaves[off]; + } + lookup->dl_dx_root_bh = dx_root_bh; + dx_root_bh =NULL ; } out_commit:
@@ -3504,6 +3644,133 @@ out:return ret; } +static int ocfs2_expand_inline_dx_root (struct inode *dir, +struct buffer_head *dx_root_bh) +{ +int ret, num_dx_leaves, i, j, did_quota =0 ; +struct buffer_head **dx_leaves =NULL ; +struct ocfs2_extent_tree et; +u64 insert_blkno; +struct ocfs2_alloc_context *data_ac =NULL ; +struct ocfs2_super *osb =OCFS2_SB (dir->i_sb); +handle_t *handle =NULL ; +struct ocfs2_dx_root_block *dx_root; +struct ocfs2_dx_entry_list *entry_list; +struct ocfs2_dx_entry *dx_entry; +struct ocfs2_dx_leaf *target_leaf; + + ret =ocfs2_reserve_clusters (osb,1 , &data_ac); +if (ret) { +mlog_errno (ret); + goto out; + } + + dx_leaves =ocfs2_dx_dir_kmalloc_leaves (osb->sb, &num_dx_leaves); +if (!dx_leaves) { + ret = -ENOMEM ; +mlog_errno (ret); + goto out; + } + + handle =ocfs2_start_trans (osb,ocfs2_calc_dxi_expand_credits (osb->sb)); +if (IS_ERR (handle)) { + ret =PTR_ERR (handle); +mlog_errno (ret); + goto out; + } + +if (vfs_dq_alloc_space_nodirty (dir, +ocfs2_clusters_to_bytes (osb->sb,1 ))) { + ret = -EDQUOT ; + goto out_commit; + } + did_quota =1 ; + + ret =__ocfs2_dx_dir_new_cluster (dir,0 , handle, data_ac, dx_leaves, + num_dx_leaves, &insert_blkno); +if (ret) { +mlog_errno (ret); + goto out_commit; + } + +/* +* Transfer the entries from our dx_root into the appropriate +* block +*/ + dx_root = (struct ocfs2_dx_root_block *) dx_root_bh->b_data; + entry_list = &dx_root->dr_entries; + +for (i =0 ; i <le16_to_cpu (entry_list->de_num_used); i++) { + dx_entry = &entry_list->de_entries[i]; + + j =__ocfs2_dx_dir_hash_idx (osb, +le32_to_cpu (dx_entry->dx_minor_hash)); + target_leaf = (struct ocfs2_dx_leaf *)dx_leaves[j]->b_data; + +ocfs2_dx_dir_leaf_insert_tail (target_leaf, dx_entry); + +/* Each leaf has been passed to the journal already +* via __ocfs2_dx_dir_new_cluster() */ + } + + ret =ocfs2_journal_access_dr (handle, dir, dx_root_bh, +OCFS2_JOURNAL_ACCESS_WRITE ); +if (ret) { +mlog_errno (ret); + goto out_commit; + } + + dx_root->dr_flags &= ~OCFS2_DX_FLAG_INLINE ; +memset (&dx_root->dr_list,0 , osb->sb->s_blocksize - + offsetof(struct ocfs2_dx_root_block , dr_list)); + dx_root->dr_list.l_count = +cpu_to_le16 (ocfs2_extent_recs_per_dx_root (osb->sb)); + +/* This should never fail considering we start with an empty +* dx_root. */ +ocfs2_init_dx_root_extent_tree (&et, dir, dx_root_bh); + ret =ocfs2_insert_extent (osb, handle, dir, &et,0 , + insert_blkno,1 ,0 ,NULL ); +if (ret) +mlog_errno (ret); + did_quota =0 ; + +ocfs2_journal_dirty (handle, dx_root_bh); + +out_commit: +if (ret <0 && did_quota) +vfs_dq_free_space_nodirty (dir, +ocfs2_clusters_to_bytes (dir->i_sb,1 )); + +ocfs2_commit_trans (osb, handle); + +out: +if (data_ac) +ocfs2_free_alloc_context (data_ac); + +if (dx_leaves) { +for (i =0 ; i < num_dx_leaves; i++) +brelse (dx_leaves[i]); +kfree (dx_leaves); + } +return ret; +} + +static int ocfs2_inline_dx_has_space (struct buffer_head *dx_root_bh) +{ +struct ocfs2_dx_root_block *dx_root; +struct ocfs2_dx_entry_list *entry_list; + + dx_root = (struct ocfs2_dx_root_block *) dx_root_bh->b_data; + entry_list = &dx_root->dr_entries; + +if (le16_to_cpu (entry_list->de_num_used) >= +le16_to_cpu (entry_list->de_count)) +return -ENOSPC ; + +return 0 ; +} + static int ocfs2_find_dir_space_dx(struct ocfs2_super *osb, struct inode *dir, struct buffer_head *di_bh, const char *name, int namelen,
@@ -3525,6 +3792,23 @@ static int ocfs2_find_dir_space_dx(struct ocfs2_super *osb, struct inode *dir, } dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data; +if (ocfs2_dx_root_inline (dx_root)) { + ret =ocfs2_inline_dx_has_space (dx_root_bh); + +if (ret ==0 ) + goto search_el; + +/* +* We ran out of room in the root block. Expand it to +* an extent, then allow ocfs2_find_dir_space_dx to do +* the rest. +*/ + ret =ocfs2_expand_inline_dx_root (dir, dx_root_bh); +if (ret) { +mlog_errno (ret); + goto out; + } + } restart_search: ret = ocfs2_dx_dir_lookup(dir, &dx_root->dr_list, &lookup->dl_hinfo,
@@ -3576,8 +3860,11 @@ restart_search: goto restart_search; } +search_el: lookup->dl_dx_leaf_bh = dx_leaf_bh; dx_leaf_bh =NULL ; + lookup->dl_dx_root_bh = dx_root_bh; + dx_root_bh =NULL ; out:brelse (dx_leaf_bh);
@@ -3772,10 +4059,12 @@ int ocfs2_dx_dir_truncate(struct inode *dir, struct buffer_head *di_bh)mlog_errno (ret); goto out; } + dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data; -ocfs2_init_dx_root_extent_tree (&et, dir, dx_root_bh); +if (ocfs2_dx_root_inline (dx_root)) + goto remove_index; - dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data; +ocfs2_init_dx_root_extent_tree (&et, dir, dx_root_bh);/* XXX: What if dr_clusters is too large? */ while (le32_to_cpu (dx_root->dr_clusters)) {
@@ -3801,6 +4090,7 @@ int ocfs2_dx_dir_truncate(struct inode *dir, struct buffer_head *di_bh) major_hash = cpos -1 ; } +remove_index: ret =ocfs2_dx_dir_remove_index (dir, di_bh, dx_root_bh);if (ret) {mlog_errno (ret);
fs/ocfs2/dir.h +2 -0
@@ -37,6 +37,8 @@ struct ocfs2_dir_lookup_result {struct ocfs2_dir_entry *dl_entry;/* Target dirent in * unindexed leaf */ +struct buffer_head *dl_dx_root_bh;/* Root of indexed +* tree */ struct buffer_head *dl_dx_leaf_bh;/* Indexed leaf block */ struct ocfs2_dx_entry *dl_dx_entry;/* Target dx_entry in * indexed leaf */
fs/ocfs2/journal.h +10 -0
@@ -447,6 +447,16 @@ static inline int ocfs2_rename_credits(struct super_block *sb)#define OCFS2_DX_ROOT_REMOVE_CREDITS (OCFS2_INODE_UPDATE_CREDITS + \ OCFS2_SUBALLOC_FREE) +static inline int ocfs2_calc_dxi_expand_credits (struct super_block *sb) +{ +int credits =1 +OCFS2_SUBALLOC_ALLOC ; + + credits +=ocfs2_clusters_to_blocks (sb,1 ); + credits +=ocfs2_quota_trans_credits (sb); + +return credits; +} +/* * Please note that the caller must make sure that root_el is the root * of extent tree. So for an inode, it should be &fe->id2.i_list. Otherwise
fs/ocfs2/namei.c +1 -3
@@ -321,10 +321,8 @@ static int ocfs2_mknod(struct inode *dir, want_clusters +=1 ;/* Dir indexing requires extra space as well */ -if (ocfs2_supports_indexed_dirs (osb)) { - want_clusters++; +if (ocfs2_supports_indexed_dirs (osb)) want_meta++; - } } status =ocfs2_reserve_new_metadata_blocks (osb, want_meta, &meta_ac);
fs/ocfs2/ocfs2_fs.h +24 -4
@@ -815,6 +815,8 @@ struct ocfs2_dx_entry_list {* length de_num_used */ }; +#define OCFS2_DX_FLAG_INLINE 0x01 +/* * A directory indexing block. Each indexed directory has one of these, * pointed to by ocfs2_dinode.
@@ -835,13 +837,21 @@ struct ocfs2_dx_root_block {* extent block */ __le32 dr_clusters;/* Clusters allocated * to the indexed tree. */ -__le32 dr_reserved1; +__u8 dr_flags;/* OCFS2_DX_FLAG_* flags */ +__u8 dr_reserved0; +__le16 dr_reserved1;__le64 dr_dir_blkno;/* Pointer to parent inode */ __le64 dr_reserved2;__le64 dr_reserved3[16 ]; -struct ocfs2_extent_list dr_list;/* Keep this aligned to 128 -* bits for maximum space -* efficiency. */ +union { +struct ocfs2_extent_list dr_list;/* Keep this aligned to 128 +* bits for maximum space +* efficiency. */ +struct ocfs2_dx_entry_list dr_entries;/* In-root-block list of +* entries. We grow out +* to extents if this +* gets too big. */ + }; };/*
@@ -1234,6 +1244,16 @@ static inline int ocfs2_dx_entries_per_leaf(struct super_block *sb)return size /sizeof (struct ocfs2_dx_entry ); } +static inline int ocfs2_dx_entries_per_root (struct super_block *sb) +{ +int size; + + size = sb->s_blocksize - + offsetof(struct ocfs2_dx_root_block, dr_entries.de_entries); + +return size /sizeof (struct ocfs2_dx_entry ); +} +static inline u16 ocfs2_local_alloc_size (struct super_block *sb) {u16 size;
Signature · 1 line
1.5.6
PATCH 3/7 ocfs2: Store dir index records inline
Quoted 7 lines · Mark Fasheh
Allow us to store a small number of directory index records in the
ocfs2_dx_root_block. This saves us a disk read on small to medium sized directories (less than about 250 entries). The inline root is automatically turned into a root block with extents if the directory size increases beyond it's capacity.Signed-off-by Mark Fasheh <[email protected]>
Two tiny comments, but otherwise
Quoted 10 lines
fs/ocfs2/dir.c +0
-6@@ -1407,14 +1498,14 @@ int __ocfs2_add_entry(handle_t *handle,else { status = ocfs2_journal_access_db(handle, dir, insert_bh, -OCFS2_JOURNAL_ACCESS_WRITE ); -if (ocfs2_dir_indexed (dir)) { - status =ocfs2_dx_dir_leaf_insert (dir, - handle, - lookup); -if (status) {
fs/ocfs2/dir.c int __ocfs2_add_entry(handle_t *handle, · line 1508
Quoted 10 lines
fs/ocfs2/dir.c +8
-2-mlog_errno (status); - goto bail; + OCFS2_JOURNAL_ACCESS_WRITE); + +if (ocfs2_dir_indexed (dir)) { + status =ocfs2_dx_dir_insert (dir, handle, + lookup); +if (status) { +mlog_errno (status); + goto bail;
This hunk looks indented wrong. I think it's all inside the
else{, and should be indented the same as the journal_access_db() call.
Quoted 69 lines
fs/ocfs2/dir.c +65
-0@@ -3504,6 +3644,133 @@ out:return ret; } +static int ocfs2_expand_inline_dx_root (struct inode *dir, +struct buffer_head *dx_root_bh) +{ +int ret, num_dx_leaves, i, j, did_quota =0 ; +struct buffer_head **dx_leaves =NULL ; +struct ocfs2_extent_tree et; +u64 insert_blkno; +struct ocfs2_alloc_context *data_ac =NULL ; +struct ocfs2_super *osb =OCFS2_SB (dir->i_sb); +handle_t *handle =NULL ; +struct ocfs2_dx_root_block *dx_root; +struct ocfs2_dx_entry_list *entry_list; +struct ocfs2_dx_entry *dx_entry; +struct ocfs2_dx_leaf *target_leaf; + + ret =ocfs2_reserve_clusters (osb,1 , &data_ac); +if (ret) { +mlog_errno (ret); + goto out; + } + + dx_leaves =ocfs2_dx_dir_kmalloc_leaves (osb->sb, &num_dx_leaves); +if (!dx_leaves) { + ret = -ENOMEM ; +mlog_errno (ret); + goto out; + } + + handle =ocfs2_start_trans (osb,ocfs2_calc_dxi_expand_credits (osb->sb)); +if (IS_ERR (handle)) { + ret =PTR_ERR (handle); +mlog_errno (ret); + goto out; + } + +if (vfs_dq_alloc_space_nodirty (dir, +ocfs2_clusters_to_bytes (osb->sb,1 ))) { + ret = -EDQUOT ; + goto out_commit; + } + did_quota =1 ; + + ret =__ocfs2_dx_dir_new_cluster (dir,0 , handle, data_ac, dx_leaves, + num_dx_leaves, &insert_blkno); +if (ret) { +mlog_errno (ret); + goto out_commit; + } + +/* +* Transfer the entries from our dx_root into the appropriate +* block +*/ + dx_root = (struct ocfs2_dx_root_block *) dx_root_bh->b_data; + entry_list = &dx_root->dr_entries; + +for (i =0 ; i <le16_to_cpu (entry_list->de_num_used); i++) { + dx_entry = &entry_list->de_entries[i]; + + j =__ocfs2_dx_dir_hash_idx (osb, +le32_to_cpu (dx_entry->dx_minor_hash)); + target_leaf = (struct ocfs2_dx_leaf *)dx_leaves[j]->b_data; + +ocfs2_dx_dir_leaf_insert_tail (target_leaf, dx_entry); +
fs/ocfs2/dir.c out: · line 3721
Quoted 10 lines
fs/ocfs2/dir.c +10
-0+/* Each leaf has been passed to the journal already +* via __ocfs2_dx_dir_new_cluster() */ + } + + ret =ocfs2_journal_access_dr (handle, dir, dx_root_bh, +OCFS2_JOURNAL_ACCESS_WRITE ); +if (ret) { +mlog_errno (ret); + goto out_commit; + }
Why wnot journal_access the dr before you claim the leaf
clusters, so that failure to get journal_access on the dr doesn't force a commit of the allocated clusters? Maybe I'm missing something.
Joel
Signature · 9 lines
"When choosing between two evils, I always like to try the one
I've never tried before."
- Mae West
Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127PATCH 4/7 ocfs2: Introduce dir free space list
In reply to Mark FashehThe only operation which doesn't get faster with directory indexing is insert, which still has to walk the entire unindexed directory portion to find a free block. This patch provides an improvement in directory insert performance by maintaining a singly linked list of directory leaf blocks which have space for additional dirents.
--- fs/ocfs2/dir.c | 551 +++++++++++++++++++++++++++++++++++++++++++-------- fs/ocfs2/dir.h | 8 + fs/ocfs2/journal.h | 12 +- fs/ocfs2/ocfs2_fs.h | 5 +- 4 files changed, 483 insertions(+), 93 deletions(-)
fs/ocfs2/dir.c +465 -86
@@ -80,22 +80,36 @@ static int ocfs2_do_extend_dir(struct super_block *sb,struct ocfs2_alloc_context *data_ac, struct ocfs2_alloc_context *meta_ac, struct buffer_head **new_bh); +static int ocfs2_dir_indexed (struct inode *inode);/* * These are distinct checks because future versions of the file system will * want to have a trailing dirent structure independent of indexing. */ -static int ocfs2_dir_has_trailer (struct inode *dir) +static int ocfs2_supports_dir_trailer (struct inode *dir) { +struct ocfs2_super *osb =OCFS2_SB (dir->i_sb); +if (OCFS2_I (dir)->ip_dyn_features &OCFS2_INLINE_DATA_FL )return 0 ; -return ocfs2_meta_ecc (OCFS2_SB (dir->i_sb)); +return ocfs2_meta_ecc (osb) ||ocfs2_dir_indexed (dir); } -static int ocfs2_supports_dir_trailer (struct ocfs2_super *osb) +/* +* "new' here refers to the point at which we're creating a new +* directory via "mkdir()", but also when we're expanding an inline +* directory. In either case, we don't yet have the indexing bit set +* on the directory, so the standard checks will fail in when metaecc +* is turned off. Only directory-initialization type functions should +* use this then. Everything else wants ocfs2_supports_dir_trailer() +*/ +static int ocfs2_new_dir_wants_trailer (struct inode *dir) { -return ocfs2_meta_ecc (osb); +struct ocfs2_super *osb =OCFS2_SB (dir->i_sb); + +return ocfs2_meta_ecc (osb) || +ocfs2_supports_indexed_dirs (osb); }static inline unsigned int ocfs2_dir_trailer_blk_off (struct super_block *sb)
@@ -127,7 +141,7 @@ static int ocfs2_skip_dir_trailer(struct inode *dir, {unsigned long toff = blklen -sizeof (struct ocfs2_dir_block_trailer ); -if (!ocfs2_dir_has_trailer (dir)) +if (!ocfs2_supports_dir_trailer (dir))return 0 ;if (offset != toff)
@@ -137,7 +151,7 @@ static int ocfs2_skip_dir_trailer(struct inode *dir, }static void ocfs2_init_dir_trailer (struct inode *inode, -struct buffer_head *bh) +struct buffer_head *bh,u16 rec_len) {struct ocfs2_dir_block_trailer *trailer;
@@ -147,6 +161,42 @@ static void ocfs2_init_dir_trailer(struct inode *inode,cpu_to_le16 (sizeof (struct ocfs2_dir_block_trailer )); trailer->db_parent_dinode =cpu_to_le64 (OCFS2_I (inode)->ip_blkno); trailer->db_blkno =cpu_to_le64 (bh->b_blocknr); + trailer->db_free_rec_len =cpu_to_le16 (rec_len); +} +/* +* Link an unindexed block with a dir trailer structure into the index free +* list. This function will modify dirdata_bh, but assumes you've already +* passed it to the journal. +*/ +static int ocfs2_dx_dir_link_trailer (struct inode *dir,handle_t *handle, +struct buffer_head *dx_root_bh, +struct buffer_head *dirdata_bh) +{ +int ret; +struct ocfs2_dx_root_block *dx_root; +struct ocfs2_dir_block_trailer *trailer; + + ret =ocfs2_journal_access_dr (handle, dir, dx_root_bh, +OCFS2_JOURNAL_ACCESS_WRITE ); +if (ret) { +mlog_errno (ret); + goto out; + } + trailer =ocfs2_trailer_from_bh (dirdata_bh, dir->i_sb); + dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data; + + trailer->db_free_next = dx_root->dr_free_blk; + dx_root->dr_free_blk =cpu_to_le64 (dirdata_bh->b_blocknr); + +ocfs2_journal_dirty (handle, dx_root_bh); + +out: +return ret; +} + +static int ocfs2_free_list_at_root (struct ocfs2_dir_lookup_result *res) +{ +return res->dl_prev_leaf_bh ==NULL ; }void ocfs2_free_dir_lookup_result (struct ocfs2_dir_lookup_result *res)
@@ -154,6 +204,7 @@ void ocfs2_free_dir_lookup_result(struct ocfs2_dir_lookup_result *res)brelse (res->dl_dx_root_bh);brelse (res->dl_leaf_bh);brelse (res->dl_dx_leaf_bh); +brelse (res->dl_prev_leaf_bh); }static int ocfs2_dir_indexed (struct inode *inode)
@@ -484,7 +535,7 @@ static int ocfs2_read_dir_block(struct inode *inode, u64 v_block, }if (!(flags &OCFS2_BH_READAHEAD ) && -ocfs2_dir_has_trailer (inode)) { +ocfs2_supports_dir_trailer (inode)) { rc =ocfs2_check_dir_trailer (inode, tmp);if (rc) {if (!*bh)
@@ -1148,6 +1199,47 @@ bail:return status; } +static unsigned int ocfs2_figure_dirent_hole (struct ocfs2_dir_entry *de) +{ +unsigned int hole; + +if (le64_to_cpu (de->inode) ==0 ) + hole =le16_to_cpu (de->rec_len); +else + hole =le16_to_cpu (de->rec_len) - +OCFS2_DIR_REC_LEN (de->name_len); + +return hole; +} + +static int ocfs2_find_max_rec_len (struct super_block *sb, +struct buffer_head *dirblock_bh) +{ +int size, this_hole, largest_hole =0 ; +char *trailer, *de_buf, *limit, *start = dirblock_bh->b_data; +struct ocfs2_dir_entry *de; + + trailer = (char *)ocfs2_trailer_from_bh (dirblock_bh, sb); + size =ocfs2_dir_trailer_blk_off (sb); + limit = start + size; + de_buf = start; + de = (struct ocfs2_dir_entry *)de_buf; +do { +if (de_buf != trailer) { + this_hole =ocfs2_figure_dirent_hole (de); +if (this_hole > largest_hole) + largest_hole = this_hole; + } + + de_buf +=le16_to_cpu (de->rec_len); + de = (struct ocfs2_dir_entry *)de_buf; + }while (de_buf < limit); + +if (largest_hole >=OCFS2_DIR_MIN_REC_LEN ) +return largest_hole; +return 0 ; +} +static void ocfs2_dx_list_remove_entry (struct ocfs2_dx_entry_list *entry_list,int index) {
@@ -1169,14 +1261,26 @@ clear:static int ocfs2_delete_entry_dx (handle_t *handle,struct inode *dir,struct ocfs2_dir_lookup_result *lookup) { -int ret, index; +int ret, index, max_rec_len, add_to_free_list =0 ;struct buffer_head *dx_root_bh = lookup->dl_dx_root_bh;struct buffer_head *leaf_bh = lookup->dl_leaf_bh;struct ocfs2_dx_leaf *dx_leaf;struct ocfs2_dx_entry *dx_entry = lookup->dl_dx_entry; +struct ocfs2_dir_block_trailer *trailer;struct ocfs2_dx_root_block *dx_root;struct ocfs2_dx_entry_list *entry_list; +/* +* This function gets a bit messy because we might have to +* modify the root block, regardless of whether the indexed +* entries are stored inline. +*/ + +/* +* *Only* set 'entry_list' here, based on where we're looking +* for the indexed entries. Later, we might still want to +* journal both blocks, based on free list state. +*/ dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data;if (ocfs2_dx_root_inline (dx_root)) { entry_list = &dx_root->dr_entries;
@@ -1201,6 +1305,15 @@ static int ocfs2_delete_entry_dx(handle_t *handle, struct inode *dir, }/* +* We know that removal of this dirent will leave enough room +* for a new one, so add this block to the free list if it +* isn't already there. +*/ + trailer =ocfs2_trailer_from_bh (leaf_bh, dir->i_sb); +if (trailer->db_free_rec_len ==0 ) + add_to_free_list =1 ; + +/* * Add the block holding our index into the journal before * removing the unindexed entry. If we get an error return * from __ocfs2_delete_entry(), then it hasn't removed the
@@ -1210,14 +1323,16 @@ static int ocfs2_delete_entry_dx(handle_t *handle, struct inode *dir,* We're also careful to journal the root tree block here if * we're going to be adding to the start of the free list. */ -if (ocfs2_dx_root_inline (dx_root)) { +if (add_to_free_list ||ocfs2_dx_root_inline (dx_root)) { ret =ocfs2_journal_access_dr (handle, dir, dx_root_bh,OCFS2_JOURNAL_ACCESS_WRITE );if (ret) {mlog_errno (ret); goto out; } - }else { + } + +if (!ocfs2_dx_root_inline (dx_root)) { ret =ocfs2_journal_access_dl (handle, dir, lookup->dl_dx_leaf_bh,OCFS2_JOURNAL_ACCESS_WRITE );
@@ -1237,6 +1352,17 @@ static int ocfs2_delete_entry_dx(handle_t *handle, struct inode *dir, goto out; } + max_rec_len =ocfs2_find_max_rec_len (dir->i_sb, leaf_bh); + trailer->db_free_rec_len =cpu_to_le16 (max_rec_len); +if (add_to_free_list) { + trailer->db_free_next = dx_root->dr_free_blk; + dx_root->dr_free_blk =cpu_to_le64 (leaf_bh->b_blocknr); +ocfs2_journal_dirty (handle, dx_root_bh); + } + +/* leaf_bh was journal_accessed for us in __ocfs2_delete_entry */ +ocfs2_journal_dirty (handle, leaf_bh); +ocfs2_dx_list_remove_entry (entry_list, index);if (ocfs2_dx_root_inline (dx_root))
@@ -1420,6 +1546,59 @@ static int ocfs2_dx_dir_insert(struct inode *dir, handle_t *handle, lookup->dl_dx_leaf_bh); } +static void ocfs2_remove_block_from_free_list (struct inode *dir, +handle_t *handle, +struct ocfs2_dir_lookup_result *lookup) +{ +struct ocfs2_dir_block_trailer *trailer, *prev; +struct ocfs2_dx_root_block *dx_root; +struct buffer_head *bh; + + trailer =ocfs2_trailer_from_bh (lookup->dl_leaf_bh, dir->i_sb); + +if (ocfs2_free_list_at_root (lookup)) { + bh = lookup->dl_dx_root_bh; + dx_root = (struct ocfs2_dx_root_block *)bh->b_data; + dx_root->dr_free_blk = trailer->db_free_next; + }else { + bh = lookup->dl_prev_leaf_bh; + prev =ocfs2_trailer_from_bh (bh, dir->i_sb); + prev->db_free_next = trailer->db_free_next; + } + + trailer->db_free_rec_len =cpu_to_le16 (0 ); + trailer->db_free_next =cpu_to_le64 (0 ); + +ocfs2_journal_dirty (handle, bh); +ocfs2_journal_dirty (handle, lookup->dl_leaf_bh); +} + +/* +* This expects that a journal write has been reserved on +* lookup->dl_prev_leaf_bh or lookup->dl_dx_root_bh +*/ +static void ocfs2_recalc_free_list (struct inode *dir,handle_t *handle, +struct ocfs2_dir_lookup_result *lookup) +{ +int max_rec_len; +struct ocfs2_dir_block_trailer *trailer; + +/* Walk dl_leaf_bh to figure out what the new free rec_len is. */ + max_rec_len =ocfs2_find_max_rec_len (dir->i_sb, lookup->dl_leaf_bh); +if (max_rec_len) { +/* +* There's still room in this block, so no need to remove it +* from the free list. In this case, we just want to update +* the rec len accounting. +*/ + trailer =ocfs2_trailer_from_bh (lookup->dl_leaf_bh, dir->i_sb); + trailer->db_free_rec_len =cpu_to_le16 (max_rec_len); +ocfs2_journal_dirty (handle, lookup->dl_leaf_bh); + }else { +ocfs2_remove_block_from_free_list (dir, handle, lookup); + } +} +/* we don't always have a dentry for what we want to add, so people * like orphan dir can call this instead. *
@@ -1448,7 +1627,31 @@ int __ocfs2_add_entry(handle_t *handle,if (!namelen)return -EINVAL ; -if (OCFS2_I (dir)->ip_dyn_features &OCFS2_INLINE_DATA_FL ) { +if (ocfs2_dir_indexed (dir)) { +struct buffer_head *bh; + +/* +* An indexed dir may require that we update the free space +* list. Reserve a write to the previous node in the list so +* that we don't fail later. +* +* XXX: This can be either a dx_root_block, or an unindexed +* directory tree leaf block. +*/ +if (ocfs2_free_list_at_root (lookup)) { + bh = lookup->dl_dx_root_bh; + retval =ocfs2_journal_access_dr (handle, dir, bh, +OCFS2_JOURNAL_ACCESS_WRITE ); + }else { + bh = lookup->dl_prev_leaf_bh; + retval =ocfs2_journal_access_db (handle, dir, bh, +OCFS2_JOURNAL_ACCESS_WRITE ); + } +if (retval) { +mlog_errno (retval); +return retval; + } + }else if (OCFS2_I (dir)->ip_dyn_features &OCFS2_INLINE_DATA_FL ) { data_start = di->id2.i_data.id_data; size =i_size_read (dir);
@@ -1530,6 +1733,9 @@ int __ocfs2_add_entry(handle_t *handle, de->name_len = namelen;memcpy (de->name, name, namelen); +if (ocfs2_dir_indexed (dir)) +ocfs2_recalc_free_list (dir, handle, lookup); + dir->i_version++; status =ocfs2_journal_dirty (handle, insert_bh); retval =0 ;
@@ -2053,7 +2259,7 @@ static int ocfs2_fill_new_dir_el(struct ocfs2_super *osb,mlog_entry_void (); -if (ocfs2_supports_dir_trailer (osb)) +if (ocfs2_new_dir_wants_trailer (inode)) size =ocfs2_dir_trailer_blk_off (parent->i_sb); status = ocfs2_do_extend_dir(osb->sb, handle, inode, fe_bh,
@@ -2074,8 +2280,12 @@ static int ocfs2_fill_new_dir_el(struct ocfs2_super *osb,memset (new_bh->b_data,0 , osb->sb->s_blocksize); de =ocfs2_fill_initial_dirents (inode, parent, new_bh->b_data, size); -if (ocfs2_supports_dir_trailer (osb)) -ocfs2_init_dir_trailer (inode, new_bh); +if (ocfs2_new_dir_wants_trailer (inode)) { +int size =le16_to_cpu (de->rec_len); + size -=OCFS2_DIR_REC_LEN (2 ); + size -=sizeof (struct ocfs2_dir_block_trailer ); +ocfs2_init_dir_trailer (inode, new_bh, size); + } status =ocfs2_journal_dirty (handle, new_bh);if (status <0 ) {
@@ -2107,6 +2317,7 @@ bail:static int ocfs2_dx_dir_attach_index (struct ocfs2_super *osb,handle_t *handle,struct inode *dir,struct buffer_head *di_bh, +struct buffer_head *dirdata_bh,struct ocfs2_alloc_context *meta_ac,int dx_inline,struct buffer_head **ret_dx_root_bh)
@@ -2118,6 +2329,8 @@ static int ocfs2_dx_dir_attach_index(struct ocfs2_super *osb,unsigned int num_bits;struct buffer_head *dx_root_bh =NULL ;struct ocfs2_dx_root_block *dx_root; +struct ocfs2_dir_block_trailer *trailer = +ocfs2_trailer_from_bh (dirdata_bh, dir->i_sb); ret =ocfs2_claim_metadata (osb, handle, meta_ac,1 , &dr_suballoc_bit, &num_bits, &dr_blkno);
@@ -2152,6 +2365,10 @@ static int ocfs2_dx_dir_attach_index(struct ocfs2_super *osb, dx_root->dr_fs_generation =cpu_to_le32 (osb->fs_generation); dx_root->dr_blkno =cpu_to_le64 (dr_blkno); dx_root->dr_dir_blkno =cpu_to_le64 (OCFS2_I (dir)->ip_blkno); +if (le16_to_cpu (trailer->db_free_rec_len)) + dx_root->dr_free_blk =cpu_to_le64 (dirdata_bh->b_blocknr); +else + dx_root->dr_free_blk =cpu_to_le64 (0 );if (dx_inline) { dx_root->dr_flags |=OCFS2_DX_FLAG_INLINE ;
@@ -2358,7 +2575,7 @@ static int ocfs2_fill_new_dir_dx(struct ocfs2_super *osb, goto out; } - ret =ocfs2_dx_dir_attach_index (osb, handle, inode, di_bh, + ret =ocfs2_dx_dir_attach_index (osb, handle, inode, di_bh, leaf_bh, meta_ac,1 , &dx_root_bh);if (ret) {mlog_errno (ret);
@@ -2368,6 +2585,7 @@ static int ocfs2_fill_new_dir_dx(struct ocfs2_super *osb, entry_list = &dx_root->dr_entries;/* Buffer has been journaled for us by ocfs2_dx_dir_attach_index */ +ocfs2_dx_dir_name_hash (inode,"." ,1 , &hinfo);ocfs2_dx_entry_list_insert (entry_list, &hinfo, leaf_bh->b_blocknr);ocfs2_dx_dir_name_hash (inode,".." ,2 , &hinfo);
@@ -2443,7 +2661,8 @@ inc: out:return ret; } -/* + +/* * XXX: This expects dx_root_bh to already be part of the transaction. */ static void ocfs2_dx_dir_index_root_block(struct inode *dir,
@@ -2518,18 +2737,26 @@ static int ocfs2_new_dx_should_be_inline(struct inode *dir,* expansion from an inline directory to one with extents. The first dir block * in that case is taken from the inline data portion of the inode block. * +* This will also return the largest amount of contiguous space for a dirent +* in the block. That value is *not* necessarily the last dirent, even after +* expansion. The directory indexing code wants this value for free space +* accounting. We do this here since we're already walking the entire dir +* block. +* * We add the dir trailer if this filesystem wants it. */ -static void ocfs2_expand_last_dirent (char *start,unsigned int old_size, -struct super_block *sb) +static unsigned int ocfs2_expand_last_dirent (char *start,unsigned int old_size, +struct inode *dir) { +struct super_block *sb = dir->i_sb;struct ocfs2_dir_entry *de;struct ocfs2_dir_entry *prev_de;char *de_buf, *limit;unsigned int new_size = sb->s_blocksize; -unsigned int bytes; +unsigned int bytes, this_hole; +unsigned int largest_hole =0 ; -if (ocfs2_supports_dir_trailer (OCFS2_SB (sb))) +if (ocfs2_new_dir_wants_trailer (dir)) new_size =ocfs2_dir_trailer_blk_off (sb); bytes = new_size - old_size;
@@ -2538,12 +2765,26 @@ static void ocfs2_expand_last_dirent(char *start, unsigned int old_size, de_buf = start; de = (struct ocfs2_dir_entry *)de_buf;do { + this_hole =ocfs2_figure_dirent_hole (de); +if (this_hole > largest_hole) + largest_hole = this_hole; + prev_de = de; de_buf +=le16_to_cpu (de->rec_len); de = (struct ocfs2_dir_entry *)de_buf; }while (de_buf < limit);le16_add_cpu (&prev_de->rec_len, bytes); + +/* We need to double check this after modification of the final +* dirent. */ + this_hole =ocfs2_figure_dirent_hole (prev_de); +if (this_hole > largest_hole) + largest_hole = this_hole; + +if (largest_hole >=OCFS2_DIR_MIN_REC_LEN ) +return largest_hole; +return 0 ; }/*
@@ -2700,9 +2941,16 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,memcpy (dirdata_bh->b_data, di->id2.i_data.id_data,i_size_read (dir));memset (dirdata_bh->b_data +i_size_read (dir),0 , sb->s_blocksize -i_size_read (dir)); -ocfs2_expand_last_dirent (dirdata_bh->b_data,i_size_read (dir), sb); -if (ocfs2_supports_dir_trailer (osb)) -ocfs2_init_dir_trailer (dir, dirdata_bh); + i =ocfs2_expand_last_dirent (dirdata_bh->b_data,i_size_read (dir), dir); +if (ocfs2_new_dir_wants_trailer (dir)) { +/* +* Prepare the dir trailer up front. It will otherwise look +* like a valid dirent. Even if inserting the index fails +* (unlikely), then all we'll have done is given first dir +* block a small amount of fragmentation. +*/ +ocfs2_init_dir_trailer (dir, dirdata_bh, i); + } ret =ocfs2_journal_dirty (handle, dirdata_bh);if (ret) {
@@ -2778,7 +3026,7 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,if (ocfs2_supports_indexed_dirs (osb)) { ret =ocfs2_dx_dir_attach_index (osb, handle, dir, di_bh, - meta_ac, dx_inline, + dirdata_bh, meta_ac, dx_inline, &dx_root_bh);if (ret) {mlog_errno (ret);
@@ -2930,6 +3178,8 @@ bail:* is to be turned into an extent based one. The size of the dirent to * insert might be larger than the space gained by growing to just one * block, so we may have to grow the inode by two blocks in that case. +* +* If the directory is already indexed, dx_root_bh must be provided. */ static int ocfs2_extend_dir(struct ocfs2_super *osb, struct inode *dir,
@@ -2950,10 +3200,17 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb,struct ocfs2_dir_entry * de;struct super_block *sb = osb->sb;struct ocfs2_extent_tree et; +struct buffer_head *dx_root_bh = lookup->dl_dx_root_bh;mlog_entry_void ();if (OCFS2_I (dir)->ip_dyn_features &OCFS2_INLINE_DATA_FL ) { +/* +* This would be a code error as an inline directory should +* never have an index root. +*/ +BUG_ON (dx_root_bh); + status =ocfs2_expand_inline_dir (dir, parent_fe_bh, blocks_wanted, lookup, &new_bh);
@@ -2962,6 +3219,10 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb, goto bail; } +/* Expansion from inline to an indexed directory will +* have given us this. */ + dx_root_bh = lookup->dl_dx_root_bh; +if (blocks_wanted ==1 ) {/* * If the new dirent will fit inside the space
@@ -3025,6 +3286,10 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb, } do_extend: +if (ocfs2_dir_indexed (dir)) + credits++;/* For attaching the new dirent block to the +* dx_root */ +down_write (&OCFS2_I (dir)->ip_alloc_sem); drop_alloc_sem =1 ;
@@ -3055,9 +3320,19 @@ do_extend: de = (struct ocfs2_dir_entry *) new_bh->b_data; de->inode =0 ; -if (ocfs2_dir_has_trailer (dir)) { +if (ocfs2_supports_dir_trailer (dir)) { de->rec_len =cpu_to_le16 (ocfs2_dir_trailer_blk_off (sb)); -ocfs2_init_dir_trailer (dir, new_bh); + +ocfs2_init_dir_trailer (dir, new_bh,le16_to_cpu (de->rec_len)); + +if (ocfs2_dir_indexed (dir)) { + status =ocfs2_dx_dir_link_trailer (dir, handle, + dx_root_bh, new_bh); +if (status) { +mlog_errno (status); + goto bail; + } + } }else { de->rec_len =cpu_to_le16 (sb->s_blocksize); }
@@ -3113,7 +3388,7 @@ static int ocfs2_find_dir_space_id(struct inode *dir, struct buffer_head *di_bh,* This calculates how many free bytes we'd have in block zero, should * this function force expansion to an extent tree. */ -if (ocfs2_supports_dir_trailer (OCFS2_SB (sb))) +if (ocfs2_new_dir_wants_trailer (dir)) free_space =ocfs2_dir_trailer_blk_off (sb) -i_size_read (dir);else free_space = dir->i_sb->s_blocksize -i_size_read (dir);
@@ -3644,6 +3919,127 @@ out:return ret; } +static int ocfs2_find_dir_space_dx (struct ocfs2_super *osb,struct inode *dir, +struct buffer_head *di_bh, +struct buffer_head *dx_root_bh, +const char *name,int namelen, +struct ocfs2_dir_lookup_result *lookup) +{ +int ret, rebalanced =0 ; +struct ocfs2_dx_root_block *dx_root; +struct buffer_head *dx_leaf_bh =NULL ; +struct ocfs2_dx_leaf *dx_leaf; +u64 blkno; +u32 leaf_cpos; + + dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data; + +restart_search: + ret =ocfs2_dx_dir_lookup (dir, &dx_root->dr_list, &lookup->dl_hinfo, + &leaf_cpos, &blkno); +if (ret) { +mlog_errno (ret); + goto out; + } + + ret =ocfs2_read_dx_leaf (dir, blkno, &dx_leaf_bh); +if (ret) { +mlog_errno (ret); + goto out; + } + + dx_leaf = (struct ocfs2_dx_leaf *)dx_leaf_bh->b_data; + +if (le16_to_cpu (dx_leaf->dl_list.de_num_used) >= +le16_to_cpu (dx_leaf->dl_list.de_count)) { +if (rebalanced) { +/* +* Rebalancing should have provided us with +* space in an appropriate leaf. +* +* XXX: Is this an abnormal condition then? +* Should we print a message here? +*/ + ret = -ENOSPC ; + goto out; + } + + ret =ocfs2_dx_dir_rebalance (osb, dir, dx_root_bh, dx_leaf_bh, + &lookup->dl_hinfo, leaf_cpos, + blkno); +if (ret) { +if (ret != -ENOSPC ) +mlog_errno (ret); + goto out; + } + +/* +* Restart the lookup. The rebalance might have +* changed which block our item fits into. Mark our +* progress, so we only execute this once. +*/ +brelse (dx_leaf_bh); + dx_leaf_bh =NULL ; + rebalanced =1 ; + goto restart_search; + } + + lookup->dl_dx_leaf_bh = dx_leaf_bh; + dx_leaf_bh =NULL ; + +out: +brelse (dx_leaf_bh); +return ret; +} + +static int ocfs2_search_dx_free_list (struct inode *dir, +struct buffer_head *dx_root_bh, +int namelen, +struct ocfs2_dir_lookup_result *lookup) +{ +int ret = -ENOSPC ; +struct buffer_head *leaf_bh =NULL , *prev_leaf_bh =NULL ; +struct ocfs2_dir_block_trailer *db; +u64 next_block; +int rec_len =OCFS2_DIR_REC_LEN (namelen); +struct ocfs2_dx_root_block *dx_root; + + dx_root = (struct ocfs2_dx_root_block *)dx_root_bh->b_data; + next_block =le64_to_cpu (dx_root->dr_free_blk); + +while (next_block) { +brelse (prev_leaf_bh); + prev_leaf_bh = leaf_bh; + leaf_bh =NULL ; + + ret =ocfs2_read_dir_block_direct (dir, next_block, &leaf_bh); +if (ret) { +mlog_errno (ret); + goto out; + } + + db =ocfs2_trailer_from_bh (leaf_bh, dir->i_sb); +if (rec_len <=le16_to_cpu (db->db_free_rec_len)) { + lookup->dl_leaf_bh = leaf_bh; + lookup->dl_prev_leaf_bh = prev_leaf_bh; + leaf_bh =NULL ; + prev_leaf_bh =NULL ; +break ; + } + + next_block =le64_to_cpu (db->db_free_next); + } + +if (!next_block) + ret = -ENOSPC ; + +out: + +brelse (leaf_bh); +brelse (prev_leaf_bh); +return ret; +} +static int ocfs2_expand_inline_dx_root (struct inode *dir,struct buffer_head *dx_root_bh) {
@@ -3771,19 +4167,18 @@ static int ocfs2_inline_dx_has_space(struct buffer_head *dx_root_bh)return 0 ; } -static int ocfs2_find_dir_space_dx (struct ocfs2_super *osb,struct inode *dir, -struct buffer_head *di_bh,const char *name, -int namelen, -struct ocfs2_dir_lookup_result *lookup) +static int ocfs2_prepare_dx_dir_for_insert (struct inode *dir, +struct buffer_head *di_bh, +const char *name, +int namelen, +struct ocfs2_dir_lookup_result *lookup) { -int ret, rebalanced =0 ; +int ret, free_dx_root =1 ; +struct ocfs2_super *osb =OCFS2_SB (dir->i_sb);struct buffer_head *dx_root_bh =NULL ; -struct ocfs2_dx_root_block *dx_root; -struct buffer_head *dx_leaf_bh =NULL ; -struct ocfs2_dx_leaf *dx_leaf; +struct buffer_head *leaf_bh =NULL ;struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data; -u64 blkno; -u32 leaf_cpos; +struct ocfs2_dx_root_block *dx_root; ret =ocfs2_read_dx_root (dir, di, &dx_root_bh);if (ret) {
@@ -3810,65 +4205,55 @@ static int ocfs2_find_dir_space_dx(struct ocfs2_super *osb, struct inode *dir, } } -restart_search: - ret =ocfs2_dx_dir_lookup (dir, &dx_root->dr_list, &lookup->dl_hinfo, - &leaf_cpos, &blkno); +/* +* Insert preparation for an indexed directory is split into two +* steps. The call to find_dir_space_dx reserves room in the index for +* an additional item. If we run out of space there, it's a real error +* we can't continue on. +*/ + ret =ocfs2_find_dir_space_dx (osb, dir, di_bh, dx_root_bh, name, + namelen, lookup);if (ret) {mlog_errno (ret); goto out; } - ret =ocfs2_read_dx_leaf (dir, blkno, &dx_leaf_bh); -if (ret) { +search_el: +/* +* Next, we need to find space in the unindexed tree. This call +* searches using the free space linked list. If the unindexed tree +* lacks sufficient space, we'll expand it below. The expansion code +* is smart enough to add any new blocks to the free space list. +*/ + ret =ocfs2_search_dx_free_list (dir, dx_root_bh, namelen, lookup); +if (ret && ret != -ENOSPC ) {mlog_errno (ret); goto out; } - dx_leaf = (struct ocfs2_dx_leaf *)dx_leaf_bh->b_data; +/* Do this up here - ocfs2_extend_dir might need the dx_root */ + lookup->dl_dx_root_bh = dx_root_bh; + free_dx_root =0 ; -if (le16_to_cpu (dx_leaf->dl_list.de_num_used) >= -le16_to_cpu (dx_leaf->dl_list.de_count)) { -if (rebalanced) { -/* -* Rebalancing should have provided us with -* space in an appropriate leaf. -* -* XXX: Is this an abnormal condition then? -* Should we print a message here? -*/ - ret = -ENOSPC ; - goto out; - } +if (ret == -ENOSPC ) { + ret =ocfs2_extend_dir (osb, dir, di_bh,1 , lookup, &leaf_bh); - ret =ocfs2_dx_dir_rebalance (osb, dir, dx_root_bh, dx_leaf_bh, - &lookup->dl_hinfo, leaf_cpos, - blkno);if (ret) { -if (ret != -ENOSPC ) -mlog_errno (ret); +mlog_errno (ret); goto out; }/* -* Restart the lookup. The rebalance might have -* changed which block our item fits into. Mark our -* progress, so we only execute this once. +* We make the assumption here that new leaf blocks are added +* to the front of our free list. */ -brelse (dx_leaf_bh); - dx_leaf_bh =NULL ; - rebalanced =1 ; - goto restart_search; + lookup->dl_prev_leaf_bh =NULL ; + lookup->dl_leaf_bh = leaf_bh; } -search_el: - lookup->dl_dx_leaf_bh = dx_leaf_bh; - dx_leaf_bh =NULL ; - lookup->dl_dx_root_bh = dx_root_bh; - dx_root_bh =NULL ; - out: -brelse (dx_leaf_bh); -brelse (dx_root_bh); +if (free_dx_root) +brelse (dx_root_bh);return ret; }
@@ -3913,17 +4298,11 @@ int ocfs2_prepare_dir_for_insert(struct ocfs2_super *osb,ocfs2_dx_dir_name_hash (dir, name, namelen, &lookup->dl_hinfo);if (ocfs2_dir_indexed (dir)) { - ret =ocfs2_find_dir_space_dx (osb, dir, parent_fe_bh, name, - namelen, lookup); -if (ret) { + ret =ocfs2_prepare_dx_dir_for_insert (dir, parent_fe_bh, + name, namelen, lookup); +if (ret)mlog_errno (ret); - goto out; - } - -/* -* We intentionally fall through so that the unindexed -* tree can also be prepared. -*/ + goto out; }if (OCFS2_I (dir)->ip_dyn_features &OCFS2_INLINE_DATA_FL ) {
fs/ocfs2/dir.h +8 -0
@@ -39,11 +39,19 @@ struct ocfs2_dir_lookup_result {struct buffer_head *dl_dx_root_bh;/* Root of indexed * tree */ +struct buffer_head *dl_dx_leaf_bh;/* Indexed leaf block */ struct ocfs2_dx_entry *dl_dx_entry;/* Target dx_entry in * indexed leaf */ struct ocfs2_dx_hinfo dl_hinfo;/* Name hash results */ + +struct buffer_head *dl_prev_leaf_bh;/* Previous entry in +* dir free space +* list. NULL if +* previous entry is +* dx root block. */ }; +void ocfs2_free_dir_lookup_result (struct ocfs2_dir_lookup_result *res); int ocfs2_find_entry(const char *name, int namelen,
fs/ocfs2/journal.h +6 -6
@@ -374,8 +374,8 @@ static inline int ocfs2_remove_extent_credits(struct super_block *sb) }/* data block for new dir/symlink, 2 for bitmap updates (bitmap fe + -* bitmap block for the new bit) */ -#define OCFS2_DIR_LINK_ADDITIONAL_CREDITS (1 + 2) +* bitmap block for the new bit) dx_root update for free list */ +#define OCFS2_DIR_LINK_ADDITIONAL_CREDITS (1 + 2 + 1)static inline int ocfs2_add_dir_index_credits (struct super_block *sb) {
@@ -409,19 +409,19 @@ static inline int ocfs2_mknod_credits(struct super_block *sb, int is_dir,#define OCFS2_SIMPLE_DIR_EXTEND_CREDITS (2)/* file update (nlink, etc) + directory mtime/ctime + dir entry block + quota -* update on dir + index leaf */ +* update on dir + index leaf + dx root update for free list */ static inline int ocfs2_link_credits (struct super_block *sb) { -return 2 *OCFS2_INODE_UPDATE_CREDITS +2 + +return 2 *OCFS2_INODE_UPDATE_CREDITS +3 +ocfs2_quota_trans_credits (sb); }/* inode + dir inode (if we unlink a dir), + dir entry block + orphan -* dir inode link + dir inode index leaf */ +* dir inode link + dir inode index leaf + dir index root */ static inline int ocfs2_unlink_credits (struct super_block *sb) {/* The quota update from ocfs2_link_credits is unused here... */ -return 2 *OCFS2_INODE_UPDATE_CREDITS +2 +ocfs2_link_credits (sb); +return 2 *OCFS2_INODE_UPDATE_CREDITS +3 +ocfs2_link_credits (sb); }/* dinode + orphan dir dinode + inode alloc dinode + orphan dir entry +
fs/ocfs2/ocfs2_fs.h +4 -1
@@ -416,6 +416,7 @@ static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {#define OCFS2_DIR_REC_LEN (name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \ OCFS2_DIR_ROUND) & \ ~OCFS2_DIR_ROUND) +#define OCFS2_DIR_MIN_REC_LEN OCFS2_DIR_REC_LEN(1)#define OCFS2_LINK_MAX 32000
@@ -842,7 +843,9 @@ struct ocfs2_dx_root_block {__le16 dr_reserved1;__le64 dr_dir_blkno;/* Pointer to parent inode */ __le64 dr_reserved2; -__le64 dr_reserved3[16 ]; +__le64 dr_free_blk;/* Pointer to head of free +* unindexed block list. */ +__le64 dr_reserved3[15 ];union {struct ocfs2_extent_list dr_list;/* Keep this aligned to 128 * bits for maximum space
Signature · 1 line
1.5.6
PATCH 4/7 ocfs2: Introduce dir free space list
Quoted 7 lines · Mark Fasheh
The only operation which doesn't get faster with directory indexing is insert, which still has to walk the entire unindexed directory portion to find a free block. This patch provides an improvement in directory insert performance by maintaining a singly linked list of directory leaf blocks which have space for additional dirents.
Signed-off-by Mark Fasheh <[email protected]>
Two small comments inline.
fs/ocfs2/dir.c static int ocfs2_fill_new_dir_el(struct ocfs2_super *osb, · line 2288
Quoted 12 lines
fs/ocfs2/dir.c +6
-2@@ -2074,8 +2280,12 @@ static int ocfs2_fill_new_dir_el(struct ocfs2_super *osb,memset (new_bh->b_data,0 , osb->sb->s_blocksize); de =ocfs2_fill_initial_dirents (inode, parent, new_bh->b_data, size); -if (ocfs2_supports_dir_trailer (osb)) -ocfs2_init_dir_trailer (inode, new_bh); +if (ocfs2_new_dir_wants_trailer (inode)) { +int size =le16_to_cpu (de->rec_len); + size -=OCFS2_DIR_REC_LEN (2 ); + size -=sizeof (struct ocfs2_dir_block_trailer ); +ocfs2_init_dir_trailer (inode, new_bh, size); + }
I don't get why you are...oh, I get it. In fill_new_dir_el(), you're starting with the rec_len of '..', then subtracting the "real" portion of that dirent. That describes the hole. Can we get a comment - it wasn't obvious.
fs/ocfs2/ocfs2_fs.h static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = { · line 419
Quoted 9 lines
fs/ocfs2/ocfs2_fs.h +1
-0@@ -416,6 +416,7 @@ static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {#define OCFS2_DIR_REC_LEN (name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \ OCFS2_DIR_ROUND) & \ ~OCFS2_DIR_ROUND) +#define OCFS2_DIR_MIN_REC_LEN OCFS2_DIR_REC_LEN(1)
I think tools has this defined in ocfs2.h or dirblock.h or
something. So when you bring ocfs2_fs.h over to tools, make sure to remove any tools copy of this macro.
Joel
Signature · 9 lines
"Not everything that can be counted counts, and not everything
that counts can be counted."
- Albert Einstein
Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127PATCH 5/7 ocfs2: Increase max links count
In reply to Mark FashehSince we've now got a directory format capable of handling a large number of entries, we can increase the maximum link count supported. This only gets increased if the directory indexing feature is turned on.
--- fs/ocfs2/inode.c | 6 +++--- fs/ocfs2/namei.c | 44 ++++++++++++++++++++++---------------------- fs/ocfs2/ocfs2.h | 37 +++++++++++++++++++++++++++++++++++++ fs/ocfs2/ocfs2_fs.h | 4 +++- 4 files changed, 65 insertions(+), 26 deletions(-)
fs/ocfs2/inode.c +3 -3
@@ -276,7 +276,7 @@ void ocfs2_populate_inode(struct inode *inode, struct ocfs2_dinode *fe, (unsigned long long )OCFS2_I (inode)->ip_blkno, (unsigned long long)le64_to_cpu(fe->i_blkno)); - inode->i_nlink =le16_to_cpu (fe->i_links_count); + inode->i_nlink =ocfs2_read_links_count (fe);if (fe->i_flags &cpu_to_le32 (OCFS2_SYSTEM_FL )) {OCFS2_I (inode)->ip_flags |=OCFS2_INODE_SYSTEM_FILE ;
@@ -1215,7 +1215,7 @@ int ocfs2_mark_inode_dirty(handle_t *handle,spin_unlock (&OCFS2_I (inode)->ip_lock); fe->i_size =cpu_to_le64 (i_size_read (inode)); - fe->i_links_count =cpu_to_le16 (inode->i_nlink); +ocfs2_set_links_count (fe, inode->i_nlink); fe->i_uid =cpu_to_le32 (inode->i_uid); fe->i_gid =cpu_to_le32 (inode->i_gid); fe->i_mode =cpu_to_le16 (inode->i_mode);
@@ -1252,7 +1252,7 @@ void ocfs2_refresh_inode(struct inode *inode,OCFS2_I (inode)->ip_dyn_features =le16_to_cpu (fe->i_dyn_features);ocfs2_set_inode_flags (inode);i_size_write (inode,le64_to_cpu (fe->i_size)); - inode->i_nlink =le16_to_cpu (fe->i_links_count); + inode->i_nlink =ocfs2_read_links_count (fe); inode->i_uid =le32_to_cpu (fe->i_uid); inode->i_gid =le32_to_cpu (fe->i_gid); inode->i_mode =le16_to_cpu (fe->i_mode);
fs/ocfs2/namei.c +22 -22
143 lines not on this page · raw message
fs/ocfs2/ocfs2.h +37 -0
@@ -403,6 +403,43 @@ static inline int ocfs2_supports_indexed_dirs(struct ocfs2_super *osb)return 0 ; } +static inline unsigned int ocfs2_link_max (struct ocfs2_super *osb) +{ +if (ocfs2_supports_indexed_dirs (osb)) +return OCFS2_DX_LINK_MAX ; +return OCFS2_LINK_MAX ; +} + +static inline unsigned int ocfs2_read_links_count (struct ocfs2_dinode *di) +{ +u32 nlink =le16_to_cpu (di->i_links_count); +u32 hi =le16_to_cpu (di->i_links_count_hi); + + nlink |= (hi <<OCFS2_LINKS_HI_SHIFT ); + +return nlink; +} + +static inline void ocfs2_set_links_count (struct ocfs2_dinode *di,u32 nlink) +{ +u16 lo, hi; + + lo = nlink; + hi = nlink >>OCFS2_LINKS_HI_SHIFT ; + + di->i_links_count =cpu_to_le16 (lo); + di->i_links_count_hi =cpu_to_le16 (hi); +} + +static inline void ocfs2_add_links_count (struct ocfs2_dinode *di,int n) +{ +u32 links =ocfs2_read_links_count (di); + + links += n; + +ocfs2_set_links_count (di, links); +} +/* set / clear functions because cluster events can make these happen * in parallel so we want the transitions to be atomic. this also * means that any future flags osb_flags must be protected by spinlock
fs/ocfs2/ocfs2_fs.h +3 -1
@@ -419,6 +419,8 @@ static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {#define OCFS2_DIR_MIN_REC_LEN OCFS2_DIR_REC_LEN(1)#define OCFS2_LINK_MAX 32000 +#define OCFS2_DX_LINK_MAX ((1U << 31) - 1U) +#define OCFS2_LINKS_HI_SHIFT 16#define S_SHIFT 12static unsigned char ocfs2_type_by_mode[S_IFMT >>S_SHIFT ] = {
@@ -686,7 +688,7 @@ struct ocfs2_dinode {belongs to */ __le16 i_suballoc_bit;/* Bit offset in suballocator block group */ -/*10*/ __le16 i_reserved0; +/*10*/ __le16 i_links_count_hi;/* High 16 bits of links count */ __le16 i_xattr_inline_size;__le32 i_clusters;/* Cluster count */ __le32 i_uid;/* Owner UID */
Signature · 1 line
1.5.6
PATCH 5/7 ocfs2: Increase max links count
Quoted 5 lines · Mark Fasheh
Since we've now got a directory format capable of handling a large number of entries, we can increase the maximum link count supported. This only gets increased if the directory indexing feature is turned on.
Signed-off-by Mark Fasheh <[email protected]>
Couple comments - I think one needs fixing.
fs/ocfs2/namei.c static int ocfs2_rename(struct inode *old_dir, · line 1299
Quoted 9 lines
fs/ocfs2/namei.c +1
-1@@ -1292,7 +1293,7 @@ static int ocfs2_rename(struct inode *old_dir, }if (S_ISDIR (new_inode->i_mode) || - (newfe->i_links_count ==cpu_to_le16 (1 ))){ + (ocfs2_read_links_count (newfe) ==cpu_to_le16 (1 ))) { status =ocfs2_orphan_add (osb, handle, new_inode, newfe, orphan_name, &orphan_insert, orphan_dir);
ocfs2_read_links_count() returns cpu-endian numbers. So I think
this needs to compare with "1", not "cpu_to_le16(1)".
fs/ocfs2/ocfs2.h static inline int ocfs2_supports_indexed_dirs(struct ocfs2_super *osb) · line 421
Quoted 9 lines
fs/ocfs2/ocfs2.h +9
-0+static inline unsigned int ocfs2_read_links_count (struct ocfs2_dinode *di) +{ +u32 nlink =le16_to_cpu (di->i_links_count); +u32 hi =le16_to_cpu (di->i_links_count_hi); + + nlink |= (hi <<OCFS2_LINKS_HI_SHIFT ); + +return nlink; +}
I *think* we can rely on links_count_hi being 0 on all
existing filesystems. But wouldn't it be safer to just skip links_count_hi if !FEATURE_DX?
Joel
Signature · 9 lines
Life's Little Instruction Book #444 "Never underestimate the power of a kind word or deed." Joel Becker Principal Software Developer Oracle E-mail: joel.becker at oracle.com Phone: (650) 506-8127
PATCH 6/7 ocfs2: Enable indexed directories
In reply to Mark FashehSince the disk format is finalized, we can set this feature bit in the supported mask.
--- fs/ocfs2/ocfs2_fs.h | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
fs/ocfs2/ocfs2_fs.h +2 -1
@@ -97,7 +97,8 @@ | OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP \ | OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK \ | OCFS2_FEATURE_INCOMPAT_XATTR \ - | OCFS2_FEATURE_INCOMPAT_META_ECC) + | OCFS2_FEATURE_INCOMPAT_META_ECC \ + | OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS)#define OCFS2_FEATURE_RO_COMPAT_SUPP (OCFS2_FEATURE_RO_COMPAT_UNWRITTEN \ | OCFS2_FEATURE_RO_COMPAT_USRQUOTA \ | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
Signature · 1 line
1.5.6
PATCH 6/7 ocfs2: Enable indexed directories
Quoted 4 lines · Mark Fasheh
Since the disk format is finalized, we can set this feature bit in the supported mask.
Signed-off-by Mark Fasheh <[email protected]>
Signature · 9 lines
"Practice random acts of kindness and senseless acts of beauty." Oh, and don't forget where your towel is. Joel Becker Principal Software Developer Oracle E-mail: joel.becker at oracle.com Phone: (650) 506-8127
PATCH 7/7 ocfs2: add quota call to ocfs2_remove_btree_range()
In reply to Mark FashehWe weren't reclaiming the clusters which get free'd from this function, so any user punching holes in a file would still have those bytes accounted against him/her. Add the call to vfs_dq_free_space_nodirty() to fix this. Interestingly enough, the journal credits calculation already took this into account.
--- fs/ocfs2/alloc.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
fs/ocfs2/alloc.c +3 -0
@@ -5447,6 +5447,9 @@ int ocfs2_remove_btree_range(struct inode *inode, goto out; } +vfs_dq_free_space_nodirty (inode, +ocfs2_clusters_to_bytes (inode->i_sb, len)); + ret =ocfs2_remove_extent (inode, et, cpos, len, handle, meta_ac, dealloc);if (ret) {
Signature · 1 line
1.5.6
PATCH 7/7 ocfs2: add quota call to ocfs2_remove_btree_range()
Quoted 8 lines · Mark Fasheh
We weren't reclaiming the clusters which get free'd from this function, so any user punching holes in a file would still have those bytes accounted against him/her. Add the call to
vfs_dq_free_space_nodirty()to fix this. Interestingly enough, the journal credits calculation already took this into account.Cc Jan Kara <[email protected]>Signed-off-by Mark Fasheh <[email protected]>
Looks good to me, though I think it's for Jan's Ack.
Joel
Signature · 9 lines
"For every complex problem there exists a solution that is brief,
concise, and totally wrong."
-Unknown
Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127PATCH 7/7 ocfs2: add quota call to ocfs2_remove_btree_range()
In reply to Mark FashehQuoted 8 lines · Mark Fasheh
We weren't reclaiming the clusters which get free'd from this function, so any user punching holes in a file would still have those bytes accounted against him/her. Add the call to
vfs_dq_free_space_nodirty()to fix this. Interestingly enough, the journal credits calculation already took this into account.Cc Jan Kara <[email protected]>Signed-off-by Mark Fasheh <[email protected]>
Looks fine. Thanks for finding this.
Honza
Quoted 21 lines
--- fs/ocfs2/alloc.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)fs/ocfs2/alloc.c +3
-0@@ -5447,6 +5447,9 @@ int ocfs2_remove_btree_range(struct inode *inode, goto out; } +vfs_dq_free_space_nodirty (inode, +ocfs2_clusters_to_bytes (inode->i_sb, len)); + ret =ocfs2_remove_extent (inode, et, cpos, len, handle, meta_ac, dealloc);if (ret) {Signature · 1 line
1.5.6
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR