Commit 3ae2a1ce authored by Linus Torvalds's avatar Linus Torvalds

Merge git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-2.6-nmw

* git://git.kernel.org/pub/scm/linux/kernel/git/steve/gfs2-2.6-nmw:
  GFS2: Don't use _raw version of RCU dereference
  GFS2: Adding missing unlock_page()
  GFS2: Update to AIL list locking
  GFS2: introduce AIL lock
  GFS2: fix block allocation check for fallocate
  GFS2: Optimize glock multiple-dequeue code
  GFS2: Remove potential race in flock code
  GFS2: Fix glock deallocation race
  GFS2: quota allows exceeding hard limit
  GFS2: deallocation performance patch
  GFS2: panics on quotacheck update
  GFS2: Improve cluster mmap scalability
  GFS2: Fix glock queue trace point
  GFS2: Post-VFS scale update for RCU path walk
  GFS2: Use RCU for glock hash table
parents 26a992db 7e32d026
...@@ -80,8 +80,11 @@ int gfs2_check_acl(struct inode *inode, int mask, unsigned int flags) ...@@ -80,8 +80,11 @@ int gfs2_check_acl(struct inode *inode, int mask, unsigned int flags)
struct posix_acl *acl; struct posix_acl *acl;
int error; int error;
if (flags & IPERM_FLAG_RCU) if (flags & IPERM_FLAG_RCU) {
if (!negative_cached_acl(inode, ACL_TYPE_ACCESS))
return -ECHILD; return -ECHILD;
return -EAGAIN;
}
acl = gfs2_acl_get(GFS2_I(inode), ACL_TYPE_ACCESS); acl = gfs2_acl_get(GFS2_I(inode), ACL_TYPE_ACCESS);
if (IS_ERR(acl)) if (IS_ERR(acl))
......
...@@ -695,6 +695,7 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping, ...@@ -695,6 +695,7 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
if (error == 0) if (error == 0)
return 0; return 0;
unlock_page(page);
page_cache_release(page); page_cache_release(page);
gfs2_trans_end(sdp); gfs2_trans_end(sdp);
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "meta_io.h" #include "meta_io.h"
#include "quota.h" #include "quota.h"
#include "rgrp.h" #include "rgrp.h"
#include "super.h"
#include "trans.h" #include "trans.h"
#include "dir.h" #include "dir.h"
#include "util.h" #include "util.h"
...@@ -757,7 +758,7 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh, ...@@ -757,7 +758,7 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh,
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
struct gfs2_rgrp_list rlist; struct gfs2_rgrp_list rlist;
u64 bn, bstart; u64 bn, bstart;
u32 blen; u32 blen, btotal;
__be64 *p; __be64 *p;
unsigned int rg_blocks = 0; unsigned int rg_blocks = 0;
int metadata; int metadata;
...@@ -839,6 +840,7 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh, ...@@ -839,6 +840,7 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh,
bstart = 0; bstart = 0;
blen = 0; blen = 0;
btotal = 0;
for (p = top; p < bottom; p++) { for (p = top; p < bottom; p++) {
if (!*p) if (!*p)
...@@ -851,9 +853,11 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh, ...@@ -851,9 +853,11 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh,
else { else {
if (bstart) { if (bstart) {
if (metadata) if (metadata)
gfs2_free_meta(ip, bstart, blen); __gfs2_free_meta(ip, bstart, blen);
else else
gfs2_free_data(ip, bstart, blen); __gfs2_free_data(ip, bstart, blen);
btotal += blen;
} }
bstart = bn; bstart = bn;
...@@ -865,11 +869,17 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh, ...@@ -865,11 +869,17 @@ static int do_strip(struct gfs2_inode *ip, struct buffer_head *dibh,
} }
if (bstart) { if (bstart) {
if (metadata) if (metadata)
gfs2_free_meta(ip, bstart, blen); __gfs2_free_meta(ip, bstart, blen);
else else
gfs2_free_data(ip, bstart, blen); __gfs2_free_data(ip, bstart, blen);
btotal += blen;
} }
gfs2_statfs_change(sdp, 0, +btotal, 0);
gfs2_quota_change(ip, -(s64)btotal, ip->i_inode.i_uid,
ip->i_inode.i_gid);
ip->i_inode.i_mtime = ip->i_inode.i_ctime = CURRENT_TIME; ip->i_inode.i_mtime = ip->i_inode.i_ctime = CURRENT_TIME;
gfs2_dinode_out(ip, dibh->b_data); gfs2_dinode_out(ip, dibh->b_data);
......
...@@ -448,15 +448,20 @@ static int gfs2_mmap(struct file *file, struct vm_area_struct *vma) ...@@ -448,15 +448,20 @@ static int gfs2_mmap(struct file *file, struct vm_area_struct *vma)
{ {
struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
if (!(file->f_flags & O_NOATIME)) { if (!(file->f_flags & O_NOATIME) &&
!IS_NOATIME(&ip->i_inode)) {
struct gfs2_holder i_gh; struct gfs2_holder i_gh;
int error; int error;
gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &i_gh); gfs2_holder_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
error = gfs2_glock_nq(&i_gh); error = gfs2_glock_nq(&i_gh);
if (error == 0) {
file_accessed(file); file_accessed(file);
if (error == 0) gfs2_glock_dq(&i_gh);
gfs2_glock_dq_uninit(&i_gh); }
gfs2_holder_uninit(&i_gh);
if (error)
return error;
} }
vma->vm_ops = &gfs2_vm_ops; vma->vm_ops = &gfs2_vm_ops;
vma->vm_flags |= VM_CAN_NONLINEAR; vma->vm_flags |= VM_CAN_NONLINEAR;
...@@ -617,8 +622,7 @@ static void empty_write_end(struct page *page, unsigned from, ...@@ -617,8 +622,7 @@ static void empty_write_end(struct page *page, unsigned from,
{ {
struct gfs2_inode *ip = GFS2_I(page->mapping->host); struct gfs2_inode *ip = GFS2_I(page->mapping->host);
page_zero_new_buffers(page, from, to); zero_user(page, from, to-from);
flush_dcache_page(page);
mark_page_accessed(page); mark_page_accessed(page);
if (!gfs2_is_writeback(ip)) if (!gfs2_is_writeback(ip))
...@@ -627,36 +631,43 @@ static void empty_write_end(struct page *page, unsigned from, ...@@ -627,36 +631,43 @@ static void empty_write_end(struct page *page, unsigned from,
block_commit_write(page, from, to); block_commit_write(page, from, to);
} }
static int write_empty_blocks(struct page *page, unsigned from, unsigned to) static int needs_empty_write(sector_t block, struct inode *inode)
{ {
unsigned start, end, next;
struct buffer_head *bh, *head;
int error; int error;
struct buffer_head bh_map = { .b_state = 0, .b_blocknr = 0 };
if (!page_has_buffers(page)) { bh_map.b_size = 1 << inode->i_blkbits;
error = __block_write_begin(page, from, to - from, gfs2_block_map); error = gfs2_block_map(inode, block, &bh_map, 0);
if (unlikely(error)) if (unlikely(error))
return error; return error;
return !buffer_mapped(&bh_map);
}
empty_write_end(page, from, to); static int write_empty_blocks(struct page *page, unsigned from, unsigned to)
return 0; {
} struct inode *inode = page->mapping->host;
unsigned start, end, next, blksize;
sector_t block = page->index << (PAGE_CACHE_SHIFT - inode->i_blkbits);
int ret;
bh = head = page_buffers(page); blksize = 1 << inode->i_blkbits;
next = end = 0; next = end = 0;
while (next < from) { while (next < from) {
next += bh->b_size; next += blksize;
bh = bh->b_this_page; block++;
} }
start = next; start = next;
do { do {
next += bh->b_size; next += blksize;
if (buffer_mapped(bh)) { ret = needs_empty_write(block, inode);
if (unlikely(ret < 0))
return ret;
if (ret == 0) {
if (end) { if (end) {
error = __block_write_begin(page, start, end - start, ret = __block_write_begin(page, start, end - start,
gfs2_block_map); gfs2_block_map);
if (unlikely(error)) if (unlikely(ret))
return error; return ret;
empty_write_end(page, start, end); empty_write_end(page, start, end);
end = 0; end = 0;
} }
...@@ -664,13 +675,13 @@ static int write_empty_blocks(struct page *page, unsigned from, unsigned to) ...@@ -664,13 +675,13 @@ static int write_empty_blocks(struct page *page, unsigned from, unsigned to)
} }
else else
end = next; end = next;
bh = bh->b_this_page; block++;
} while (next < to); } while (next < to);
if (end) { if (end) {
error = __block_write_begin(page, start, end - start, gfs2_block_map); ret = __block_write_begin(page, start, end - start, gfs2_block_map);
if (unlikely(error)) if (unlikely(ret))
return error; return ret;
empty_write_end(page, start, end); empty_write_end(page, start, end);
} }
...@@ -976,8 +987,10 @@ static void do_unflock(struct file *file, struct file_lock *fl) ...@@ -976,8 +987,10 @@ static void do_unflock(struct file *file, struct file_lock *fl)
mutex_lock(&fp->f_fl_mutex); mutex_lock(&fp->f_fl_mutex);
flock_lock_file_wait(file, fl); flock_lock_file_wait(file, fl);
if (fl_gh->gh_gl) if (fl_gh->gh_gl) {
gfs2_glock_dq_uninit(fl_gh); gfs2_glock_dq_wait(fl_gh);
gfs2_holder_uninit(fl_gh);
}
mutex_unlock(&fp->f_fl_mutex); mutex_unlock(&fp->f_fl_mutex);
} }
......
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
#include <linux/freezer.h> #include <linux/freezer.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/jiffies.h> #include <linux/jiffies.h>
#include <linux/rcupdate.h>
#include <linux/rculist_bl.h>
#include <linux/bit_spinlock.h>
#include "gfs2.h" #include "gfs2.h"
#include "incore.h" #include "incore.h"
...@@ -41,10 +44,6 @@ ...@@ -41,10 +44,6 @@
#define CREATE_TRACE_POINTS #define CREATE_TRACE_POINTS
#include "trace_gfs2.h" #include "trace_gfs2.h"
struct gfs2_gl_hash_bucket {
struct hlist_head hb_list;
};
struct gfs2_glock_iter { struct gfs2_glock_iter {
int hash; /* hash bucket index */ int hash; /* hash bucket index */
struct gfs2_sbd *sdp; /* incore superblock */ struct gfs2_sbd *sdp; /* incore superblock */
...@@ -54,7 +53,6 @@ struct gfs2_glock_iter { ...@@ -54,7 +53,6 @@ struct gfs2_glock_iter {
typedef void (*glock_examiner) (struct gfs2_glock * gl); typedef void (*glock_examiner) (struct gfs2_glock * gl);
static int gfs2_dump_lockstate(struct gfs2_sbd *sdp);
static int __dump_glock(struct seq_file *seq, const struct gfs2_glock *gl); static int __dump_glock(struct seq_file *seq, const struct gfs2_glock *gl);
#define GLOCK_BUG_ON(gl,x) do { if (unlikely(x)) { __dump_glock(NULL, gl); BUG(); } } while(0) #define GLOCK_BUG_ON(gl,x) do { if (unlikely(x)) { __dump_glock(NULL, gl); BUG(); } } while(0)
static void do_xmote(struct gfs2_glock *gl, struct gfs2_holder *gh, unsigned int target); static void do_xmote(struct gfs2_glock *gl, struct gfs2_holder *gh, unsigned int target);
...@@ -70,57 +68,9 @@ static DEFINE_SPINLOCK(lru_lock); ...@@ -70,57 +68,9 @@ static DEFINE_SPINLOCK(lru_lock);
#define GFS2_GL_HASH_SIZE (1 << GFS2_GL_HASH_SHIFT) #define GFS2_GL_HASH_SIZE (1 << GFS2_GL_HASH_SHIFT)
#define GFS2_GL_HASH_MASK (GFS2_GL_HASH_SIZE - 1) #define GFS2_GL_HASH_MASK (GFS2_GL_HASH_SIZE - 1)
static struct gfs2_gl_hash_bucket gl_hash_table[GFS2_GL_HASH_SIZE]; static struct hlist_bl_head gl_hash_table[GFS2_GL_HASH_SIZE];
static struct dentry *gfs2_root; static struct dentry *gfs2_root;
/*
* Despite what you might think, the numbers below are not arbitrary :-)
* They are taken from the ipv4 routing hash code, which is well tested
* and thus should be nearly optimal. Later on we might tweek the numbers
* but for now this should be fine.
*
* The reason for putting the locks in a separate array from the list heads
* is that we can have fewer locks than list heads and save memory. We use
* the same hash function for both, but with a different hash mask.
*/
#if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK) || \
defined(CONFIG_PROVE_LOCKING)
#ifdef CONFIG_LOCKDEP
# define GL_HASH_LOCK_SZ 256
#else
# if NR_CPUS >= 32
# define GL_HASH_LOCK_SZ 4096
# elif NR_CPUS >= 16
# define GL_HASH_LOCK_SZ 2048
# elif NR_CPUS >= 8
# define GL_HASH_LOCK_SZ 1024
# elif NR_CPUS >= 4
# define GL_HASH_LOCK_SZ 512
# else
# define GL_HASH_LOCK_SZ 256
# endif
#endif
/* We never want more locks than chains */
#if GFS2_GL_HASH_SIZE < GL_HASH_LOCK_SZ
# undef GL_HASH_LOCK_SZ
# define GL_HASH_LOCK_SZ GFS2_GL_HASH_SIZE
#endif
static rwlock_t gl_hash_locks[GL_HASH_LOCK_SZ];
static inline rwlock_t *gl_lock_addr(unsigned int x)
{
return &gl_hash_locks[x & (GL_HASH_LOCK_SZ-1)];
}
#else /* not SMP, so no spinlocks required */
static inline rwlock_t *gl_lock_addr(unsigned int x)
{
return NULL;
}
#endif
/** /**
* gl_hash() - Turn glock number into hash bucket number * gl_hash() - Turn glock number into hash bucket number
* @lock: The glock number * @lock: The glock number
...@@ -141,25 +91,35 @@ static unsigned int gl_hash(const struct gfs2_sbd *sdp, ...@@ -141,25 +91,35 @@ static unsigned int gl_hash(const struct gfs2_sbd *sdp,
return h; return h;
} }
/** static inline void spin_lock_bucket(unsigned int hash)
* glock_free() - Perform a few checks and then release struct gfs2_glock {
* @gl: The glock to release struct hlist_bl_head *bl = &gl_hash_table[hash];
* bit_spin_lock(0, (unsigned long *)bl);
* Also calls lock module to release its internal structure for this glock. }
*
*/ static inline void spin_unlock_bucket(unsigned int hash)
{
struct hlist_bl_head *bl = &gl_hash_table[hash];
__bit_spin_unlock(0, (unsigned long *)bl);
}
static void gfs2_glock_dealloc(struct rcu_head *rcu)
{
struct gfs2_glock *gl = container_of(rcu, struct gfs2_glock, gl_rcu);
static void glock_free(struct gfs2_glock *gl) if (gl->gl_ops->go_flags & GLOF_ASPACE)
kmem_cache_free(gfs2_glock_aspace_cachep, gl);
else
kmem_cache_free(gfs2_glock_cachep, gl);
}
void gfs2_glock_free(struct gfs2_glock *gl)
{ {
struct gfs2_sbd *sdp = gl->gl_sbd; struct gfs2_sbd *sdp = gl->gl_sbd;
struct address_space *mapping = gfs2_glock2aspace(gl);
struct kmem_cache *cachep = gfs2_glock_cachep;
GLOCK_BUG_ON(gl, mapping && mapping->nrpages); call_rcu(&gl->gl_rcu, gfs2_glock_dealloc);
trace_gfs2_glock_put(gl); if (atomic_dec_and_test(&sdp->sd_glock_disposal))
if (mapping) wake_up(&sdp->sd_glock_wait);
cachep = gfs2_glock_aspace_cachep;
sdp->sd_lockstruct.ls_ops->lm_put_lock(cachep, gl);
} }
/** /**
...@@ -185,34 +145,49 @@ static int demote_ok(const struct gfs2_glock *gl) ...@@ -185,34 +145,49 @@ static int demote_ok(const struct gfs2_glock *gl)
{ {
const struct gfs2_glock_operations *glops = gl->gl_ops; const struct gfs2_glock_operations *glops = gl->gl_ops;
/* assert_spin_locked(&gl->gl_spin); */
if (gl->gl_state == LM_ST_UNLOCKED) if (gl->gl_state == LM_ST_UNLOCKED)
return 0; return 0;
if (!list_empty(&gl->gl_holders)) if (test_bit(GLF_LFLUSH, &gl->gl_flags))
return 0;
if ((gl->gl_name.ln_type != LM_TYPE_INODE) &&
!list_empty(&gl->gl_holders))
return 0; return 0;
if (glops->go_demote_ok) if (glops->go_demote_ok)
return glops->go_demote_ok(gl); return glops->go_demote_ok(gl);
return 1; return 1;
} }
/** /**
* gfs2_glock_schedule_for_reclaim - Add a glock to the reclaim list * __gfs2_glock_schedule_for_reclaim - Add a glock to the reclaim list
* @gl: the glock * @gl: the glock
* *
* If the glock is demotable, then we add it (or move it) to the end
* of the glock LRU list.
*/ */
static void gfs2_glock_schedule_for_reclaim(struct gfs2_glock *gl) static void __gfs2_glock_schedule_for_reclaim(struct gfs2_glock *gl)
{ {
int may_reclaim; if (demote_ok(gl)) {
may_reclaim = (demote_ok(gl) &&
(atomic_read(&gl->gl_ref) == 1 ||
(gl->gl_name.ln_type == LM_TYPE_INODE &&
atomic_read(&gl->gl_ref) <= 2)));
spin_lock(&lru_lock); spin_lock(&lru_lock);
if (list_empty(&gl->gl_lru) && may_reclaim) {
list_add_tail(&gl->gl_lru, &lru_list); if (!list_empty(&gl->gl_lru))
list_del_init(&gl->gl_lru);
else
atomic_inc(&lru_count); atomic_inc(&lru_count);
}
list_add_tail(&gl->gl_lru, &lru_list);
spin_unlock(&lru_lock); spin_unlock(&lru_lock);
}
}
void gfs2_glock_schedule_for_reclaim(struct gfs2_glock *gl)
{
spin_lock(&gl->gl_spin);
__gfs2_glock_schedule_for_reclaim(gl);
spin_unlock(&gl->gl_spin);
} }
/** /**
...@@ -227,7 +202,6 @@ void gfs2_glock_put_nolock(struct gfs2_glock *gl) ...@@ -227,7 +202,6 @@ void gfs2_glock_put_nolock(struct gfs2_glock *gl)
{ {
if (atomic_dec_and_test(&gl->gl_ref)) if (atomic_dec_and_test(&gl->gl_ref))
GLOCK_BUG_ON(gl, 1); GLOCK_BUG_ON(gl, 1);
gfs2_glock_schedule_for_reclaim(gl);
} }
/** /**
...@@ -236,30 +210,26 @@ void gfs2_glock_put_nolock(struct gfs2_glock *gl) ...@@ -236,30 +210,26 @@ void gfs2_glock_put_nolock(struct gfs2_glock *gl)
* *
*/ */
int gfs2_glock_put(struct gfs2_glock *gl) void gfs2_glock_put(struct gfs2_glock *gl)
{ {
int rv = 0; struct gfs2_sbd *sdp = gl->gl_sbd;
struct address_space *mapping = gfs2_glock2aspace(gl);
write_lock(gl_lock_addr(gl->gl_hash)); if (atomic_dec_and_test(&gl->gl_ref)) {
if (atomic_dec_and_lock(&gl->gl_ref, &lru_lock)) { spin_lock_bucket(gl->gl_hash);
hlist_del(&gl->gl_list); hlist_bl_del_rcu(&gl->gl_list);
spin_unlock_bucket(gl->gl_hash);
spin_lock(&lru_lock);
if (!list_empty(&gl->gl_lru)) { if (!list_empty(&gl->gl_lru)) {
list_del_init(&gl->gl_lru); list_del_init(&gl->gl_lru);
atomic_dec(&lru_count); atomic_dec(&lru_count);
} }
spin_unlock(&lru_lock); spin_unlock(&lru_lock);
write_unlock(gl_lock_addr(gl->gl_hash));
GLOCK_BUG_ON(gl, !list_empty(&gl->gl_holders)); GLOCK_BUG_ON(gl, !list_empty(&gl->gl_holders));
glock_free(gl); GLOCK_BUG_ON(gl, mapping && mapping->nrpages);
rv = 1; trace_gfs2_glock_put(gl);
goto out; sdp->sd_lockstruct.ls_ops->lm_put_lock(gl);
} }
spin_lock(&gl->gl_spin);
gfs2_glock_schedule_for_reclaim(gl);
spin_unlock(&gl->gl_spin);
write_unlock(gl_lock_addr(gl->gl_hash));
out:
return rv;
} }
/** /**
...@@ -275,16 +245,14 @@ static struct gfs2_glock *search_bucket(unsigned int hash, ...@@ -275,16 +245,14 @@ static struct gfs2_glock *search_bucket(unsigned int hash,
const struct lm_lockname *name) const struct lm_lockname *name)
{ {
struct gfs2_glock *gl; struct gfs2_glock *gl;
struct hlist_node *h; struct hlist_bl_node *h;
hlist_for_each_entry(gl, h, &gl_hash_table[hash].hb_list, gl_list) { hlist_bl_for_each_entry_rcu(gl, h, &gl_hash_table[hash], gl_list) {
if (!lm_name_equal(&gl->gl_name, name)) if (!lm_name_equal(&gl->gl_name, name))
continue; continue;
if (gl->gl_sbd != sdp) if (gl->gl_sbd != sdp)
continue; continue;
if (atomic_inc_not_zero(&gl->gl_ref))
atomic_inc(&gl->gl_ref);
return gl; return gl;
} }
...@@ -743,10 +711,11 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number, ...@@ -743,10 +711,11 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
struct gfs2_glock *gl, *tmp; struct gfs2_glock *gl, *tmp;
unsigned int hash = gl_hash(sdp, &name); unsigned int hash = gl_hash(sdp, &name);
struct address_space *mapping; struct address_space *mapping;
struct kmem_cache *cachep;
read_lock(gl_lock_addr(hash)); rcu_read_lock();
gl = search_bucket(hash, sdp, &name); gl = search_bucket(hash, sdp, &name);
read_unlock(gl_lock_addr(hash)); rcu_read_unlock();
*glp = gl; *glp = gl;
if (gl) if (gl)
...@@ -755,9 +724,10 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number, ...@@ -755,9 +724,10 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
return -ENOENT; return -ENOENT;
if (glops->go_flags & GLOF_ASPACE) if (glops->go_flags & GLOF_ASPACE)
gl = kmem_cache_alloc(gfs2_glock_aspace_cachep, GFP_KERNEL); cachep = gfs2_glock_aspace_cachep;
else else
gl = kmem_cache_alloc(gfs2_glock_cachep, GFP_KERNEL); cachep = gfs2_glock_cachep;
gl = kmem_cache_alloc(cachep, GFP_KERNEL);
if (!gl) if (!gl)
return -ENOMEM; return -ENOMEM;
...@@ -790,15 +760,16 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number, ...@@ -790,15 +760,16 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
mapping->writeback_index = 0; mapping->writeback_index = 0;
} }
write_lock(gl_lock_addr(hash)); spin_lock_bucket(hash);
tmp = search_bucket(hash, sdp, &name); tmp = search_bucket(hash, sdp, &name);
if (tmp) { if (tmp) {
write_unlock(gl_lock_addr(hash)); spin_unlock_bucket(hash);
glock_free(gl); kmem_cache_free(cachep, gl);
atomic_dec(&sdp->sd_glock_disposal);
gl = tmp; gl = tmp;
} else { } else {
hlist_add_head(&gl->gl_list, &gl_hash_table[hash].hb_list); hlist_bl_add_head_rcu(&gl->gl_list, &gl_hash_table[hash]);
write_unlock(gl_lock_addr(hash)); spin_unlock_bucket(hash);
} }
*glp = gl; *glp = gl;
...@@ -1007,13 +978,13 @@ __acquires(&gl->gl_spin) ...@@ -1007,13 +978,13 @@ __acquires(&gl->gl_spin)
insert_pt = &gh2->gh_list; insert_pt = &gh2->gh_list;
} }
set_bit(GLF_QUEUED, &gl->gl_flags); set_bit(GLF_QUEUED, &gl->gl_flags);
trace_gfs2_glock_queue(gh, 1);
if (likely(insert_pt == NULL)) { if (likely(insert_pt == NULL)) {
list_add_tail(&gh->gh_list, &gl->gl_holders); list_add_tail(&gh->gh_list, &gl->gl_holders);
if (unlikely(gh->gh_flags & LM_FLAG_PRIORITY)) if (unlikely(gh->gh_flags & LM_FLAG_PRIORITY))
goto do_cancel; goto do_cancel;
return; return;
} }
trace_gfs2_glock_queue(gh, 1);
list_add_tail(&gh->gh_list, insert_pt); list_add_tail(&gh->gh_list, insert_pt);
do_cancel: do_cancel:
gh = list_entry(gl->gl_holders.next, struct gfs2_holder, gh_list); gh = list_entry(gl->gl_holders.next, struct gfs2_holder, gh_list);
...@@ -1113,6 +1084,7 @@ void gfs2_glock_dq(struct gfs2_holder *gh) ...@@ -1113,6 +1084,7 @@ void gfs2_glock_dq(struct gfs2_holder *gh)
!test_bit(GLF_DEMOTE, &gl->gl_flags)) !test_bit(GLF_DEMOTE, &gl->gl_flags))
fast_path = 1; fast_path = 1;
} }
__gfs2_glock_schedule_for_reclaim(gl);
trace_gfs2_glock_queue(gh, 0); trace_gfs2_glock_queue(gh, 0);
spin_unlock(&gl->gl_spin); spin_unlock(&gl->gl_spin);
if (likely(fast_path)) if (likely(fast_path))
...@@ -1276,10 +1248,8 @@ int gfs2_glock_nq_m(unsigned int num_gh, struct gfs2_holder *ghs) ...@@ -1276,10 +1248,8 @@ int gfs2_glock_nq_m(unsigned int num_gh, struct gfs2_holder *ghs)
void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs) void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs)
{ {
unsigned int x; while (num_gh--)
gfs2_glock_dq(&ghs[num_gh]);
for (x = 0; x < num_gh; x++)
gfs2_glock_dq(&ghs[x]);
} }
/** /**
...@@ -1291,10 +1261,8 @@ void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs) ...@@ -1291,10 +1261,8 @@ void gfs2_glock_dq_m(unsigned int num_gh, struct gfs2_holder *ghs)
void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs) void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs)
{ {
unsigned int x; while (num_gh--)
gfs2_glock_dq_uninit(&ghs[num_gh]);
for (x = 0; x < num_gh; x++)
gfs2_glock_dq_uninit(&ghs[x]);
} }
void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state) void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state)
...@@ -1440,42 +1408,30 @@ static struct shrinker glock_shrinker = { ...@@ -1440,42 +1408,30 @@ static struct shrinker glock_shrinker = {
* @sdp: the filesystem * @sdp: the filesystem
* @bucket: the bucket * @bucket: the bucket
* *
* Returns: 1 if the bucket has entries
*/ */
static int examine_bucket(glock_examiner examiner, struct gfs2_sbd *sdp, static void examine_bucket(glock_examiner examiner, const struct gfs2_sbd *sdp,
unsigned int hash) unsigned int hash)
{ {
struct gfs2_glock *gl, *prev = NULL; struct gfs2_glock *gl;
int has_entries = 0; struct hlist_bl_head *head = &gl_hash_table[hash];
struct hlist_head *head = &gl_hash_table[hash].hb_list; struct hlist_bl_node *pos;
read_lock(gl_lock_addr(hash)); rcu_read_lock();
/* Can't use hlist_for_each_entry - don't want prefetch here */ hlist_bl_for_each_entry_rcu(gl, pos, head, gl_list) {
if (hlist_empty(head)) if ((gl->gl_sbd == sdp) && atomic_read(&gl->gl_ref))
goto out;
gl = list_entry(head->first, struct gfs2_glock, gl_list);
while(1) {
if (!sdp || gl->gl_sbd == sdp) {
gfs2_glock_hold(gl);
read_unlock(gl_lock_addr(hash));
if (prev)
gfs2_glock_put(prev);
prev = gl;
examiner(gl); examiner(gl);
has_entries = 1;
read_lock(gl_lock_addr(hash));
} }
if (gl->gl_list.next == NULL) rcu_read_unlock();
break;
gl = list_entry(gl->gl_list.next, struct gfs2_glock, gl_list);
}
out:
read_unlock(gl_lock_addr(hash));
if (prev)
gfs2_glock_put(prev);
cond_resched(); cond_resched();
return has_entries; }
static void glock_hash_walk(glock_examiner examiner, const struct gfs2_sbd *sdp)
{
unsigned x;
for (x = 0; x < GFS2_GL_HASH_SIZE; x++)
examine_bucket(examiner, sdp, x);
} }
...@@ -1529,10 +1485,21 @@ static void clear_glock(struct gfs2_glock *gl) ...@@ -1529,10 +1485,21 @@ static void clear_glock(struct gfs2_glock *gl)
void gfs2_glock_thaw(struct gfs2_sbd *sdp) void gfs2_glock_thaw(struct gfs2_sbd *sdp)
{ {
unsigned x; glock_hash_walk(thaw_glock, sdp);
}
for (x = 0; x < GFS2_GL_HASH_SIZE; x++) static int dump_glock(struct seq_file *seq, struct gfs2_glock *gl)
examine_bucket(thaw_glock, sdp, x); {
int ret;
spin_lock(&gl->gl_spin);
ret = __dump_glock(seq, gl);
spin_unlock(&gl->gl_spin);
return ret;
}
static void dump_glock_func(struct gfs2_glock *gl)
{
dump_glock(NULL, gl);
} }
/** /**
...@@ -1545,13 +1512,10 @@ void gfs2_glock_thaw(struct gfs2_sbd *sdp) ...@@ -1545,13 +1512,10 @@ void gfs2_glock_thaw(struct gfs2_sbd *sdp)
void gfs2_gl_hash_clear(struct gfs2_sbd *sdp) void gfs2_gl_hash_clear(struct gfs2_sbd *sdp)
{ {
unsigned int x; glock_hash_walk(clear_glock, sdp);
for (x = 0; x < GFS2_GL_HASH_SIZE; x++)
examine_bucket(clear_glock, sdp, x);
flush_workqueue(glock_workqueue); flush_workqueue(glock_workqueue);
wait_event(sdp->sd_glock_wait, atomic_read(&sdp->sd_glock_disposal) == 0); wait_event(sdp->sd_glock_wait, atomic_read(&sdp->sd_glock_disposal) == 0);
gfs2_dump_lockstate(sdp); glock_hash_walk(dump_glock_func, sdp);
} }
void gfs2_glock_finish_truncate(struct gfs2_inode *ip) void gfs2_glock_finish_truncate(struct gfs2_inode *ip)
...@@ -1717,66 +1681,15 @@ static int __dump_glock(struct seq_file *seq, const struct gfs2_glock *gl) ...@@ -1717,66 +1681,15 @@ static int __dump_glock(struct seq_file *seq, const struct gfs2_glock *gl)
return error; return error;
} }
static int dump_glock(struct seq_file *seq, struct gfs2_glock *gl)
{
int ret;
spin_lock(&gl->gl_spin);
ret = __dump_glock(seq, gl);
spin_unlock(&gl->gl_spin);
return ret;
}
/**
* gfs2_dump_lockstate - print out the current lockstate
* @sdp: the filesystem
* @ub: the buffer to copy the information into
*
* If @ub is NULL, dump the lockstate to the console.
*
*/
static int gfs2_dump_lockstate(struct gfs2_sbd *sdp)
{
struct gfs2_glock *gl;
struct hlist_node *h;
unsigned int x;
int error = 0;
for (x = 0; x < GFS2_GL_HASH_SIZE; x++) {
read_lock(gl_lock_addr(x));
hlist_for_each_entry(gl, h, &gl_hash_table[x].hb_list, gl_list) {
if (gl->gl_sbd != sdp)
continue;
error = dump_glock(NULL, gl);
if (error)
break;
}
read_unlock(gl_lock_addr(x));
if (error)
break;
}
return error;
}
int __init gfs2_glock_init(void) int __init gfs2_glock_init(void)
{ {
unsigned i; unsigned i;
for(i = 0; i < GFS2_GL_HASH_SIZE; i++) { for(i = 0; i < GFS2_GL_HASH_SIZE; i++) {
INIT_HLIST_HEAD(&gl_hash_table[i].hb_list); INIT_HLIST_BL_HEAD(&gl_hash_table[i]);
} }
#ifdef GL_HASH_LOCK_SZ
for(i = 0; i < GL_HASH_LOCK_SZ; i++) {
rwlock_init(&gl_hash_locks[i]);
}
#endif
glock_workqueue = alloc_workqueue("glock_workqueue", WQ_MEM_RECLAIM | glock_workqueue = alloc_workqueue("glock_workqueue", WQ_MEM_RECLAIM |
WQ_HIGHPRI | WQ_FREEZABLE, 0); WQ_HIGHPRI | WQ_FREEZABLE, 0);
...@@ -1802,62 +1715,54 @@ void gfs2_glock_exit(void) ...@@ -1802,62 +1715,54 @@ void gfs2_glock_exit(void)
destroy_workqueue(gfs2_delete_workqueue); destroy_workqueue(gfs2_delete_workqueue);
} }
static inline struct gfs2_glock *glock_hash_chain(unsigned hash)
{
return hlist_bl_entry(hlist_bl_first_rcu(&gl_hash_table[hash]),
struct gfs2_glock, gl_list);
}
static inline struct gfs2_glock *glock_hash_next(struct gfs2_glock *gl)
{
return hlist_bl_entry(rcu_dereference(gl->gl_list.next),
struct gfs2_glock, gl_list);
}
static int gfs2_glock_iter_next(struct gfs2_glock_iter *gi) static int gfs2_glock_iter_next(struct gfs2_glock_iter *gi)
{ {
struct gfs2_glock *gl; struct gfs2_glock *gl;
restart: do {
read_lock(gl_lock_addr(gi->hash));
gl = gi->gl; gl = gi->gl;
if (gl) { if (gl) {
gi->gl = hlist_entry(gl->gl_list.next, gi->gl = glock_hash_next(gl);
struct gfs2_glock, gl_list);
} else { } else {
gi->gl = hlist_entry(gl_hash_table[gi->hash].hb_list.first, gi->gl = glock_hash_chain(gi->hash);
struct gfs2_glock, gl_list);
} }
if (gi->gl)
gfs2_glock_hold(gi->gl);
read_unlock(gl_lock_addr(gi->hash));
if (gl)
gfs2_glock_put(gl);
while (gi->gl == NULL) { while (gi->gl == NULL) {
gi->hash++; gi->hash++;
if (gi->hash >= GFS2_GL_HASH_SIZE) if (gi->hash >= GFS2_GL_HASH_SIZE) {
rcu_read_unlock();
return 1; return 1;
read_lock(gl_lock_addr(gi->hash));
gi->gl = hlist_entry(gl_hash_table[gi->hash].hb_list.first,
struct gfs2_glock, gl_list);
if (gi->gl)
gfs2_glock_hold(gi->gl);
read_unlock(gl_lock_addr(gi->hash));
} }
gi->gl = glock_hash_chain(gi->hash);
if (gi->sdp != gi->gl->gl_sbd) }
goto restart; /* Skip entries for other sb and dead entries */
} while (gi->sdp != gi->gl->gl_sbd || atomic_read(&gi->gl->gl_ref) == 0);
return 0; return 0;
} }
static void gfs2_glock_iter_free(struct gfs2_glock_iter *gi)
{
if (gi->gl)
gfs2_glock_put(gi->gl);
gi->gl = NULL;
}
static void *gfs2_glock_seq_start(struct seq_file *seq, loff_t *pos) static void *gfs2_glock_seq_start(struct seq_file *seq, loff_t *pos)
{ {
struct gfs2_glock_iter *gi = seq->private; struct gfs2_glock_iter *gi = seq->private;
loff_t n = *pos; loff_t n = *pos;
gi->hash = 0; gi->hash = 0;
rcu_read_lock();
do { do {
if (gfs2_glock_iter_next(gi)) { if (gfs2_glock_iter_next(gi))
gfs2_glock_iter_free(gi);
return NULL; return NULL;
}
} while (n--); } while (n--);
return gi->gl; return gi->gl;
...@@ -1870,10 +1775,8 @@ static void *gfs2_glock_seq_next(struct seq_file *seq, void *iter_ptr, ...@@ -1870,10 +1775,8 @@ static void *gfs2_glock_seq_next(struct seq_file *seq, void *iter_ptr,
(*pos)++; (*pos)++;
if (gfs2_glock_iter_next(gi)) { if (gfs2_glock_iter_next(gi))
gfs2_glock_iter_free(gi);
return NULL; return NULL;
}
return gi->gl; return gi->gl;
} }
...@@ -1881,7 +1784,10 @@ static void *gfs2_glock_seq_next(struct seq_file *seq, void *iter_ptr, ...@@ -1881,7 +1784,10 @@ static void *gfs2_glock_seq_next(struct seq_file *seq, void *iter_ptr,
static void gfs2_glock_seq_stop(struct seq_file *seq, void *iter_ptr) static void gfs2_glock_seq_stop(struct seq_file *seq, void *iter_ptr)
{ {
struct gfs2_glock_iter *gi = seq->private; struct gfs2_glock_iter *gi = seq->private;
gfs2_glock_iter_free(gi);
if (gi->gl)
rcu_read_unlock();
gi->gl = NULL;
} }
static int gfs2_glock_seq_show(struct seq_file *seq, void *iter_ptr) static int gfs2_glock_seq_show(struct seq_file *seq, void *iter_ptr)
......
...@@ -118,7 +118,7 @@ struct lm_lockops { ...@@ -118,7 +118,7 @@ struct lm_lockops {
int (*lm_mount) (struct gfs2_sbd *sdp, const char *fsname); int (*lm_mount) (struct gfs2_sbd *sdp, const char *fsname);
void (*lm_unmount) (struct gfs2_sbd *sdp); void (*lm_unmount) (struct gfs2_sbd *sdp);
void (*lm_withdraw) (struct gfs2_sbd *sdp); void (*lm_withdraw) (struct gfs2_sbd *sdp);
void (*lm_put_lock) (struct kmem_cache *cachep, struct gfs2_glock *gl); void (*lm_put_lock) (struct gfs2_glock *gl);
int (*lm_lock) (struct gfs2_glock *gl, unsigned int req_state, int (*lm_lock) (struct gfs2_glock *gl, unsigned int req_state,
unsigned int flags); unsigned int flags);
void (*lm_cancel) (struct gfs2_glock *gl); void (*lm_cancel) (struct gfs2_glock *gl);
...@@ -174,7 +174,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, ...@@ -174,7 +174,7 @@ int gfs2_glock_get(struct gfs2_sbd *sdp,
int create, struct gfs2_glock **glp); int create, struct gfs2_glock **glp);
void gfs2_glock_hold(struct gfs2_glock *gl); void gfs2_glock_hold(struct gfs2_glock *gl);
void gfs2_glock_put_nolock(struct gfs2_glock *gl); void gfs2_glock_put_nolock(struct gfs2_glock *gl);
int gfs2_glock_put(struct gfs2_glock *gl); void gfs2_glock_put(struct gfs2_glock *gl);
void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, unsigned flags, void gfs2_holder_init(struct gfs2_glock *gl, unsigned int state, unsigned flags,
struct gfs2_holder *gh); struct gfs2_holder *gh);
void gfs2_holder_reinit(unsigned int state, unsigned flags, void gfs2_holder_reinit(unsigned int state, unsigned flags,
...@@ -223,25 +223,22 @@ static inline int gfs2_glock_nq_init(struct gfs2_glock *gl, ...@@ -223,25 +223,22 @@ static inline int gfs2_glock_nq_init(struct gfs2_glock *gl,
return error; return error;
} }
/* Lock Value Block functions */ extern void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state);
extern void gfs2_glock_complete(struct gfs2_glock *gl, int ret);
int gfs2_lvb_hold(struct gfs2_glock *gl); extern void gfs2_reclaim_glock(struct gfs2_sbd *sdp);
void gfs2_lvb_unhold(struct gfs2_glock *gl); extern void gfs2_gl_hash_clear(struct gfs2_sbd *sdp);
extern void gfs2_glock_finish_truncate(struct gfs2_inode *ip);
void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state); extern void gfs2_glock_thaw(struct gfs2_sbd *sdp);
void gfs2_glock_complete(struct gfs2_glock *gl, int ret); extern void gfs2_glock_schedule_for_reclaim(struct gfs2_glock *gl);
void gfs2_reclaim_glock(struct gfs2_sbd *sdp); extern void gfs2_glock_free(struct gfs2_glock *gl);
void gfs2_gl_hash_clear(struct gfs2_sbd *sdp);
void gfs2_glock_finish_truncate(struct gfs2_inode *ip); extern int __init gfs2_glock_init(void);
void gfs2_glock_thaw(struct gfs2_sbd *sdp); extern void gfs2_glock_exit(void);
int __init gfs2_glock_init(void); extern int gfs2_create_debugfs_file(struct gfs2_sbd *sdp);
void gfs2_glock_exit(void); extern void gfs2_delete_debugfs_file(struct gfs2_sbd *sdp);
extern int gfs2_register_debugfs(void);
int gfs2_create_debugfs_file(struct gfs2_sbd *sdp); extern void gfs2_unregister_debugfs(void);
void gfs2_delete_debugfs_file(struct gfs2_sbd *sdp);
int gfs2_register_debugfs(void);
void gfs2_unregister_debugfs(void);
extern const struct lm_lockops gfs2_dlm_ops; extern const struct lm_lockops gfs2_dlm_ops;
......
...@@ -56,20 +56,26 @@ static void gfs2_ail_empty_gl(struct gfs2_glock *gl) ...@@ -56,20 +56,26 @@ static void gfs2_ail_empty_gl(struct gfs2_glock *gl)
BUG_ON(current->journal_info); BUG_ON(current->journal_info);
current->journal_info = &tr; current->journal_info = &tr;
gfs2_log_lock(sdp); spin_lock(&sdp->sd_ail_lock);
while (!list_empty(head)) { while (!list_empty(head)) {
bd = list_entry(head->next, struct gfs2_bufdata, bd = list_entry(head->next, struct gfs2_bufdata,
bd_ail_gl_list); bd_ail_gl_list);
bh = bd->bd_bh; bh = bd->bd_bh;
gfs2_remove_from_ail(bd); gfs2_remove_from_ail(bd);
spin_unlock(&sdp->sd_ail_lock);
bd->bd_bh = NULL; bd->bd_bh = NULL;
bh->b_private = NULL; bh->b_private = NULL;
bd->bd_blkno = bh->b_blocknr; bd->bd_blkno = bh->b_blocknr;
gfs2_log_lock(sdp);
gfs2_assert_withdraw(sdp, !buffer_busy(bh)); gfs2_assert_withdraw(sdp, !buffer_busy(bh));
gfs2_trans_add_revoke(sdp, bd); gfs2_trans_add_revoke(sdp, bd);
gfs2_log_unlock(sdp);
spin_lock(&sdp->sd_ail_lock);
} }
gfs2_assert_withdraw(sdp, !atomic_read(&gl->gl_ail_count)); gfs2_assert_withdraw(sdp, !atomic_read(&gl->gl_ail_count));
gfs2_log_unlock(sdp); spin_unlock(&sdp->sd_ail_lock);
gfs2_trans_end(sdp); gfs2_trans_end(sdp);
gfs2_log_flush(sdp, NULL); gfs2_log_flush(sdp, NULL);
...@@ -206,8 +212,17 @@ static void inode_go_inval(struct gfs2_glock *gl, int flags) ...@@ -206,8 +212,17 @@ static void inode_go_inval(struct gfs2_glock *gl, int flags)
static int inode_go_demote_ok(const struct gfs2_glock *gl) static int inode_go_demote_ok(const struct gfs2_glock *gl)
{ {
struct gfs2_sbd *sdp = gl->gl_sbd; struct gfs2_sbd *sdp = gl->gl_sbd;
struct gfs2_holder *gh;
if (sdp->sd_jindex == gl->gl_object || sdp->sd_rindex == gl->gl_object) if (sdp->sd_jindex == gl->gl_object || sdp->sd_rindex == gl->gl_object)
return 0; return 0;
if (!list_empty(&gl->gl_holders)) {
gh = list_entry(gl->gl_holders.next, struct gfs2_holder, gh_list);
if (gh->gh_list.next != &gl->gl_holders)
return 0;
}
return 1; return 1;
} }
...@@ -271,19 +286,6 @@ static int inode_go_dump(struct seq_file *seq, const struct gfs2_glock *gl) ...@@ -271,19 +286,6 @@ static int inode_go_dump(struct seq_file *seq, const struct gfs2_glock *gl)
return 0; return 0;
} }
/**
* rgrp_go_demote_ok - Check to see if it's ok to unlock a RG's glock
* @gl: the glock
*
* Returns: 1 if it's ok
*/
static int rgrp_go_demote_ok(const struct gfs2_glock *gl)
{
const struct address_space *mapping = (const struct address_space *)(gl + 1);
return !mapping->nrpages;
}
/** /**
* rgrp_go_lock - operation done after an rgrp lock is locked by * rgrp_go_lock - operation done after an rgrp lock is locked by
* a first holder on this node. * a first holder on this node.
...@@ -410,7 +412,6 @@ const struct gfs2_glock_operations gfs2_inode_glops = { ...@@ -410,7 +412,6 @@ const struct gfs2_glock_operations gfs2_inode_glops = {
const struct gfs2_glock_operations gfs2_rgrp_glops = { const struct gfs2_glock_operations gfs2_rgrp_glops = {
.go_xmote_th = rgrp_go_sync, .go_xmote_th = rgrp_go_sync,
.go_inval = rgrp_go_inval, .go_inval = rgrp_go_inval,
.go_demote_ok = rgrp_go_demote_ok,
.go_lock = rgrp_go_lock, .go_lock = rgrp_go_lock,
.go_unlock = rgrp_go_unlock, .go_unlock = rgrp_go_unlock,
.go_dump = gfs2_rgrp_dump, .go_dump = gfs2_rgrp_dump,
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/dlm.h> #include <linux/dlm.h>
#include <linux/buffer_head.h> #include <linux/buffer_head.h>
#include <linux/rcupdate.h>
#include <linux/rculist_bl.h>
#define DIO_WAIT 0x00000010 #define DIO_WAIT 0x00000010
#define DIO_METADATA 0x00000020 #define DIO_METADATA 0x00000020
...@@ -201,7 +203,7 @@ enum { ...@@ -201,7 +203,7 @@ enum {
}; };
struct gfs2_glock { struct gfs2_glock {
struct hlist_node gl_list; struct hlist_bl_node gl_list;
unsigned long gl_flags; /* GLF_... */ unsigned long gl_flags; /* GLF_... */
struct lm_lockname gl_name; struct lm_lockname gl_name;
atomic_t gl_ref; atomic_t gl_ref;
...@@ -234,6 +236,7 @@ struct gfs2_glock { ...@@ -234,6 +236,7 @@ struct gfs2_glock {
atomic_t gl_ail_count; atomic_t gl_ail_count;
struct delayed_work gl_work; struct delayed_work gl_work;
struct work_struct gl_delete; struct work_struct gl_delete;
struct rcu_head gl_rcu;
}; };
#define GFS2_MIN_LVB_SIZE 32 /* Min size of LVB that gfs2 supports */ #define GFS2_MIN_LVB_SIZE 32 /* Min size of LVB that gfs2 supports */
...@@ -314,6 +317,7 @@ enum { ...@@ -314,6 +317,7 @@ enum {
QDF_USER = 0, QDF_USER = 0,
QDF_CHANGE = 1, QDF_CHANGE = 1,
QDF_LOCKED = 2, QDF_LOCKED = 2,
QDF_REFRESH = 3,
}; };
struct gfs2_quota_data { struct gfs2_quota_data {
...@@ -647,6 +651,7 @@ struct gfs2_sbd { ...@@ -647,6 +651,7 @@ struct gfs2_sbd {
unsigned int sd_log_flush_head; unsigned int sd_log_flush_head;
u64 sd_log_flush_wrapped; u64 sd_log_flush_wrapped;
spinlock_t sd_ail_lock;
struct list_head sd_ail1_list; struct list_head sd_ail1_list;
struct list_head sd_ail2_list; struct list_head sd_ail2_list;
u64 sd_ail_sync_gen; u64 sd_ail_sync_gen;
......
...@@ -22,7 +22,6 @@ static void gdlm_ast(void *arg) ...@@ -22,7 +22,6 @@ static void gdlm_ast(void *arg)
{ {
struct gfs2_glock *gl = arg; struct gfs2_glock *gl = arg;
unsigned ret = gl->gl_state; unsigned ret = gl->gl_state;
struct gfs2_sbd *sdp = gl->gl_sbd;
BUG_ON(gl->gl_lksb.sb_flags & DLM_SBF_DEMOTED); BUG_ON(gl->gl_lksb.sb_flags & DLM_SBF_DEMOTED);
...@@ -31,12 +30,7 @@ static void gdlm_ast(void *arg) ...@@ -31,12 +30,7 @@ static void gdlm_ast(void *arg)
switch (gl->gl_lksb.sb_status) { switch (gl->gl_lksb.sb_status) {
case -DLM_EUNLOCK: /* Unlocked, so glock can be freed */ case -DLM_EUNLOCK: /* Unlocked, so glock can be freed */
if (gl->gl_ops->go_flags & GLOF_ASPACE) gfs2_glock_free(gl);
kmem_cache_free(gfs2_glock_aspace_cachep, gl);
else
kmem_cache_free(gfs2_glock_cachep, gl);
if (atomic_dec_and_test(&sdp->sd_glock_disposal))
wake_up(&sdp->sd_glock_wait);
return; return;
case -DLM_ECANCEL: /* Cancel while getting lock */ case -DLM_ECANCEL: /* Cancel while getting lock */
ret |= LM_OUT_CANCELED; ret |= LM_OUT_CANCELED;
...@@ -164,16 +158,14 @@ static int gdlm_lock(struct gfs2_glock *gl, unsigned int req_state, ...@@ -164,16 +158,14 @@ static int gdlm_lock(struct gfs2_glock *gl, unsigned int req_state,
GDLM_STRNAME_BYTES - 1, 0, gdlm_ast, gl, gdlm_bast); GDLM_STRNAME_BYTES - 1, 0, gdlm_ast, gl, gdlm_bast);
} }
static void gdlm_put_lock(struct kmem_cache *cachep, struct gfs2_glock *gl) static void gdlm_put_lock(struct gfs2_glock *gl)
{ {
struct gfs2_sbd *sdp = gl->gl_sbd; struct gfs2_sbd *sdp = gl->gl_sbd;
struct lm_lockstruct *ls = &sdp->sd_lockstruct; struct lm_lockstruct *ls = &sdp->sd_lockstruct;
int error; int error;
if (gl->gl_lksb.sb_lkid == 0) { if (gl->gl_lksb.sb_lkid == 0) {
kmem_cache_free(cachep, gl); gfs2_glock_free(gl);
if (atomic_dec_and_test(&sdp->sd_glock_disposal))
wake_up(&sdp->sd_glock_wait);
return; return;
} }
......
...@@ -67,7 +67,7 @@ unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct, ...@@ -67,7 +67,7 @@ unsigned int gfs2_struct2blk(struct gfs2_sbd *sdp, unsigned int nstruct,
* @mapping: The associated mapping (maybe NULL) * @mapping: The associated mapping (maybe NULL)
* @bd: The gfs2_bufdata to remove * @bd: The gfs2_bufdata to remove
* *
* The log lock _must_ be held when calling this function * The ail lock _must_ be held when calling this function
* *
*/ */
...@@ -88,8 +88,8 @@ void gfs2_remove_from_ail(struct gfs2_bufdata *bd) ...@@ -88,8 +88,8 @@ void gfs2_remove_from_ail(struct gfs2_bufdata *bd)
*/ */
static void gfs2_ail1_start_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai) static void gfs2_ail1_start_one(struct gfs2_sbd *sdp, struct gfs2_ail *ai)
__releases(&sdp->sd_log_lock) __releases(&sdp->sd_ail_lock)
__acquires(&sdp->sd_log_lock) __acquires(&sdp->sd_ail_lock)
{ {
struct gfs2_bufdata *bd, *s; struct gfs2_bufdata *bd, *s;
struct buffer_head *bh; struct buffer_head *bh;
...@@ -117,7 +117,7 @@ __acquires(&sdp->sd_log_lock) ...@@ -117,7 +117,7 @@ __acquires(&sdp->sd_log_lock)
list_move(&bd->bd_ail_st_list, &ai->ai_ail1_list); list_move(&bd->bd_ail_st_list, &ai->ai_ail1_list);
get_bh(bh); get_bh(bh);
gfs2_log_unlock(sdp); spin_unlock(&sdp->sd_ail_lock);
lock_buffer(bh); lock_buffer(bh);
if (test_clear_buffer_dirty(bh)) { if (test_clear_buffer_dirty(bh)) {
bh->b_end_io = end_buffer_write_sync; bh->b_end_io = end_buffer_write_sync;
...@@ -126,7 +126,7 @@ __acquires(&sdp->sd_log_lock) ...@@ -126,7 +126,7 @@ __acquires(&sdp->sd_log_lock)
unlock_buffer(bh); unlock_buffer(bh);
brelse(bh); brelse(bh);
} }
gfs2_log_lock(sdp); spin_lock(&sdp->sd_ail_lock);
retry = 1; retry = 1;
break; break;
...@@ -175,10 +175,10 @@ static void gfs2_ail1_start(struct gfs2_sbd *sdp) ...@@ -175,10 +175,10 @@ static void gfs2_ail1_start(struct gfs2_sbd *sdp)
struct gfs2_ail *ai; struct gfs2_ail *ai;
int done = 0; int done = 0;
gfs2_log_lock(sdp); spin_lock(&sdp->sd_ail_lock);
head = &sdp->sd_ail1_list; head = &sdp->sd_ail1_list;
if (list_empty(head)) { if (list_empty(head)) {
gfs2_log_unlock(sdp); spin_unlock(&sdp->sd_ail_lock);
return; return;
} }
sync_gen = sdp->sd_ail_sync_gen++; sync_gen = sdp->sd_ail_sync_gen++;
...@@ -189,13 +189,13 @@ static void gfs2_ail1_start(struct gfs2_sbd *sdp) ...@@ -189,13 +189,13 @@ static void gfs2_ail1_start(struct gfs2_sbd *sdp)
if (ai->ai_sync_gen >= sync_gen) if (ai->ai_sync_gen >= sync_gen)
continue; continue;
ai->ai_sync_gen = sync_gen; ai->ai_sync_gen = sync_gen;
gfs2_ail1_start_one(sdp, ai); /* This may drop log lock */ gfs2_ail1_start_one(sdp, ai); /* This may drop ail lock */
done = 0; done = 0;
break; break;
} }
} }
gfs2_log_unlock(sdp); spin_unlock(&sdp->sd_ail_lock);
} }
static int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags) static int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags)
...@@ -203,7 +203,7 @@ static int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags) ...@@ -203,7 +203,7 @@ static int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags)
struct gfs2_ail *ai, *s; struct gfs2_ail *ai, *s;
int ret; int ret;
gfs2_log_lock(sdp); spin_lock(&sdp->sd_ail_lock);
list_for_each_entry_safe_reverse(ai, s, &sdp->sd_ail1_list, ai_list) { list_for_each_entry_safe_reverse(ai, s, &sdp->sd_ail1_list, ai_list) {
if (gfs2_ail1_empty_one(sdp, ai, flags)) if (gfs2_ail1_empty_one(sdp, ai, flags))
...@@ -214,7 +214,7 @@ static int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags) ...@@ -214,7 +214,7 @@ static int gfs2_ail1_empty(struct gfs2_sbd *sdp, int flags)
ret = list_empty(&sdp->sd_ail1_list); ret = list_empty(&sdp->sd_ail1_list);
gfs2_log_unlock(sdp); spin_unlock(&sdp->sd_ail_lock);
return ret; return ret;
} }
...@@ -247,7 +247,7 @@ static void ail2_empty(struct gfs2_sbd *sdp, unsigned int new_tail) ...@@ -247,7 +247,7 @@ static void ail2_empty(struct gfs2_sbd *sdp, unsigned int new_tail)
int wrap = (new_tail < old_tail); int wrap = (new_tail < old_tail);
int a, b, rm; int a, b, rm;
gfs2_log_lock(sdp); spin_lock(&sdp->sd_ail_lock);
list_for_each_entry_safe(ai, safe, &sdp->sd_ail2_list, ai_list) { list_for_each_entry_safe(ai, safe, &sdp->sd_ail2_list, ai_list) {
a = (old_tail <= ai->ai_first); a = (old_tail <= ai->ai_first);
...@@ -263,7 +263,7 @@ static void ail2_empty(struct gfs2_sbd *sdp, unsigned int new_tail) ...@@ -263,7 +263,7 @@ static void ail2_empty(struct gfs2_sbd *sdp, unsigned int new_tail)
kfree(ai); kfree(ai);
} }
gfs2_log_unlock(sdp); spin_unlock(&sdp->sd_ail_lock);
} }
/** /**
...@@ -421,7 +421,7 @@ static unsigned int current_tail(struct gfs2_sbd *sdp) ...@@ -421,7 +421,7 @@ static unsigned int current_tail(struct gfs2_sbd *sdp)
struct gfs2_ail *ai; struct gfs2_ail *ai;
unsigned int tail; unsigned int tail;
gfs2_log_lock(sdp); spin_lock(&sdp->sd_ail_lock);
if (list_empty(&sdp->sd_ail1_list)) { if (list_empty(&sdp->sd_ail1_list)) {
tail = sdp->sd_log_head; tail = sdp->sd_log_head;
...@@ -430,7 +430,7 @@ static unsigned int current_tail(struct gfs2_sbd *sdp) ...@@ -430,7 +430,7 @@ static unsigned int current_tail(struct gfs2_sbd *sdp)
tail = ai->ai_first; tail = ai->ai_first;
} }
gfs2_log_unlock(sdp); spin_unlock(&sdp->sd_ail_lock);
return tail; return tail;
} }
...@@ -743,10 +743,12 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl) ...@@ -743,10 +743,12 @@ void gfs2_log_flush(struct gfs2_sbd *sdp, struct gfs2_glock *gl)
sdp->sd_log_commited_databuf = 0; sdp->sd_log_commited_databuf = 0;
sdp->sd_log_commited_revoke = 0; sdp->sd_log_commited_revoke = 0;
spin_lock(&sdp->sd_ail_lock);
if (!list_empty(&ai->ai_ail1_list)) { if (!list_empty(&ai->ai_ail1_list)) {
list_add(&ai->ai_list, &sdp->sd_ail1_list); list_add(&ai->ai_list, &sdp->sd_ail1_list);
ai = NULL; ai = NULL;
} }
spin_unlock(&sdp->sd_ail_lock);
gfs2_log_unlock(sdp); gfs2_log_unlock(sdp);
trace_gfs2_log_flush(sdp, 0); trace_gfs2_log_flush(sdp, 0);
up_write(&sdp->sd_log_flush_lock); up_write(&sdp->sd_log_flush_lock);
......
...@@ -51,8 +51,10 @@ static void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh) ...@@ -51,8 +51,10 @@ static void gfs2_pin(struct gfs2_sbd *sdp, struct buffer_head *bh)
/* If this buffer is in the AIL and it has already been written /* If this buffer is in the AIL and it has already been written
* to in-place disk block, remove it from the AIL. * to in-place disk block, remove it from the AIL.
*/ */
spin_lock(&sdp->sd_ail_lock);
if (bd->bd_ail) if (bd->bd_ail)
list_move(&bd->bd_ail_st_list, &bd->bd_ail->ai_ail2_list); list_move(&bd->bd_ail_st_list, &bd->bd_ail->ai_ail2_list);
spin_unlock(&sdp->sd_ail_lock);
get_bh(bh); get_bh(bh);
atomic_inc(&sdp->sd_log_pinned); atomic_inc(&sdp->sd_log_pinned);
trace_gfs2_pin(bd, 1); trace_gfs2_pin(bd, 1);
...@@ -80,7 +82,7 @@ static void gfs2_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh, ...@@ -80,7 +82,7 @@ static void gfs2_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh,
mark_buffer_dirty(bh); mark_buffer_dirty(bh);
clear_buffer_pinned(bh); clear_buffer_pinned(bh);
gfs2_log_lock(sdp); spin_lock(&sdp->sd_ail_lock);
if (bd->bd_ail) { if (bd->bd_ail) {
list_del(&bd->bd_ail_st_list); list_del(&bd->bd_ail_st_list);
brelse(bh); brelse(bh);
...@@ -91,9 +93,11 @@ static void gfs2_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh, ...@@ -91,9 +93,11 @@ static void gfs2_unpin(struct gfs2_sbd *sdp, struct buffer_head *bh,
} }
bd->bd_ail = ai; bd->bd_ail = ai;
list_add(&bd->bd_ail_st_list, &ai->ai_ail1_list); list_add(&bd->bd_ail_st_list, &ai->ai_ail1_list);
clear_bit(GLF_LFLUSH, &bd->bd_gl->gl_flags); spin_unlock(&sdp->sd_ail_lock);
if (test_and_clear_bit(GLF_LFLUSH, &bd->bd_gl->gl_flags))
gfs2_glock_schedule_for_reclaim(bd->bd_gl);
trace_gfs2_pin(bd, 0); trace_gfs2_pin(bd, 0);
gfs2_log_unlock(sdp);
unlock_buffer(bh); unlock_buffer(bh);
atomic_dec(&sdp->sd_log_pinned); atomic_dec(&sdp->sd_log_pinned);
} }
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/gfs2_ondisk.h> #include <linux/gfs2_ondisk.h>
#include <linux/rcupdate.h>
#include <linux/rculist_bl.h>
#include <asm/atomic.h> #include <asm/atomic.h>
#include "gfs2.h" #include "gfs2.h"
...@@ -45,7 +47,7 @@ static void gfs2_init_glock_once(void *foo) ...@@ -45,7 +47,7 @@ static void gfs2_init_glock_once(void *foo)
{ {
struct gfs2_glock *gl = foo; struct gfs2_glock *gl = foo;
INIT_HLIST_NODE(&gl->gl_list); INIT_HLIST_BL_NODE(&gl->gl_list);
spin_lock_init(&gl->gl_spin); spin_lock_init(&gl->gl_spin);
INIT_LIST_HEAD(&gl->gl_holders); INIT_LIST_HEAD(&gl->gl_holders);
INIT_LIST_HEAD(&gl->gl_lru); INIT_LIST_HEAD(&gl->gl_lru);
...@@ -191,6 +193,8 @@ static void __exit exit_gfs2_fs(void) ...@@ -191,6 +193,8 @@ static void __exit exit_gfs2_fs(void)
unregister_filesystem(&gfs2meta_fs_type); unregister_filesystem(&gfs2meta_fs_type);
destroy_workqueue(gfs_recovery_wq); destroy_workqueue(gfs_recovery_wq);
rcu_barrier();
kmem_cache_destroy(gfs2_quotad_cachep); kmem_cache_destroy(gfs2_quotad_cachep);
kmem_cache_destroy(gfs2_rgrpd_cachep); kmem_cache_destroy(gfs2_rgrpd_cachep);
kmem_cache_destroy(gfs2_bufdata_cachep); kmem_cache_destroy(gfs2_bufdata_cachep);
......
...@@ -326,6 +326,7 @@ void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr, int ...@@ -326,6 +326,7 @@ void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr, int
brelse(bh); brelse(bh);
} }
if (bd) { if (bd) {
spin_lock(&sdp->sd_ail_lock);
if (bd->bd_ail) { if (bd->bd_ail) {
gfs2_remove_from_ail(bd); gfs2_remove_from_ail(bd);
bh->b_private = NULL; bh->b_private = NULL;
...@@ -333,6 +334,7 @@ void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr, int ...@@ -333,6 +334,7 @@ void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr, int
bd->bd_blkno = bh->b_blocknr; bd->bd_blkno = bh->b_blocknr;
gfs2_trans_add_revoke(sdp, bd); gfs2_trans_add_revoke(sdp, bd);
} }
spin_unlock(&sdp->sd_ail_lock);
} }
clear_buffer_dirty(bh); clear_buffer_dirty(bh);
clear_buffer_uptodate(bh); clear_buffer_uptodate(bh);
......
...@@ -99,6 +99,7 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb) ...@@ -99,6 +99,7 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb)
init_waitqueue_head(&sdp->sd_log_waitq); init_waitqueue_head(&sdp->sd_log_waitq);
init_waitqueue_head(&sdp->sd_logd_waitq); init_waitqueue_head(&sdp->sd_logd_waitq);
spin_lock_init(&sdp->sd_ail_lock);
INIT_LIST_HEAD(&sdp->sd_ail1_list); INIT_LIST_HEAD(&sdp->sd_ail1_list);
INIT_LIST_HEAD(&sdp->sd_ail2_list); INIT_LIST_HEAD(&sdp->sd_ail2_list);
...@@ -928,17 +929,9 @@ static const match_table_t nolock_tokens = { ...@@ -928,17 +929,9 @@ static const match_table_t nolock_tokens = {
{ Opt_err, NULL }, { Opt_err, NULL },
}; };
static void nolock_put_lock(struct kmem_cache *cachep, struct gfs2_glock *gl)
{
struct gfs2_sbd *sdp = gl->gl_sbd;
kmem_cache_free(cachep, gl);
if (atomic_dec_and_test(&sdp->sd_glock_disposal))
wake_up(&sdp->sd_glock_wait);
}
static const struct lm_lockops nolock_ops = { static const struct lm_lockops nolock_ops = {
.lm_proto_name = "lock_nolock", .lm_proto_name = "lock_nolock",
.lm_put_lock = nolock_put_lock, .lm_put_lock = gfs2_glock_free,
.lm_tokens = &nolock_tokens, .lm_tokens = &nolock_tokens,
}; };
......
...@@ -1026,9 +1026,9 @@ static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p) ...@@ -1026,9 +1026,9 @@ static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
/** /**
* gfs2_permission - * gfs2_permission -
* @inode: * @inode: The inode
* @mask: * @mask: The mask to be tested
* @nd: passed from Linux VFS, ignored by us * @flags: Indicates whether this is an RCU path walk or not
* *
* This may be called from the VFS directly, or from within GFS2 with the * This may be called from the VFS directly, or from within GFS2 with the
* inode locked, so we look to see if the glock is already locked and only * inode locked, so we look to see if the glock is already locked and only
...@@ -1044,11 +1044,11 @@ int gfs2_permission(struct inode *inode, int mask, unsigned int flags) ...@@ -1044,11 +1044,11 @@ int gfs2_permission(struct inode *inode, int mask, unsigned int flags)
int error; int error;
int unlock = 0; int unlock = 0;
if (flags & IPERM_FLAG_RCU)
return -ECHILD;
ip = GFS2_I(inode); ip = GFS2_I(inode);
if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) { if (gfs2_glock_is_locked_by_me(ip->i_gl) == NULL) {
if (flags & IPERM_FLAG_RCU)
return -ECHILD;
error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh); error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &i_gh);
if (error) if (error)
return error; return error;
......
...@@ -834,6 +834,7 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda) ...@@ -834,6 +834,7 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda)
goto out_end_trans; goto out_end_trans;
do_qc(qd, -qd->qd_change_sync); do_qc(qd, -qd->qd_change_sync);
set_bit(QDF_REFRESH, &qd->qd_flags);
} }
error = 0; error = 0;
...@@ -929,6 +930,7 @@ int gfs2_quota_lock(struct gfs2_inode *ip, u32 uid, u32 gid) ...@@ -929,6 +930,7 @@ int gfs2_quota_lock(struct gfs2_inode *ip, u32 uid, u32 gid)
{ {
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
struct gfs2_alloc *al = ip->i_alloc; struct gfs2_alloc *al = ip->i_alloc;
struct gfs2_quota_data *qd;
unsigned int x; unsigned int x;
int error = 0; int error = 0;
...@@ -942,7 +944,11 @@ int gfs2_quota_lock(struct gfs2_inode *ip, u32 uid, u32 gid) ...@@ -942,7 +944,11 @@ int gfs2_quota_lock(struct gfs2_inode *ip, u32 uid, u32 gid)
sort_qd, NULL); sort_qd, NULL);
for (x = 0; x < al->al_qd_num; x++) { for (x = 0; x < al->al_qd_num; x++) {
error = do_glock(al->al_qd[x], NO_FORCE, &al->al_qd_ghs[x]); int force = NO_FORCE;
qd = al->al_qd[x];
if (test_and_clear_bit(QDF_REFRESH, &qd->qd_flags))
force = FORCE;
error = do_glock(qd, force, &al->al_qd_ghs[x]);
if (error) if (error)
break; break;
} }
...@@ -1587,6 +1593,8 @@ static int gfs2_set_dqblk(struct super_block *sb, int type, qid_t id, ...@@ -1587,6 +1593,8 @@ static int gfs2_set_dqblk(struct super_block *sb, int type, qid_t id,
offset = qd2offset(qd); offset = qd2offset(qd);
alloc_required = gfs2_write_alloc_required(ip, offset, sizeof(struct gfs2_quota)); alloc_required = gfs2_write_alloc_required(ip, offset, sizeof(struct gfs2_quota));
if (gfs2_is_stuffed(ip))
alloc_required = 1;
if (alloc_required) { if (alloc_required) {
al = gfs2_alloc_get(ip); al = gfs2_alloc_get(ip);
if (al == NULL) if (al == NULL)
...@@ -1600,7 +1608,9 @@ static int gfs2_set_dqblk(struct super_block *sb, int type, qid_t id, ...@@ -1600,7 +1608,9 @@ static int gfs2_set_dqblk(struct super_block *sb, int type, qid_t id,
blocks += gfs2_rg_blocks(al); blocks += gfs2_rg_blocks(al);
} }
error = gfs2_trans_begin(sdp, blocks + RES_DINODE + 1, 0); /* Some quotas span block boundaries and can update two blocks,
adding an extra block to the transaction to handle such quotas */
error = gfs2_trans_begin(sdp, blocks + RES_DINODE + 2, 0);
if (error) if (error)
goto out_release; goto out_release;
......
...@@ -1602,7 +1602,7 @@ int gfs2_alloc_di(struct gfs2_inode *dip, u64 *bn, u64 *generation) ...@@ -1602,7 +1602,7 @@ int gfs2_alloc_di(struct gfs2_inode *dip, u64 *bn, u64 *generation)
* *
*/ */
void gfs2_free_data(struct gfs2_inode *ip, u64 bstart, u32 blen) void __gfs2_free_data(struct gfs2_inode *ip, u64 bstart, u32 blen)
{ {
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
struct gfs2_rgrpd *rgd; struct gfs2_rgrpd *rgd;
...@@ -1617,7 +1617,21 @@ void gfs2_free_data(struct gfs2_inode *ip, u64 bstart, u32 blen) ...@@ -1617,7 +1617,21 @@ void gfs2_free_data(struct gfs2_inode *ip, u64 bstart, u32 blen)
gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data); gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data);
gfs2_trans_add_rg(rgd); gfs2_trans_add_rg(rgd);
}
/**
* gfs2_free_data - free a contiguous run of data block(s)
* @ip: the inode these blocks are being freed from
* @bstart: first block of a run of contiguous blocks
* @blen: the length of the block run
*
*/
void gfs2_free_data(struct gfs2_inode *ip, u64 bstart, u32 blen)
{
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
__gfs2_free_data(ip, bstart, blen);
gfs2_statfs_change(sdp, 0, +blen, 0); gfs2_statfs_change(sdp, 0, +blen, 0);
gfs2_quota_change(ip, -(s64)blen, ip->i_inode.i_uid, ip->i_inode.i_gid); gfs2_quota_change(ip, -(s64)blen, ip->i_inode.i_uid, ip->i_inode.i_gid);
} }
...@@ -1630,7 +1644,7 @@ void gfs2_free_data(struct gfs2_inode *ip, u64 bstart, u32 blen) ...@@ -1630,7 +1644,7 @@ void gfs2_free_data(struct gfs2_inode *ip, u64 bstart, u32 blen)
* *
*/ */
void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen) void __gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen)
{ {
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode); struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
struct gfs2_rgrpd *rgd; struct gfs2_rgrpd *rgd;
...@@ -1645,10 +1659,24 @@ void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen) ...@@ -1645,10 +1659,24 @@ void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen)
gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data); gfs2_rgrp_out(rgd, rgd->rd_bits[0].bi_bh->b_data);
gfs2_trans_add_rg(rgd); gfs2_trans_add_rg(rgd);
gfs2_meta_wipe(ip, bstart, blen);
}
/**
* gfs2_free_meta - free a contiguous run of data block(s)
* @ip: the inode these blocks are being freed from
* @bstart: first block of a run of contiguous blocks
* @blen: the length of the block run
*
*/
void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen)
{
struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
__gfs2_free_meta(ip, bstart, blen);
gfs2_statfs_change(sdp, 0, +blen, 0); gfs2_statfs_change(sdp, 0, +blen, 0);
gfs2_quota_change(ip, -(s64)blen, ip->i_inode.i_uid, ip->i_inode.i_gid); gfs2_quota_change(ip, -(s64)blen, ip->i_inode.i_uid, ip->i_inode.i_gid);
gfs2_meta_wipe(ip, bstart, blen);
} }
void gfs2_unlink_di(struct inode *inode) void gfs2_unlink_di(struct inode *inode)
......
...@@ -52,7 +52,9 @@ extern int gfs2_ri_update(struct gfs2_inode *ip); ...@@ -52,7 +52,9 @@ extern int gfs2_ri_update(struct gfs2_inode *ip);
extern int gfs2_alloc_block(struct gfs2_inode *ip, u64 *bn, unsigned int *n); extern int gfs2_alloc_block(struct gfs2_inode *ip, u64 *bn, unsigned int *n);
extern int gfs2_alloc_di(struct gfs2_inode *ip, u64 *bn, u64 *generation); extern int gfs2_alloc_di(struct gfs2_inode *ip, u64 *bn, u64 *generation);
extern void __gfs2_free_data(struct gfs2_inode *ip, u64 bstart, u32 blen);
extern void gfs2_free_data(struct gfs2_inode *ip, u64 bstart, u32 blen); extern void gfs2_free_data(struct gfs2_inode *ip, u64 bstart, u32 blen);
extern void __gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen);
extern void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen); extern void gfs2_free_meta(struct gfs2_inode *ip, u64 bstart, u32 blen);
extern void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip); extern void gfs2_free_di(struct gfs2_rgrpd *rgd, struct gfs2_inode *ip);
extern void gfs2_unlink_di(struct inode *inode); extern void gfs2_unlink_di(struct inode *inode);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment