提交 ece78b7d 编写于 作者: L Linus Torvalds

Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs

Pull ext2, ext3 and quota fixes from Jan Kara:
 "Interesting bits are:
   - removal of a special i_mutex locking subclass (I_MUTEX_QUOTA) since
     quota code does not need i_mutex anymore in any unusual way.
   - backport (from ext4) of a fix of a checkpointing bug (missing cache
     flush) that could lead to fs corruption on power failure

  The rest are just random small fixes & cleanups."

* 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs:
  ext2: trivial fix to comment for ext2_free_blocks
  ext2: remove the redundant comment for ext2_export_ops
  ext3: return 32/64-bit dir name hash according to usage type
  quota: Get rid of nested I_MUTEX_QUOTA locking subclass
  quota: Use precomputed value of sb_dqopt in dquot_quota_sync
  ext2: Remove i_mutex use from ext2_quota_write()
  reiserfs: Remove i_mutex use from reiserfs_quota_write()
  ext4: Remove i_mutex use from ext4_quota_write()
  ext3: Remove i_mutex use from ext3_quota_write()
  quota: Fix double lock in add_dquot_ref() with CONFIG_QUOTA_DEBUG
  jbd: Write journal superblock with WRITE_FUA after checkpointing
  jbd: protect all log tail updates with j_checkpoint_mutex
  jbd: Split updating of journal superblock and marking journal empty
  ext2: do not register write_super within VFS
  ext2: Remove s_dirt handling
  ext2: write superblock only once on unmount
  ext3: update documentation with barrier=1 default
  ext3: remove max_debt in find_group_orlov()
  jbd: Refine commit writeout logic
...@@ -59,9 +59,9 @@ commit=nrsec (*) Ext3 can be told to sync all its data and metadata ...@@ -59,9 +59,9 @@ commit=nrsec (*) Ext3 can be told to sync all its data and metadata
Setting it to very large values will improve Setting it to very large values will improve
performance. performance.
barrier=<0(*)|1> This enables/disables the use of write barriers in barrier=<0|1(*)> This enables/disables the use of write barriers in
barrier the jbd code. barrier=0 disables, barrier=1 enables. barrier (*) the jbd code. barrier=0 disables, barrier=1 enables.
nobarrier (*) This also requires an IO stack which can support nobarrier This also requires an IO stack which can support
barriers, and if jbd gets an error on a barrier barriers, and if jbd gets an error on a barrier
write, it will disable again with a warning. write, it will disable again with a warning.
Write barriers enforce proper on-disk ordering Write barriers enforce proper on-disk ordering
......
...@@ -165,7 +165,6 @@ static void release_blocks(struct super_block *sb, int count) ...@@ -165,7 +165,6 @@ static void release_blocks(struct super_block *sb, int count)
struct ext2_sb_info *sbi = EXT2_SB(sb); struct ext2_sb_info *sbi = EXT2_SB(sb);
percpu_counter_add(&sbi->s_freeblocks_counter, count); percpu_counter_add(&sbi->s_freeblocks_counter, count);
sb->s_dirt = 1;
} }
} }
...@@ -180,7 +179,6 @@ static void group_adjust_blocks(struct super_block *sb, int group_no, ...@@ -180,7 +179,6 @@ static void group_adjust_blocks(struct super_block *sb, int group_no,
free_blocks = le16_to_cpu(desc->bg_free_blocks_count); free_blocks = le16_to_cpu(desc->bg_free_blocks_count);
desc->bg_free_blocks_count = cpu_to_le16(free_blocks + count); desc->bg_free_blocks_count = cpu_to_le16(free_blocks + count);
spin_unlock(sb_bgl_lock(sbi, group_no)); spin_unlock(sb_bgl_lock(sbi, group_no));
sb->s_dirt = 1;
mark_buffer_dirty(bh); mark_buffer_dirty(bh);
} }
} }
...@@ -479,7 +477,7 @@ void ext2_discard_reservation(struct inode *inode) ...@@ -479,7 +477,7 @@ void ext2_discard_reservation(struct inode *inode)
} }
/** /**
* ext2_free_blocks_sb() -- Free given blocks and update quota and i_blocks * ext2_free_blocks() -- Free given blocks and update quota and i_blocks
* @inode: inode * @inode: inode
* @block: start physcial block to free * @block: start physcial block to free
* @count: number of blocks to free * @count: number of blocks to free
......
...@@ -81,7 +81,6 @@ static void ext2_release_inode(struct super_block *sb, int group, int dir) ...@@ -81,7 +81,6 @@ static void ext2_release_inode(struct super_block *sb, int group, int dir)
spin_unlock(sb_bgl_lock(EXT2_SB(sb), group)); spin_unlock(sb_bgl_lock(EXT2_SB(sb), group));
if (dir) if (dir)
percpu_counter_dec(&EXT2_SB(sb)->s_dirs_counter); percpu_counter_dec(&EXT2_SB(sb)->s_dirs_counter);
sb->s_dirt = 1;
mark_buffer_dirty(bh); mark_buffer_dirty(bh);
} }
...@@ -543,7 +542,6 @@ struct inode *ext2_new_inode(struct inode *dir, umode_t mode, ...@@ -543,7 +542,6 @@ struct inode *ext2_new_inode(struct inode *dir, umode_t mode,
} }
spin_unlock(sb_bgl_lock(sbi, group)); spin_unlock(sb_bgl_lock(sbi, group));
sb->s_dirt = 1;
mark_buffer_dirty(bh2); mark_buffer_dirty(bh2);
if (test_opt(sb, GRPID)) { if (test_opt(sb, GRPID)) {
inode->i_mode = mode; inode->i_mode = mode;
......
...@@ -130,9 +130,6 @@ static void ext2_put_super (struct super_block * sb) ...@@ -130,9 +130,6 @@ static void ext2_put_super (struct super_block * sb)
dquot_disable(sb, -1, DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED); dquot_disable(sb, -1, DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED);
if (sb->s_dirt)
ext2_write_super(sb);
ext2_xattr_put_super(sb); ext2_xattr_put_super(sb);
if (!(sb->s_flags & MS_RDONLY)) { if (!(sb->s_flags & MS_RDONLY)) {
struct ext2_super_block *es = sbi->s_es; struct ext2_super_block *es = sbi->s_es;
...@@ -307,7 +304,6 @@ static const struct super_operations ext2_sops = { ...@@ -307,7 +304,6 @@ static const struct super_operations ext2_sops = {
.write_inode = ext2_write_inode, .write_inode = ext2_write_inode,
.evict_inode = ext2_evict_inode, .evict_inode = ext2_evict_inode,
.put_super = ext2_put_super, .put_super = ext2_put_super,
.write_super = ext2_write_super,
.sync_fs = ext2_sync_fs, .sync_fs = ext2_sync_fs,
.statfs = ext2_statfs, .statfs = ext2_statfs,
.remount_fs = ext2_remount, .remount_fs = ext2_remount,
...@@ -358,11 +354,6 @@ static struct dentry *ext2_fh_to_parent(struct super_block *sb, struct fid *fid, ...@@ -358,11 +354,6 @@ static struct dentry *ext2_fh_to_parent(struct super_block *sb, struct fid *fid,
ext2_nfs_get_inode); ext2_nfs_get_inode);
} }
/* Yes, most of these are left as NULL!!
* A NULL value implies the default, which works with ext2-like file
* systems, but can be improved upon.
* Currently only get_parent is required.
*/
static const struct export_operations ext2_export_ops = { static const struct export_operations ext2_export_ops = {
.fh_to_dentry = ext2_fh_to_dentry, .fh_to_dentry = ext2_fh_to_dentry,
.fh_to_parent = ext2_fh_to_parent, .fh_to_parent = ext2_fh_to_parent,
...@@ -1176,7 +1167,6 @@ static void ext2_sync_super(struct super_block *sb, struct ext2_super_block *es, ...@@ -1176,7 +1167,6 @@ static void ext2_sync_super(struct super_block *sb, struct ext2_super_block *es,
mark_buffer_dirty(EXT2_SB(sb)->s_sbh); mark_buffer_dirty(EXT2_SB(sb)->s_sbh);
if (wait) if (wait)
sync_dirty_buffer(EXT2_SB(sb)->s_sbh); sync_dirty_buffer(EXT2_SB(sb)->s_sbh);
sb->s_dirt = 0;
} }
/* /*
...@@ -1209,8 +1199,6 @@ void ext2_write_super(struct super_block *sb) ...@@ -1209,8 +1199,6 @@ void ext2_write_super(struct super_block *sb)
{ {
if (!(sb->s_flags & MS_RDONLY)) if (!(sb->s_flags & MS_RDONLY))
ext2_sync_fs(sb, 1); ext2_sync_fs(sb, 1);
else
sb->s_dirt = 0;
} }
static int ext2_remount (struct super_block * sb, int * flags, char * data) static int ext2_remount (struct super_block * sb, int * flags, char * data)
...@@ -1456,7 +1444,6 @@ static ssize_t ext2_quota_write(struct super_block *sb, int type, ...@@ -1456,7 +1444,6 @@ static ssize_t ext2_quota_write(struct super_block *sb, int type,
struct buffer_head tmp_bh; struct buffer_head tmp_bh;
struct buffer_head *bh; struct buffer_head *bh;
mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA);
while (towrite > 0) { while (towrite > 0) {
tocopy = sb->s_blocksize - offset < towrite ? tocopy = sb->s_blocksize - offset < towrite ?
sb->s_blocksize - offset : towrite; sb->s_blocksize - offset : towrite;
...@@ -1486,16 +1473,13 @@ static ssize_t ext2_quota_write(struct super_block *sb, int type, ...@@ -1486,16 +1473,13 @@ static ssize_t ext2_quota_write(struct super_block *sb, int type,
blk++; blk++;
} }
out: out:
if (len == towrite) { if (len == towrite)
mutex_unlock(&inode->i_mutex);
return err; return err;
}
if (inode->i_size < off+len-towrite) if (inode->i_size < off+len-towrite)
i_size_write(inode, off+len-towrite); i_size_write(inode, off+len-towrite);
inode->i_version++; inode->i_version++;
inode->i_mtime = inode->i_ctime = CURRENT_TIME; inode->i_mtime = inode->i_ctime = CURRENT_TIME;
mark_inode_dirty(inode); mark_inode_dirty(inode);
mutex_unlock(&inode->i_mutex);
return len - towrite; return len - towrite;
} }
......
...@@ -339,7 +339,6 @@ static void ext2_xattr_update_super_block(struct super_block *sb) ...@@ -339,7 +339,6 @@ static void ext2_xattr_update_super_block(struct super_block *sb)
spin_lock(&EXT2_SB(sb)->s_lock); spin_lock(&EXT2_SB(sb)->s_lock);
EXT2_SET_COMPAT_FEATURE(sb, EXT2_FEATURE_COMPAT_EXT_ATTR); EXT2_SET_COMPAT_FEATURE(sb, EXT2_FEATURE_COMPAT_EXT_ATTR);
spin_unlock(&EXT2_SB(sb)->s_lock); spin_unlock(&EXT2_SB(sb)->s_lock);
sb->s_dirt = 1;
mark_buffer_dirty(EXT2_SB(sb)->s_sbh); mark_buffer_dirty(EXT2_SB(sb)->s_sbh);
} }
......
...@@ -21,30 +21,15 @@ ...@@ -21,30 +21,15 @@
* *
*/ */
#include <linux/compat.h>
#include "ext3.h" #include "ext3.h"
static unsigned char ext3_filetype_table[] = { static unsigned char ext3_filetype_table[] = {
DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK DT_UNKNOWN, DT_REG, DT_DIR, DT_CHR, DT_BLK, DT_FIFO, DT_SOCK, DT_LNK
}; };
static int ext3_readdir(struct file *, void *, filldir_t);
static int ext3_dx_readdir(struct file * filp, static int ext3_dx_readdir(struct file * filp,
void * dirent, filldir_t filldir); void * dirent, filldir_t filldir);
static int ext3_release_dir (struct inode * inode,
struct file * filp);
const struct file_operations ext3_dir_operations = {
.llseek = generic_file_llseek,
.read = generic_read_dir,
.readdir = ext3_readdir, /* we take BKL. needed?*/
.unlocked_ioctl = ext3_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = ext3_compat_ioctl,
#endif
.fsync = ext3_sync_file, /* BKL held */
.release = ext3_release_dir,
};
static unsigned char get_dtype(struct super_block *sb, int filetype) static unsigned char get_dtype(struct super_block *sb, int filetype)
{ {
...@@ -55,6 +40,25 @@ static unsigned char get_dtype(struct super_block *sb, int filetype) ...@@ -55,6 +40,25 @@ static unsigned char get_dtype(struct super_block *sb, int filetype)
return (ext3_filetype_table[filetype]); return (ext3_filetype_table[filetype]);
} }
/**
* Check if the given dir-inode refers to an htree-indexed directory
* (or a directory which chould potentially get coverted to use htree
* indexing).
*
* Return 1 if it is a dx dir, 0 if not
*/
static int is_dx_dir(struct inode *inode)
{
struct super_block *sb = inode->i_sb;
if (EXT3_HAS_COMPAT_FEATURE(inode->i_sb,
EXT3_FEATURE_COMPAT_DIR_INDEX) &&
((EXT3_I(inode)->i_flags & EXT3_INDEX_FL) ||
((inode->i_size >> sb->s_blocksize_bits) == 1)))
return 1;
return 0;
}
int ext3_check_dir_entry (const char * function, struct inode * dir, int ext3_check_dir_entry (const char * function, struct inode * dir,
struct ext3_dir_entry_2 * de, struct ext3_dir_entry_2 * de,
...@@ -94,18 +98,13 @@ static int ext3_readdir(struct file * filp, ...@@ -94,18 +98,13 @@ static int ext3_readdir(struct file * filp,
unsigned long offset; unsigned long offset;
int i, stored; int i, stored;
struct ext3_dir_entry_2 *de; struct ext3_dir_entry_2 *de;
struct super_block *sb;
int err; int err;
struct inode *inode = filp->f_path.dentry->d_inode; struct inode *inode = filp->f_path.dentry->d_inode;
struct super_block *sb = inode->i_sb;
int ret = 0; int ret = 0;
int dir_has_error = 0; int dir_has_error = 0;
sb = inode->i_sb; if (is_dx_dir(inode)) {
if (EXT3_HAS_COMPAT_FEATURE(inode->i_sb,
EXT3_FEATURE_COMPAT_DIR_INDEX) &&
((EXT3_I(inode)->i_flags & EXT3_INDEX_FL) ||
((inode->i_size >> sb->s_blocksize_bits) == 1))) {
err = ext3_dx_readdir(filp, dirent, filldir); err = ext3_dx_readdir(filp, dirent, filldir);
if (err != ERR_BAD_DX_DIR) { if (err != ERR_BAD_DX_DIR) {
ret = err; ret = err;
...@@ -227,22 +226,87 @@ static int ext3_readdir(struct file * filp, ...@@ -227,22 +226,87 @@ static int ext3_readdir(struct file * filp,
return ret; return ret;
} }
static inline int is_32bit_api(void)
{
#ifdef CONFIG_COMPAT
return is_compat_task();
#else
return (BITS_PER_LONG == 32);
#endif
}
/* /*
* These functions convert from the major/minor hash to an f_pos * These functions convert from the major/minor hash to an f_pos
* value. * value for dx directories
* *
* Currently we only use major hash numer. This is unfortunate, but * Upper layer (for example NFS) should specify FMODE_32BITHASH or
* on 32-bit machines, the same VFS interface is used for lseek and * FMODE_64BITHASH explicitly. On the other hand, we allow ext3 to be mounted
* llseek, so if we use the 64 bit offset, then the 32-bit versions of * directly on both 32-bit and 64-bit nodes, under such case, neither
* lseek/telldir/seekdir will blow out spectacularly, and from within * FMODE_32BITHASH nor FMODE_64BITHASH is specified.
* the ext2 low-level routine, we don't know if we're being called by
* a 64-bit version of the system call or the 32-bit version of the
* system call. Worse yet, NFSv2 only allows for a 32-bit readdir
* cookie. Sigh.
*/ */
#define hash2pos(major, minor) (major >> 1) static inline loff_t hash2pos(struct file *filp, __u32 major, __u32 minor)
#define pos2maj_hash(pos) ((pos << 1) & 0xffffffff) {
#define pos2min_hash(pos) (0) if ((filp->f_mode & FMODE_32BITHASH) ||
(!(filp->f_mode & FMODE_64BITHASH) && is_32bit_api()))
return major >> 1;
else
return ((__u64)(major >> 1) << 32) | (__u64)minor;
}
static inline __u32 pos2maj_hash(struct file *filp, loff_t pos)
{
if ((filp->f_mode & FMODE_32BITHASH) ||
(!(filp->f_mode & FMODE_64BITHASH) && is_32bit_api()))
return (pos << 1) & 0xffffffff;
else
return ((pos >> 32) << 1) & 0xffffffff;
}
static inline __u32 pos2min_hash(struct file *filp, loff_t pos)
{
if ((filp->f_mode & FMODE_32BITHASH) ||
(!(filp->f_mode & FMODE_64BITHASH) && is_32bit_api()))
return 0;
else
return pos & 0xffffffff;
}
/*
* Return 32- or 64-bit end-of-file for dx directories
*/
static inline loff_t ext3_get_htree_eof(struct file *filp)
{
if ((filp->f_mode & FMODE_32BITHASH) ||
(!(filp->f_mode & FMODE_64BITHASH) && is_32bit_api()))
return EXT3_HTREE_EOF_32BIT;
else
return EXT3_HTREE_EOF_64BIT;
}
/*
* ext3_dir_llseek() calls generic_file_llseek[_size]() to handle both
* non-htree and htree directories, where the "offset" is in terms
* of the filename hash value instead of the byte offset.
*
* Because we may return a 64-bit hash that is well beyond s_maxbytes,
* we need to pass the max hash as the maximum allowable offset in
* the htree directory case.
*
* NOTE: offsets obtained *before* ext3_set_inode_flag(dir, EXT3_INODE_INDEX)
* will be invalid once the directory was converted into a dx directory
*/
loff_t ext3_dir_llseek(struct file *file, loff_t offset, int origin)
{
struct inode *inode = file->f_mapping->host;
int dx_dir = is_dx_dir(inode);
if (likely(dx_dir))
return generic_file_llseek_size(file, offset, origin,
ext3_get_htree_eof(file));
else
return generic_file_llseek(file, offset, origin);
}
/* /*
* This structure holds the nodes of the red-black tree used to store * This structure holds the nodes of the red-black tree used to store
...@@ -303,15 +367,16 @@ static void free_rb_tree_fname(struct rb_root *root) ...@@ -303,15 +367,16 @@ static void free_rb_tree_fname(struct rb_root *root)
} }
static struct dir_private_info *ext3_htree_create_dir_info(loff_t pos) static struct dir_private_info *ext3_htree_create_dir_info(struct file *filp,
loff_t pos)
{ {
struct dir_private_info *p; struct dir_private_info *p;
p = kzalloc(sizeof(struct dir_private_info), GFP_KERNEL); p = kzalloc(sizeof(struct dir_private_info), GFP_KERNEL);
if (!p) if (!p)
return NULL; return NULL;
p->curr_hash = pos2maj_hash(pos); p->curr_hash = pos2maj_hash(filp, pos);
p->curr_minor_hash = pos2min_hash(pos); p->curr_minor_hash = pos2min_hash(filp, pos);
return p; return p;
} }
...@@ -401,7 +466,7 @@ static int call_filldir(struct file * filp, void * dirent, ...@@ -401,7 +466,7 @@ static int call_filldir(struct file * filp, void * dirent,
printk("call_filldir: called with null fname?!?\n"); printk("call_filldir: called with null fname?!?\n");
return 0; return 0;
} }
curr_pos = hash2pos(fname->hash, fname->minor_hash); curr_pos = hash2pos(filp, fname->hash, fname->minor_hash);
while (fname) { while (fname) {
error = filldir(dirent, fname->name, error = filldir(dirent, fname->name,
fname->name_len, curr_pos, fname->name_len, curr_pos,
...@@ -426,13 +491,13 @@ static int ext3_dx_readdir(struct file * filp, ...@@ -426,13 +491,13 @@ static int ext3_dx_readdir(struct file * filp,
int ret; int ret;
if (!info) { if (!info) {
info = ext3_htree_create_dir_info(filp->f_pos); info = ext3_htree_create_dir_info(filp, filp->f_pos);
if (!info) if (!info)
return -ENOMEM; return -ENOMEM;
filp->private_data = info; filp->private_data = info;
} }
if (filp->f_pos == EXT3_HTREE_EOF) if (filp->f_pos == ext3_get_htree_eof(filp))
return 0; /* EOF */ return 0; /* EOF */
/* Some one has messed with f_pos; reset the world */ /* Some one has messed with f_pos; reset the world */
...@@ -440,8 +505,8 @@ static int ext3_dx_readdir(struct file * filp, ...@@ -440,8 +505,8 @@ static int ext3_dx_readdir(struct file * filp,
free_rb_tree_fname(&info->root); free_rb_tree_fname(&info->root);
info->curr_node = NULL; info->curr_node = NULL;
info->extra_fname = NULL; info->extra_fname = NULL;
info->curr_hash = pos2maj_hash(filp->f_pos); info->curr_hash = pos2maj_hash(filp, filp->f_pos);
info->curr_minor_hash = pos2min_hash(filp->f_pos); info->curr_minor_hash = pos2min_hash(filp, filp->f_pos);
} }
/* /*
...@@ -473,7 +538,7 @@ static int ext3_dx_readdir(struct file * filp, ...@@ -473,7 +538,7 @@ static int ext3_dx_readdir(struct file * filp,
if (ret < 0) if (ret < 0)
return ret; return ret;
if (ret == 0) { if (ret == 0) {
filp->f_pos = EXT3_HTREE_EOF; filp->f_pos = ext3_get_htree_eof(filp);
break; break;
} }
info->curr_node = rb_first(&info->root); info->curr_node = rb_first(&info->root);
...@@ -493,7 +558,7 @@ static int ext3_dx_readdir(struct file * filp, ...@@ -493,7 +558,7 @@ static int ext3_dx_readdir(struct file * filp,
info->curr_minor_hash = fname->minor_hash; info->curr_minor_hash = fname->minor_hash;
} else { } else {
if (info->next_hash == ~0) { if (info->next_hash == ~0) {
filp->f_pos = EXT3_HTREE_EOF; filp->f_pos = ext3_get_htree_eof(filp);
break; break;
} }
info->curr_hash = info->next_hash; info->curr_hash = info->next_hash;
...@@ -512,3 +577,15 @@ static int ext3_release_dir (struct inode * inode, struct file * filp) ...@@ -512,3 +577,15 @@ static int ext3_release_dir (struct inode * inode, struct file * filp)
return 0; return 0;
} }
const struct file_operations ext3_dir_operations = {
.llseek = ext3_dir_llseek,
.read = generic_read_dir,
.readdir = ext3_readdir,
.unlocked_ioctl = ext3_ioctl,
#ifdef CONFIG_COMPAT
.compat_ioctl = ext3_compat_ioctl,
#endif
.fsync = ext3_sync_file,
.release = ext3_release_dir,
};
...@@ -920,7 +920,11 @@ struct dx_hash_info ...@@ -920,7 +920,11 @@ struct dx_hash_info
u32 *seed; u32 *seed;
}; };
#define EXT3_HTREE_EOF 0x7fffffff
/* 32 and 64 bit signed EOF for dx directories */
#define EXT3_HTREE_EOF_32BIT ((1UL << (32 - 1)) - 1)
#define EXT3_HTREE_EOF_64BIT ((1ULL << (64 - 1)) - 1)
/* /*
* Control parameters used by ext3_htree_next_block * Control parameters used by ext3_htree_next_block
......
...@@ -198,8 +198,8 @@ int ext3fs_dirhash(const char *name, int len, struct dx_hash_info *hinfo) ...@@ -198,8 +198,8 @@ int ext3fs_dirhash(const char *name, int len, struct dx_hash_info *hinfo)
return -1; return -1;
} }
hash = hash & ~1; hash = hash & ~1;
if (hash == (EXT3_HTREE_EOF << 1)) if (hash == (EXT3_HTREE_EOF_32BIT << 1))
hash = (EXT3_HTREE_EOF-1) << 1; hash = (EXT3_HTREE_EOF_32BIT - 1) << 1;
hinfo->hash = hash; hinfo->hash = hash;
hinfo->minor_hash = minor_hash; hinfo->minor_hash = minor_hash;
return 0; return 0;
......
...@@ -180,8 +180,7 @@ void ext3_free_inode (handle_t *handle, struct inode * inode) ...@@ -180,8 +180,7 @@ void ext3_free_inode (handle_t *handle, struct inode * inode)
* It's OK to put directory into a group unless * It's OK to put directory into a group unless
* it has too many directories already (max_dirs) or * it has too many directories already (max_dirs) or
* it has too few free inodes left (min_inodes) or * it has too few free inodes left (min_inodes) or
* it has too few free blocks left (min_blocks) or * it has too few free blocks left (min_blocks).
* it's already running too large debt (max_debt).
* Parent's group is preferred, if it doesn't satisfy these * Parent's group is preferred, if it doesn't satisfy these
* conditions we search cyclically through the rest. If none * conditions we search cyclically through the rest. If none
* of the groups look good we just look for a group with more * of the groups look good we just look for a group with more
...@@ -191,21 +190,16 @@ void ext3_free_inode (handle_t *handle, struct inode * inode) ...@@ -191,21 +190,16 @@ void ext3_free_inode (handle_t *handle, struct inode * inode)
* when we allocate an inode, within 0--255. * when we allocate an inode, within 0--255.
*/ */
#define INODE_COST 64
#define BLOCK_COST 256
static int find_group_orlov(struct super_block *sb, struct inode *parent) static int find_group_orlov(struct super_block *sb, struct inode *parent)
{ {
int parent_group = EXT3_I(parent)->i_block_group; int parent_group = EXT3_I(parent)->i_block_group;
struct ext3_sb_info *sbi = EXT3_SB(sb); struct ext3_sb_info *sbi = EXT3_SB(sb);
struct ext3_super_block *es = sbi->s_es;
int ngroups = sbi->s_groups_count; int ngroups = sbi->s_groups_count;
int inodes_per_group = EXT3_INODES_PER_GROUP(sb); int inodes_per_group = EXT3_INODES_PER_GROUP(sb);
unsigned int freei, avefreei; unsigned int freei, avefreei;
ext3_fsblk_t freeb, avefreeb; ext3_fsblk_t freeb, avefreeb;
ext3_fsblk_t blocks_per_dir;
unsigned int ndirs; unsigned int ndirs;
int max_debt, max_dirs, min_inodes; int max_dirs, min_inodes;
ext3_grpblk_t min_blocks; ext3_grpblk_t min_blocks;
int group = -1, i; int group = -1, i;
struct ext3_group_desc *desc; struct ext3_group_desc *desc;
...@@ -242,20 +236,10 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent) ...@@ -242,20 +236,10 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent)
goto fallback; goto fallback;
} }
blocks_per_dir = (le32_to_cpu(es->s_blocks_count) - freeb) / ndirs;
max_dirs = ndirs / ngroups + inodes_per_group / 16; max_dirs = ndirs / ngroups + inodes_per_group / 16;
min_inodes = avefreei - inodes_per_group / 4; min_inodes = avefreei - inodes_per_group / 4;
min_blocks = avefreeb - EXT3_BLOCKS_PER_GROUP(sb) / 4; min_blocks = avefreeb - EXT3_BLOCKS_PER_GROUP(sb) / 4;
max_debt = EXT3_BLOCKS_PER_GROUP(sb) / max(blocks_per_dir, (ext3_fsblk_t)BLOCK_COST);
if (max_debt * INODE_COST > inodes_per_group)
max_debt = inodes_per_group / INODE_COST;
if (max_debt > 255)
max_debt = 255;
if (max_debt == 0)
max_debt = 1;
for (i = 0; i < ngroups; i++) { for (i = 0; i < ngroups; i++) {
group = (parent_group + i) % ngroups; group = (parent_group + i) % ngroups;
desc = ext3_get_group_desc (sb, group, NULL); desc = ext3_get_group_desc (sb, group, NULL);
......
...@@ -3015,7 +3015,6 @@ static ssize_t ext3_quota_write(struct super_block *sb, int type, ...@@ -3015,7 +3015,6 @@ static ssize_t ext3_quota_write(struct super_block *sb, int type,
(unsigned long long)off, (unsigned long long)len); (unsigned long long)off, (unsigned long long)len);
return -EIO; return -EIO;
} }
mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA);
bh = ext3_bread(handle, inode, blk, 1, &err); bh = ext3_bread(handle, inode, blk, 1, &err);
if (!bh) if (!bh)
goto out; goto out;
...@@ -3039,10 +3038,8 @@ static ssize_t ext3_quota_write(struct super_block *sb, int type, ...@@ -3039,10 +3038,8 @@ static ssize_t ext3_quota_write(struct super_block *sb, int type,
} }
brelse(bh); brelse(bh);
out: out:
if (err) { if (err)
mutex_unlock(&inode->i_mutex);
return err; return err;
}
if (inode->i_size < off + len) { if (inode->i_size < off + len) {
i_size_write(inode, off + len); i_size_write(inode, off + len);
EXT3_I(inode)->i_disksize = inode->i_size; EXT3_I(inode)->i_disksize = inode->i_size;
...@@ -3050,7 +3047,6 @@ static ssize_t ext3_quota_write(struct super_block *sb, int type, ...@@ -3050,7 +3047,6 @@ static ssize_t ext3_quota_write(struct super_block *sb, int type,
inode->i_version++; inode->i_version++;
inode->i_mtime = inode->i_ctime = CURRENT_TIME; inode->i_mtime = inode->i_ctime = CURRENT_TIME;
ext3_mark_inode_dirty(handle, inode); ext3_mark_inode_dirty(handle, inode);
mutex_unlock(&inode->i_mutex);
return len; return len;
} }
......
...@@ -4758,7 +4758,6 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type, ...@@ -4758,7 +4758,6 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,
return -EIO; return -EIO;
} }
mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA);
bh = ext4_bread(handle, inode, blk, 1, &err); bh = ext4_bread(handle, inode, blk, 1, &err);
if (!bh) if (!bh)
goto out; goto out;
...@@ -4774,16 +4773,13 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type, ...@@ -4774,16 +4773,13 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,
err = ext4_handle_dirty_metadata(handle, NULL, bh); err = ext4_handle_dirty_metadata(handle, NULL, bh);
brelse(bh); brelse(bh);
out: out:
if (err) { if (err)
mutex_unlock(&inode->i_mutex);
return err; return err;
}
if (inode->i_size < off + len) { if (inode->i_size < off + len) {
i_size_write(inode, off + len); i_size_write(inode, off + len);
EXT4_I(inode)->i_disksize = inode->i_size; EXT4_I(inode)->i_disksize = inode->i_size;
ext4_mark_inode_dirty(handle, inode); ext4_mark_inode_dirty(handle, inode);
} }
mutex_unlock(&inode->i_mutex);
return len; return len;
} }
......
...@@ -508,20 +508,19 @@ int cleanup_journal_tail(journal_t *journal) ...@@ -508,20 +508,19 @@ int cleanup_journal_tail(journal_t *journal)
/* /*
* We need to make sure that any blocks that were recently written out * We need to make sure that any blocks that were recently written out
* --- perhaps by log_do_checkpoint() --- are flushed out before we * --- perhaps by log_do_checkpoint() --- are flushed out before we
* drop the transactions from the journal. It's unlikely this will be * drop the transactions from the journal. Similarly we need to be sure
* necessary, especially with an appropriately sized journal, but we * superblock makes it to disk before next transaction starts reusing
* need this to guarantee correctness. Fortunately * freed space (otherwise we could replay some blocks of the new
* cleanup_journal_tail() doesn't get called all that often. * transaction thinking they belong to the old one). So we use
* WRITE_FLUSH_FUA. It's unlikely this will be necessary, especially
* with an appropriately sized journal, but we need this to guarantee
* correctness. Fortunately cleanup_journal_tail() doesn't get called
* all that often.
*/ */
if (journal->j_flags & JFS_BARRIER) journal_update_sb_log_tail(journal, first_tid, blocknr,
blkdev_issue_flush(journal->j_fs_dev, GFP_KERNEL, NULL); WRITE_FLUSH_FUA);
spin_lock(&journal->j_state_lock); spin_lock(&journal->j_state_lock);
if (!tid_gt(first_tid, journal->j_tail_sequence)) {
spin_unlock(&journal->j_state_lock);
/* Someone else cleaned up journal so return 0 */
return 0;
}
/* OK, update the superblock to recover the freed space. /* OK, update the superblock to recover the freed space.
* Physical blocks come first: have we wrapped beyond the end of * Physical blocks come first: have we wrapped beyond the end of
* the log? */ * the log? */
...@@ -539,8 +538,6 @@ int cleanup_journal_tail(journal_t *journal) ...@@ -539,8 +538,6 @@ int cleanup_journal_tail(journal_t *journal)
journal->j_tail_sequence = first_tid; journal->j_tail_sequence = first_tid;
journal->j_tail = blocknr; journal->j_tail = blocknr;
spin_unlock(&journal->j_state_lock); spin_unlock(&journal->j_state_lock);
if (!(journal->j_flags & JFS_ABORT))
journal_update_superblock(journal, 1);
return 0; return 0;
} }
......
...@@ -298,6 +298,7 @@ void journal_commit_transaction(journal_t *journal) ...@@ -298,6 +298,7 @@ void journal_commit_transaction(journal_t *journal)
int tag_flag; int tag_flag;
int i; int i;
struct blk_plug plug; struct blk_plug plug;
int write_op = WRITE;
/* /*
* First job: lock down the current transaction and wait for * First job: lock down the current transaction and wait for
...@@ -307,7 +308,16 @@ void journal_commit_transaction(journal_t *journal) ...@@ -307,7 +308,16 @@ void journal_commit_transaction(journal_t *journal)
/* Do we need to erase the effects of a prior journal_flush? */ /* Do we need to erase the effects of a prior journal_flush? */
if (journal->j_flags & JFS_FLUSHED) { if (journal->j_flags & JFS_FLUSHED) {
jbd_debug(3, "super block updated\n"); jbd_debug(3, "super block updated\n");
journal_update_superblock(journal, 1); mutex_lock(&journal->j_checkpoint_mutex);
/*
* We hold j_checkpoint_mutex so tail cannot change under us.
* We don't need any special data guarantees for writing sb
* since journal is empty and it is ok for write to be
* flushed only with transaction commit.
*/
journal_update_sb_log_tail(journal, journal->j_tail_sequence,
journal->j_tail, WRITE_SYNC);
mutex_unlock(&journal->j_checkpoint_mutex);
} else { } else {
jbd_debug(3, "superblock not updated\n"); jbd_debug(3, "superblock not updated\n");
} }
...@@ -413,13 +423,16 @@ void journal_commit_transaction(journal_t *journal) ...@@ -413,13 +423,16 @@ void journal_commit_transaction(journal_t *journal)
jbd_debug (3, "JBD: commit phase 2\n"); jbd_debug (3, "JBD: commit phase 2\n");
if (tid_geq(journal->j_commit_waited, commit_transaction->t_tid))
write_op = WRITE_SYNC;
/* /*
* Now start flushing things to disk, in the order they appear * Now start flushing things to disk, in the order they appear
* on the transaction lists. Data blocks go first. * on the transaction lists. Data blocks go first.
*/ */
blk_start_plug(&plug); blk_start_plug(&plug);
err = journal_submit_data_buffers(journal, commit_transaction, err = journal_submit_data_buffers(journal, commit_transaction,
WRITE_SYNC); write_op);
blk_finish_plug(&plug); blk_finish_plug(&plug);
/* /*
...@@ -478,7 +491,7 @@ void journal_commit_transaction(journal_t *journal) ...@@ -478,7 +491,7 @@ void journal_commit_transaction(journal_t *journal)
blk_start_plug(&plug); blk_start_plug(&plug);
journal_write_revoke_records(journal, commit_transaction, WRITE_SYNC); journal_write_revoke_records(journal, commit_transaction, write_op);
/* /*
* If we found any dirty or locked buffers, then we should have * If we found any dirty or locked buffers, then we should have
...@@ -649,7 +662,7 @@ void journal_commit_transaction(journal_t *journal) ...@@ -649,7 +662,7 @@ void journal_commit_transaction(journal_t *journal)
clear_buffer_dirty(bh); clear_buffer_dirty(bh);
set_buffer_uptodate(bh); set_buffer_uptodate(bh);
bh->b_end_io = journal_end_buffer_io_sync; bh->b_end_io = journal_end_buffer_io_sync;
submit_bh(WRITE_SYNC, bh); submit_bh(write_op, bh);
} }
cond_resched(); cond_resched();
......
...@@ -563,6 +563,8 @@ int log_wait_commit(journal_t *journal, tid_t tid) ...@@ -563,6 +563,8 @@ int log_wait_commit(journal_t *journal, tid_t tid)
spin_unlock(&journal->j_state_lock); spin_unlock(&journal->j_state_lock);
#endif #endif
spin_lock(&journal->j_state_lock); spin_lock(&journal->j_state_lock);
if (!tid_geq(journal->j_commit_waited, tid))
journal->j_commit_waited = tid;
while (tid_gt(tid, journal->j_commit_sequence)) { while (tid_gt(tid, journal->j_commit_sequence)) {
jbd_debug(1, "JBD: want %d, j_commit_sequence=%d\n", jbd_debug(1, "JBD: want %d, j_commit_sequence=%d\n",
tid, journal->j_commit_sequence); tid, journal->j_commit_sequence);
...@@ -921,8 +923,33 @@ static int journal_reset(journal_t *journal) ...@@ -921,8 +923,33 @@ static int journal_reset(journal_t *journal)
journal->j_max_transaction_buffers = journal->j_maxlen / 4; journal->j_max_transaction_buffers = journal->j_maxlen / 4;
/* Add the dynamic fields and write it to disk. */ /*
journal_update_superblock(journal, 1); * As a special case, if the on-disk copy is already marked as needing
* no recovery (s_start == 0), then we can safely defer the superblock
* update until the next commit by setting JFS_FLUSHED. This avoids
* attempting a write to a potential-readonly device.
*/
if (sb->s_start == 0) {
jbd_debug(1,"JBD: Skipping superblock update on recovered sb "
"(start %u, seq %d, errno %d)\n",
journal->j_tail, journal->j_tail_sequence,
journal->j_errno);
journal->j_flags |= JFS_FLUSHED;
} else {
/* Lock here to make assertions happy... */
mutex_lock(&journal->j_checkpoint_mutex);
/*
* Update log tail information. We use WRITE_FUA since new
* transaction will start reusing journal space and so we
* must make sure information about current log tail is on
* disk before that.
*/
journal_update_sb_log_tail(journal,
journal->j_tail_sequence,
journal->j_tail,
WRITE_FUA);
mutex_unlock(&journal->j_checkpoint_mutex);
}
return journal_start_thread(journal); return journal_start_thread(journal);
} }
...@@ -999,35 +1026,15 @@ int journal_create(journal_t *journal) ...@@ -999,35 +1026,15 @@ int journal_create(journal_t *journal)
return journal_reset(journal); return journal_reset(journal);
} }
/** static void journal_write_superblock(journal_t *journal, int write_op)
* void journal_update_superblock() - Update journal sb on disk.
* @journal: The journal to update.
* @wait: Set to '0' if you don't want to wait for IO completion.
*
* Update a journal's dynamic superblock fields and write it to disk,
* optionally waiting for the IO to complete.
*/
void journal_update_superblock(journal_t *journal, int wait)
{ {
journal_superblock_t *sb = journal->j_superblock;
struct buffer_head *bh = journal->j_sb_buffer; struct buffer_head *bh = journal->j_sb_buffer;
int ret;
/* trace_journal_write_superblock(journal, write_op);
* As a special case, if the on-disk copy is already marked as needing if (!(journal->j_flags & JFS_BARRIER))
* no recovery (s_start == 0) and there are no outstanding transactions write_op &= ~(REQ_FUA | REQ_FLUSH);
* in the filesystem, then we can safely defer the superblock update lock_buffer(bh);
* until the next commit by setting JFS_FLUSHED. This avoids
* attempting a write to a potential-readonly device.
*/
if (sb->s_start == 0 && journal->j_tail_sequence ==
journal->j_transaction_sequence) {
jbd_debug(1,"JBD: Skipping superblock update on recovered sb "
"(start %u, seq %d, errno %d)\n",
journal->j_tail, journal->j_tail_sequence,
journal->j_errno);
goto out;
}
if (buffer_write_io_error(bh)) { if (buffer_write_io_error(bh)) {
char b[BDEVNAME_SIZE]; char b[BDEVNAME_SIZE];
/* /*
...@@ -1045,42 +1052,100 @@ void journal_update_superblock(journal_t *journal, int wait) ...@@ -1045,42 +1052,100 @@ void journal_update_superblock(journal_t *journal, int wait)
set_buffer_uptodate(bh); set_buffer_uptodate(bh);
} }
get_bh(bh);
bh->b_end_io = end_buffer_write_sync;
ret = submit_bh(write_op, bh);
wait_on_buffer(bh);
if (buffer_write_io_error(bh)) {
clear_buffer_write_io_error(bh);
set_buffer_uptodate(bh);
ret = -EIO;
}
if (ret) {
char b[BDEVNAME_SIZE];
printk(KERN_ERR "JBD: Error %d detected "
"when updating journal superblock for %s.\n",
ret, journal_dev_name(journal, b));
}
}
/**
* journal_update_sb_log_tail() - Update log tail in journal sb on disk.
* @journal: The journal to update.
* @tail_tid: TID of the new transaction at the tail of the log
* @tail_block: The first block of the transaction at the tail of the log
* @write_op: With which operation should we write the journal sb
*
* Update a journal's superblock information about log tail and write it to
* disk, waiting for the IO to complete.
*/
void journal_update_sb_log_tail(journal_t *journal, tid_t tail_tid,
unsigned int tail_block, int write_op)
{
journal_superblock_t *sb = journal->j_superblock;
BUG_ON(!mutex_is_locked(&journal->j_checkpoint_mutex));
jbd_debug(1,"JBD: updating superblock (start %u, seq %u)\n",
tail_block, tail_tid);
sb->s_sequence = cpu_to_be32(tail_tid);
sb->s_start = cpu_to_be32(tail_block);
journal_write_superblock(journal, write_op);
/* Log is no longer empty */
spin_lock(&journal->j_state_lock);
WARN_ON(!sb->s_sequence);
journal->j_flags &= ~JFS_FLUSHED;
spin_unlock(&journal->j_state_lock);
}
/**
* mark_journal_empty() - Mark on disk journal as empty.
* @journal: The journal to update.
*
* Update a journal's dynamic superblock fields to show that journal is empty.
* Write updated superblock to disk waiting for IO to complete.
*/
static void mark_journal_empty(journal_t *journal)
{
journal_superblock_t *sb = journal->j_superblock;
BUG_ON(!mutex_is_locked(&journal->j_checkpoint_mutex));
spin_lock(&journal->j_state_lock); spin_lock(&journal->j_state_lock);
jbd_debug(1,"JBD: updating superblock (start %u, seq %d, errno %d)\n", jbd_debug(1, "JBD: Marking journal as empty (seq %d)\n",
journal->j_tail, journal->j_tail_sequence, journal->j_errno); journal->j_tail_sequence);
sb->s_sequence = cpu_to_be32(journal->j_tail_sequence); sb->s_sequence = cpu_to_be32(journal->j_tail_sequence);
sb->s_start = cpu_to_be32(journal->j_tail); sb->s_start = cpu_to_be32(0);
sb->s_errno = cpu_to_be32(journal->j_errno);
spin_unlock(&journal->j_state_lock); spin_unlock(&journal->j_state_lock);
BUFFER_TRACE(bh, "marking dirty"); journal_write_superblock(journal, WRITE_FUA);
mark_buffer_dirty(bh);
if (wait) {
sync_dirty_buffer(bh);
if (buffer_write_io_error(bh)) {
char b[BDEVNAME_SIZE];
printk(KERN_ERR "JBD: I/O error detected "
"when updating journal superblock for %s.\n",
journal_dev_name(journal, b));
clear_buffer_write_io_error(bh);
set_buffer_uptodate(bh);
}
} else
write_dirty_buffer(bh, WRITE);
trace_jbd_update_superblock_end(journal, wait); spin_lock(&journal->j_state_lock);
out: /* Log is empty */
/* If we have just flushed the log (by marking s_start==0), then journal->j_flags |= JFS_FLUSHED;
* any future commit will have to be careful to update the spin_unlock(&journal->j_state_lock);
* superblock again to re-record the true start of the log. */ }
/**
* journal_update_sb_errno() - Update error in the journal.
* @journal: The journal to update.
*
* Update a journal's errno. Write updated superblock to disk waiting for IO
* to complete.
*/
static void journal_update_sb_errno(journal_t *journal)
{
journal_superblock_t *sb = journal->j_superblock;
spin_lock(&journal->j_state_lock); spin_lock(&journal->j_state_lock);
if (sb->s_start) jbd_debug(1, "JBD: updating superblock error (errno %d)\n",
journal->j_flags &= ~JFS_FLUSHED; journal->j_errno);
else sb->s_errno = cpu_to_be32(journal->j_errno);
journal->j_flags |= JFS_FLUSHED;
spin_unlock(&journal->j_state_lock); spin_unlock(&journal->j_state_lock);
journal_write_superblock(journal, WRITE_SYNC);
} }
/* /*
...@@ -1251,6 +1316,8 @@ int journal_destroy(journal_t *journal) ...@@ -1251,6 +1316,8 @@ int journal_destroy(journal_t *journal)
/* Force any old transactions to disk */ /* Force any old transactions to disk */
/* We cannot race with anybody but must keep assertions happy */
mutex_lock(&journal->j_checkpoint_mutex);
/* Totally anal locking here... */ /* Totally anal locking here... */
spin_lock(&journal->j_list_lock); spin_lock(&journal->j_list_lock);
while (journal->j_checkpoint_transactions != NULL) { while (journal->j_checkpoint_transactions != NULL) {
...@@ -1266,16 +1333,14 @@ int journal_destroy(journal_t *journal) ...@@ -1266,16 +1333,14 @@ int journal_destroy(journal_t *journal)
if (journal->j_sb_buffer) { if (journal->j_sb_buffer) {
if (!is_journal_aborted(journal)) { if (!is_journal_aborted(journal)) {
/* We can now mark the journal as empty. */
journal->j_tail = 0;
journal->j_tail_sequence = journal->j_tail_sequence =
++journal->j_transaction_sequence; ++journal->j_transaction_sequence;
journal_update_superblock(journal, 1); mark_journal_empty(journal);
} else { } else
err = -EIO; err = -EIO;
}
brelse(journal->j_sb_buffer); brelse(journal->j_sb_buffer);
} }
mutex_unlock(&journal->j_checkpoint_mutex);
if (journal->j_inode) if (journal->j_inode)
iput(journal->j_inode); iput(journal->j_inode);
...@@ -1455,7 +1520,6 @@ int journal_flush(journal_t *journal) ...@@ -1455,7 +1520,6 @@ int journal_flush(journal_t *journal)
{ {
int err = 0; int err = 0;
transaction_t *transaction = NULL; transaction_t *transaction = NULL;
unsigned int old_tail;
spin_lock(&journal->j_state_lock); spin_lock(&journal->j_state_lock);
...@@ -1490,6 +1554,7 @@ int journal_flush(journal_t *journal) ...@@ -1490,6 +1554,7 @@ int journal_flush(journal_t *journal)
if (is_journal_aborted(journal)) if (is_journal_aborted(journal))
return -EIO; return -EIO;
mutex_lock(&journal->j_checkpoint_mutex);
cleanup_journal_tail(journal); cleanup_journal_tail(journal);
/* Finally, mark the journal as really needing no recovery. /* Finally, mark the journal as really needing no recovery.
...@@ -1497,14 +1562,9 @@ int journal_flush(journal_t *journal) ...@@ -1497,14 +1562,9 @@ int journal_flush(journal_t *journal)
* the magic code for a fully-recovered superblock. Any future * the magic code for a fully-recovered superblock. Any future
* commits of data to the journal will restore the current * commits of data to the journal will restore the current
* s_start value. */ * s_start value. */
mark_journal_empty(journal);
mutex_unlock(&journal->j_checkpoint_mutex);
spin_lock(&journal->j_state_lock); spin_lock(&journal->j_state_lock);
old_tail = journal->j_tail;
journal->j_tail = 0;
spin_unlock(&journal->j_state_lock);
journal_update_superblock(journal, 1);
spin_lock(&journal->j_state_lock);
journal->j_tail = old_tail;
J_ASSERT(!journal->j_running_transaction); J_ASSERT(!journal->j_running_transaction);
J_ASSERT(!journal->j_committing_transaction); J_ASSERT(!journal->j_committing_transaction);
J_ASSERT(!journal->j_checkpoint_transactions); J_ASSERT(!journal->j_checkpoint_transactions);
...@@ -1544,8 +1604,12 @@ int journal_wipe(journal_t *journal, int write) ...@@ -1544,8 +1604,12 @@ int journal_wipe(journal_t *journal, int write)
write ? "Clearing" : "Ignoring"); write ? "Clearing" : "Ignoring");
err = journal_skip_recovery(journal); err = journal_skip_recovery(journal);
if (write) if (write) {
journal_update_superblock(journal, 1); /* Lock to make assertions happy... */
mutex_lock(&journal->j_checkpoint_mutex);
mark_journal_empty(journal);
mutex_unlock(&journal->j_checkpoint_mutex);
}
no_recovery: no_recovery:
return err; return err;
...@@ -1613,7 +1677,7 @@ static void __journal_abort_soft (journal_t *journal, int errno) ...@@ -1613,7 +1677,7 @@ static void __journal_abort_soft (journal_t *journal, int errno)
__journal_abort_hard(journal); __journal_abort_hard(journal);
if (errno) if (errno)
journal_update_superblock(journal, 1); journal_update_sb_errno(journal);
} }
/** /**
......
...@@ -1433,8 +1433,6 @@ int journal_stop(handle_t *handle) ...@@ -1433,8 +1433,6 @@ int journal_stop(handle_t *handle)
} }
} }
if (handle->h_sync)
transaction->t_synchronous_commit = 1;
current->journal_info = NULL; current->journal_info = NULL;
spin_lock(&journal->j_state_lock); spin_lock(&journal->j_state_lock);
spin_lock(&transaction->t_handle_lock); spin_lock(&transaction->t_handle_lock);
......
...@@ -116,15 +116,15 @@ ...@@ -116,15 +116,15 @@
* spinlock to internal buffers before writing. * spinlock to internal buffers before writing.
* *
* Lock ordering (including related VFS locks) is the following: * Lock ordering (including related VFS locks) is the following:
* i_mutex > dqonoff_sem > journal_lock > dqptr_sem > dquot->dq_lock > * dqonoff_mutex > i_mutex > journal_lock > dqptr_sem > dquot->dq_lock >
* dqio_mutex * dqio_mutex
* dqonoff_mutex > i_mutex comes from dquot_quota_sync, dquot_enable, etc.
* The lock ordering of dqptr_sem imposed by quota code is only dqonoff_sem > * The lock ordering of dqptr_sem imposed by quota code is only dqonoff_sem >
* dqptr_sem. But filesystem has to count with the fact that functions such as * dqptr_sem. But filesystem has to count with the fact that functions such as
* dquot_alloc_space() acquire dqptr_sem and they usually have to be called * dquot_alloc_space() acquire dqptr_sem and they usually have to be called
* from inside a transaction to keep filesystem consistency after a crash. Also * from inside a transaction to keep filesystem consistency after a crash. Also
* filesystems usually want to do some IO on dquot from ->mark_dirty which is * filesystems usually want to do some IO on dquot from ->mark_dirty which is
* called with dqptr_sem held. * called with dqptr_sem held.
* i_mutex on quota files is special (it's below dqio_mutex)
*/ */
static __cacheline_aligned_in_smp DEFINE_SPINLOCK(dq_list_lock); static __cacheline_aligned_in_smp DEFINE_SPINLOCK(dq_list_lock);
...@@ -638,7 +638,7 @@ int dquot_quota_sync(struct super_block *sb, int type, int wait) ...@@ -638,7 +638,7 @@ int dquot_quota_sync(struct super_block *sb, int type, int wait)
dqstats_inc(DQST_SYNCS); dqstats_inc(DQST_SYNCS);
mutex_unlock(&dqopt->dqonoff_mutex); mutex_unlock(&dqopt->dqonoff_mutex);
if (!wait || (sb_dqopt(sb)->flags & DQUOT_QUOTA_SYS_FILE)) if (!wait || (dqopt->flags & DQUOT_QUOTA_SYS_FILE))
return 0; return 0;
/* This is not very clever (and fast) but currently I don't know about /* This is not very clever (and fast) but currently I don't know about
...@@ -652,18 +652,17 @@ int dquot_quota_sync(struct super_block *sb, int type, int wait) ...@@ -652,18 +652,17 @@ int dquot_quota_sync(struct super_block *sb, int type, int wait)
* Now when everything is written we can discard the pagecache so * Now when everything is written we can discard the pagecache so
* that userspace sees the changes. * that userspace sees the changes.
*/ */
mutex_lock(&sb_dqopt(sb)->dqonoff_mutex); mutex_lock(&dqopt->dqonoff_mutex);
for (cnt = 0; cnt < MAXQUOTAS; cnt++) { for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
if (type != -1 && cnt != type) if (type != -1 && cnt != type)
continue; continue;
if (!sb_has_quota_active(sb, cnt)) if (!sb_has_quota_active(sb, cnt))
continue; continue;
mutex_lock_nested(&sb_dqopt(sb)->files[cnt]->i_mutex, mutex_lock(&dqopt->files[cnt]->i_mutex);
I_MUTEX_QUOTA); truncate_inode_pages(&dqopt->files[cnt]->i_data, 0);
truncate_inode_pages(&sb_dqopt(sb)->files[cnt]->i_data, 0); mutex_unlock(&dqopt->files[cnt]->i_mutex);
mutex_unlock(&sb_dqopt(sb)->files[cnt]->i_mutex);
} }
mutex_unlock(&sb_dqopt(sb)->dqonoff_mutex); mutex_unlock(&dqopt->dqonoff_mutex);
return 0; return 0;
} }
...@@ -907,14 +906,14 @@ static void add_dquot_ref(struct super_block *sb, int type) ...@@ -907,14 +906,14 @@ static void add_dquot_ref(struct super_block *sb, int type)
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
continue; continue;
} }
#ifdef CONFIG_QUOTA_DEBUG
if (unlikely(inode_get_rsv_space(inode) > 0))
reserved = 1;
#endif
__iget(inode); __iget(inode);
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
spin_unlock(&inode_sb_list_lock); spin_unlock(&inode_sb_list_lock);
#ifdef CONFIG_QUOTA_DEBUG
if (unlikely(inode_get_rsv_space(inode) > 0))
reserved = 1;
#endif
iput(old_inode); iput(old_inode);
__dquot_initialize(inode, type); __dquot_initialize(inode, type);
...@@ -2037,8 +2036,7 @@ int dquot_disable(struct super_block *sb, int type, unsigned int flags) ...@@ -2037,8 +2036,7 @@ int dquot_disable(struct super_block *sb, int type, unsigned int flags)
/* If quota was reenabled in the meantime, we have /* If quota was reenabled in the meantime, we have
* nothing to do */ * nothing to do */
if (!sb_has_quota_loaded(sb, cnt)) { if (!sb_has_quota_loaded(sb, cnt)) {
mutex_lock_nested(&toputinode[cnt]->i_mutex, mutex_lock(&toputinode[cnt]->i_mutex);
I_MUTEX_QUOTA);
toputinode[cnt]->i_flags &= ~(S_IMMUTABLE | toputinode[cnt]->i_flags &= ~(S_IMMUTABLE |
S_NOATIME | S_NOQUOTA); S_NOATIME | S_NOQUOTA);
truncate_inode_pages(&toputinode[cnt]->i_data, truncate_inode_pages(&toputinode[cnt]->i_data,
...@@ -2133,7 +2131,7 @@ static int vfs_load_quota_inode(struct inode *inode, int type, int format_id, ...@@ -2133,7 +2131,7 @@ static int vfs_load_quota_inode(struct inode *inode, int type, int format_id,
/* We don't want quota and atime on quota files (deadlocks /* We don't want quota and atime on quota files (deadlocks
* possible) Also nobody should write to the file - we use * possible) Also nobody should write to the file - we use
* special IO operations which ignore the immutable bit. */ * special IO operations which ignore the immutable bit. */
mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA); mutex_lock(&inode->i_mutex);
oldflags = inode->i_flags & (S_NOATIME | S_IMMUTABLE | oldflags = inode->i_flags & (S_NOATIME | S_IMMUTABLE |
S_NOQUOTA); S_NOQUOTA);
inode->i_flags |= S_NOQUOTA | S_NOATIME | S_IMMUTABLE; inode->i_flags |= S_NOQUOTA | S_NOATIME | S_IMMUTABLE;
...@@ -2180,7 +2178,7 @@ static int vfs_load_quota_inode(struct inode *inode, int type, int format_id, ...@@ -2180,7 +2178,7 @@ static int vfs_load_quota_inode(struct inode *inode, int type, int format_id,
iput(inode); iput(inode);
out_lock: out_lock:
if (oldflags != -1) { if (oldflags != -1) {
mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA); mutex_lock(&inode->i_mutex);
/* Set the flags back (in the case of accidental quotaon() /* Set the flags back (in the case of accidental quotaon()
* on a wrong file we don't want to mess up the flags) */ * on a wrong file we don't want to mess up the flags) */
inode->i_flags &= ~(S_NOATIME | S_NOQUOTA | S_IMMUTABLE); inode->i_flags &= ~(S_NOATIME | S_NOQUOTA | S_IMMUTABLE);
......
...@@ -2270,7 +2270,6 @@ static ssize_t reiserfs_quota_write(struct super_block *sb, int type, ...@@ -2270,7 +2270,6 @@ static ssize_t reiserfs_quota_write(struct super_block *sb, int type,
(unsigned long long)off, (unsigned long long)len); (unsigned long long)off, (unsigned long long)len);
return -EIO; return -EIO;
} }
mutex_lock_nested(&inode->i_mutex, I_MUTEX_QUOTA);
while (towrite > 0) { while (towrite > 0) {
tocopy = sb->s_blocksize - offset < towrite ? tocopy = sb->s_blocksize - offset < towrite ?
sb->s_blocksize - offset : towrite; sb->s_blocksize - offset : towrite;
...@@ -2302,16 +2301,13 @@ static ssize_t reiserfs_quota_write(struct super_block *sb, int type, ...@@ -2302,16 +2301,13 @@ static ssize_t reiserfs_quota_write(struct super_block *sb, int type,
blk++; blk++;
} }
out: out:
if (len == towrite) { if (len == towrite)
mutex_unlock(&inode->i_mutex);
return err; return err;
}
if (inode->i_size < off + len - towrite) if (inode->i_size < off + len - towrite)
i_size_write(inode, off + len - towrite); i_size_write(inode, off + len - towrite);
inode->i_version++; inode->i_version++;
inode->i_mtime = inode->i_ctime = CURRENT_TIME; inode->i_mtime = inode->i_ctime = CURRENT_TIME;
mark_inode_dirty(inode); mark_inode_dirty(inode);
mutex_unlock(&inode->i_mutex);
return len - towrite; return len - towrite;
} }
......
...@@ -479,12 +479,6 @@ struct transaction_s ...@@ -479,12 +479,6 @@ struct transaction_s
* How many handles used this transaction? [t_handle_lock] * How many handles used this transaction? [t_handle_lock]
*/ */
int t_handle_count; int t_handle_count;
/*
* This transaction is being forced and some process is
* waiting for it to finish.
*/
unsigned int t_synchronous_commit:1;
}; };
/** /**
...@@ -531,6 +525,8 @@ struct transaction_s ...@@ -531,6 +525,8 @@ struct transaction_s
* transaction * transaction
* @j_commit_request: Sequence number of the most recent transaction wanting * @j_commit_request: Sequence number of the most recent transaction wanting
* commit * commit
* @j_commit_waited: Sequence number of the most recent transaction someone
* is waiting for to commit.
* @j_uuid: Uuid of client object. * @j_uuid: Uuid of client object.
* @j_task: Pointer to the current commit thread for this journal * @j_task: Pointer to the current commit thread for this journal
* @j_max_transaction_buffers: Maximum number of metadata buffers to allow in a * @j_max_transaction_buffers: Maximum number of metadata buffers to allow in a
...@@ -695,6 +691,13 @@ struct journal_s ...@@ -695,6 +691,13 @@ struct journal_s
*/ */
tid_t j_commit_request; tid_t j_commit_request;
/*
* Sequence number of the most recent transaction someone is waiting
* for to commit.
* [j_state_lock]
*/
tid_t j_commit_waited;
/* /*
* Journal uuid: identifies the object (filesystem, LVM volume etc) * Journal uuid: identifies the object (filesystem, LVM volume etc)
* backed by this journal. This will eventually be replaced by an array * backed by this journal. This will eventually be replaced by an array
...@@ -861,7 +864,8 @@ extern int journal_destroy (journal_t *); ...@@ -861,7 +864,8 @@ extern int journal_destroy (journal_t *);
extern int journal_recover (journal_t *journal); extern int journal_recover (journal_t *journal);
extern int journal_wipe (journal_t *, int); extern int journal_wipe (journal_t *, int);
extern int journal_skip_recovery (journal_t *); extern int journal_skip_recovery (journal_t *);
extern void journal_update_superblock (journal_t *, int); extern void journal_update_sb_log_tail (journal_t *, tid_t, unsigned int,
int);
extern void journal_abort (journal_t *, int); extern void journal_abort (journal_t *, int);
extern int journal_errno (journal_t *); extern int journal_errno (journal_t *);
extern void journal_ack_err (journal_t *); extern void journal_ack_err (journal_t *);
......
...@@ -36,19 +36,17 @@ DECLARE_EVENT_CLASS(jbd_commit, ...@@ -36,19 +36,17 @@ DECLARE_EVENT_CLASS(jbd_commit,
TP_STRUCT__entry( TP_STRUCT__entry(
__field( dev_t, dev ) __field( dev_t, dev )
__field( char, sync_commit )
__field( int, transaction ) __field( int, transaction )
), ),
TP_fast_assign( TP_fast_assign(
__entry->dev = journal->j_fs_dev->bd_dev; __entry->dev = journal->j_fs_dev->bd_dev;
__entry->sync_commit = commit_transaction->t_synchronous_commit;
__entry->transaction = commit_transaction->t_tid; __entry->transaction = commit_transaction->t_tid;
), ),
TP_printk("dev %d,%d transaction %d sync %d", TP_printk("dev %d,%d transaction %d",
MAJOR(__entry->dev), MINOR(__entry->dev), MAJOR(__entry->dev), MINOR(__entry->dev),
__entry->transaction, __entry->sync_commit) __entry->transaction)
); );
DEFINE_EVENT(jbd_commit, jbd_start_commit, DEFINE_EVENT(jbd_commit, jbd_start_commit,
...@@ -87,19 +85,17 @@ TRACE_EVENT(jbd_drop_transaction, ...@@ -87,19 +85,17 @@ TRACE_EVENT(jbd_drop_transaction,
TP_STRUCT__entry( TP_STRUCT__entry(
__field( dev_t, dev ) __field( dev_t, dev )
__field( char, sync_commit )
__field( int, transaction ) __field( int, transaction )
), ),
TP_fast_assign( TP_fast_assign(
__entry->dev = journal->j_fs_dev->bd_dev; __entry->dev = journal->j_fs_dev->bd_dev;
__entry->sync_commit = commit_transaction->t_synchronous_commit;
__entry->transaction = commit_transaction->t_tid; __entry->transaction = commit_transaction->t_tid;
), ),
TP_printk("dev %d,%d transaction %d sync %d", TP_printk("dev %d,%d transaction %d",
MAJOR(__entry->dev), MINOR(__entry->dev), MAJOR(__entry->dev), MINOR(__entry->dev),
__entry->transaction, __entry->sync_commit) __entry->transaction)
); );
TRACE_EVENT(jbd_end_commit, TRACE_EVENT(jbd_end_commit,
...@@ -109,21 +105,19 @@ TRACE_EVENT(jbd_end_commit, ...@@ -109,21 +105,19 @@ TRACE_EVENT(jbd_end_commit,
TP_STRUCT__entry( TP_STRUCT__entry(
__field( dev_t, dev ) __field( dev_t, dev )
__field( char, sync_commit )
__field( int, transaction ) __field( int, transaction )
__field( int, head ) __field( int, head )
), ),
TP_fast_assign( TP_fast_assign(
__entry->dev = journal->j_fs_dev->bd_dev; __entry->dev = journal->j_fs_dev->bd_dev;
__entry->sync_commit = commit_transaction->t_synchronous_commit;
__entry->transaction = commit_transaction->t_tid; __entry->transaction = commit_transaction->t_tid;
__entry->head = journal->j_tail_sequence; __entry->head = journal->j_tail_sequence;
), ),
TP_printk("dev %d,%d transaction %d sync %d head %d", TP_printk("dev %d,%d transaction %d head %d",
MAJOR(__entry->dev), MINOR(__entry->dev), MAJOR(__entry->dev), MINOR(__entry->dev),
__entry->transaction, __entry->sync_commit, __entry->head) __entry->transaction, __entry->head)
); );
TRACE_EVENT(jbd_do_submit_data, TRACE_EVENT(jbd_do_submit_data,
...@@ -133,19 +127,17 @@ TRACE_EVENT(jbd_do_submit_data, ...@@ -133,19 +127,17 @@ TRACE_EVENT(jbd_do_submit_data,
TP_STRUCT__entry( TP_STRUCT__entry(
__field( dev_t, dev ) __field( dev_t, dev )
__field( char, sync_commit )
__field( int, transaction ) __field( int, transaction )
), ),
TP_fast_assign( TP_fast_assign(
__entry->dev = journal->j_fs_dev->bd_dev; __entry->dev = journal->j_fs_dev->bd_dev;
__entry->sync_commit = commit_transaction->t_synchronous_commit;
__entry->transaction = commit_transaction->t_tid; __entry->transaction = commit_transaction->t_tid;
), ),
TP_printk("dev %d,%d transaction %d sync %d", TP_printk("dev %d,%d transaction %d",
MAJOR(__entry->dev), MINOR(__entry->dev), MAJOR(__entry->dev), MINOR(__entry->dev),
__entry->transaction, __entry->sync_commit) __entry->transaction)
); );
TRACE_EVENT(jbd_cleanup_journal_tail, TRACE_EVENT(jbd_cleanup_journal_tail,
...@@ -177,24 +169,23 @@ TRACE_EVENT(jbd_cleanup_journal_tail, ...@@ -177,24 +169,23 @@ TRACE_EVENT(jbd_cleanup_journal_tail,
__entry->block_nr, __entry->freed) __entry->block_nr, __entry->freed)
); );
TRACE_EVENT(jbd_update_superblock_end, TRACE_EVENT(journal_write_superblock,
TP_PROTO(journal_t *journal, int wait), TP_PROTO(journal_t *journal, int write_op),
TP_ARGS(journal, wait), TP_ARGS(journal, write_op),
TP_STRUCT__entry( TP_STRUCT__entry(
__field( dev_t, dev ) __field( dev_t, dev )
__field( int, wait ) __field( int, write_op )
), ),
TP_fast_assign( TP_fast_assign(
__entry->dev = journal->j_fs_dev->bd_dev; __entry->dev = journal->j_fs_dev->bd_dev;
__entry->wait = wait; __entry->write_op = write_op;
), ),
TP_printk("dev %d,%d wait %d", TP_printk("dev %d,%d write_op %x", MAJOR(__entry->dev),
MAJOR(__entry->dev), MINOR(__entry->dev), MINOR(__entry->dev), __entry->write_op)
__entry->wait)
); );
#endif /* _TRACE_JBD_H */ #endif /* _TRACE_JBD_H */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册