GFS2: Protect quota sync generation

Now that gfs2_quota_sync can be potentially called from multiple
threads, we should protect this bit of code, and the sync generation
number in particular in order to ensure that there are no races
when syncing quotas.

Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
Cc: Abhijith Das <adas@redhat.com>
This commit is contained in:
Steven Whitehouse 2013-10-04 12:29:34 +01:00
parent aabd7c72f5
commit e46c772dba
3 changed files with 6 additions and 2 deletions

View File

@ -714,6 +714,7 @@ struct gfs2_sbd {
struct list_head sd_quota_list; struct list_head sd_quota_list;
atomic_t sd_quota_count; atomic_t sd_quota_count;
struct mutex sd_quota_mutex; struct mutex sd_quota_mutex;
struct mutex sd_quota_sync_mutex;
wait_queue_head_t sd_quota_wait; wait_queue_head_t sd_quota_wait;
struct list_head sd_trunc_list; struct list_head sd_trunc_list;
spinlock_t sd_trunc_lock; spinlock_t sd_trunc_lock;

View File

@ -93,6 +93,7 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb)
INIT_LIST_HEAD(&sdp->sd_quota_list); INIT_LIST_HEAD(&sdp->sd_quota_list);
mutex_init(&sdp->sd_quota_mutex); mutex_init(&sdp->sd_quota_mutex);
mutex_init(&sdp->sd_quota_sync_mutex);
init_waitqueue_head(&sdp->sd_quota_wait); init_waitqueue_head(&sdp->sd_quota_wait);
INIT_LIST_HEAD(&sdp->sd_trunc_list); INIT_LIST_HEAD(&sdp->sd_trunc_list);
spin_lock_init(&sdp->sd_trunc_lock); spin_lock_init(&sdp->sd_trunc_lock);

View File

@ -1132,12 +1132,13 @@ int gfs2_quota_sync(struct super_block *sb, int type)
unsigned int x; unsigned int x;
int error = 0; int error = 0;
sdp->sd_quota_sync_gen++;
qda = kcalloc(max_qd, sizeof(struct gfs2_quota_data *), GFP_KERNEL); qda = kcalloc(max_qd, sizeof(struct gfs2_quota_data *), GFP_KERNEL);
if (!qda) if (!qda)
return -ENOMEM; return -ENOMEM;
mutex_lock(&sdp->sd_quota_sync_mutex);
sdp->sd_quota_sync_gen++;
do { do {
num_qd = 0; num_qd = 0;
@ -1162,6 +1163,7 @@ int gfs2_quota_sync(struct super_block *sb, int type)
} }
} while (!error && num_qd == max_qd); } while (!error && num_qd == max_qd);
mutex_unlock(&sdp->sd_quota_sync_mutex);
kfree(qda); kfree(qda);
return error; return error;