From: Niu Yawei Date: Thu, 5 Jan 2012 05:30:54 +0000 (-0800) Subject: LU-952 quota: follow locking order of quota code X-Git-Tag: v1_8_7_81_WC1~26 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=7dc058bfa97f4ae7a544ddb30109d5fe06c41dc5;p=fs%2Flustre-release.git LU-952 quota: follow locking order of quota code The locking order of quota code is: i_mutex > dqonoff_sem > journal_lock > dqptr_sem > dquot->dq_lock > dqio_mutex, so we should call the ll_vfs_dq_init() after journal started to avoid deadlock. Signed-off-by: Niu Yawei Change-Id: I7f805abc3105e338dd60bc632d860be5389d87ec Reviewed-on: http://review.whamcloud.com/1919 Tested-by: Hudson Reviewed-by: Johann Lombardi Tested-by: Maloo Reviewed-by: Fan Yong --- diff --git a/lustre/obdfilter/filter.c b/lustre/obdfilter/filter.c index 4a155c2..ca785a1 100644 --- a/lustre/obdfilter/filter.c +++ b/lustre/obdfilter/filter.c @@ -1518,9 +1518,7 @@ int filter_vfs_unlink(struct inode *dir, struct dentry *dentry, IS_IMMUTABLE(dentry->d_inode)) GOTO(out, rc = -EPERM); - /* NOTE: This might need to go outside i_mutex, though it isn't clear if - * that was done because of journal_start (which is already done - * here) or some other ordering issue. */ + /* Locking order: i_mutex -> journal_lock -> dqptr_sem. LU-952 */ ll_vfs_dq_init(dir); rc = ll_security_inode_unlink(dir, dentry, mnt); @@ -2832,7 +2830,6 @@ int filter_setattr_internal(struct obd_export *exp, struct dentry *dentry, *fcc = oa->o_lcookie; } if (ia_valid & (ATTR_SIZE | ATTR_UID | ATTR_GID)) { - ll_vfs_dq_init(inode); /* Filter truncates and writes are serialized by * i_alloc_sem, see the comment in * filter_preprw_write.*/ @@ -2904,6 +2901,10 @@ int filter_setattr_internal(struct obd_export *exp, struct dentry *dentry, GOTO(out_unlock, rc = PTR_ERR(handle)); } + /* Locking order: i_mutex -> journal_lock -> dqptr_sem. LU-952 */ + if (ia_valid & (ATTR_SIZE | ATTR_UID | ATTR_GID)) + ll_vfs_dq_init(inode); + if (oa->o_valid & OBD_MD_FLFLAGS) { rc = fsfilt_iocontrol(exp->exp_obd, dentry, FSFILT_IOC_SETFLAGS, (long)&oa->o_flags); @@ -3673,7 +3674,6 @@ int filter_destroy(struct obd_export *exp, struct obdo *oa, if (fcc != NULL) *fcc = oa->o_lcookie; } - ll_vfs_dq_init(dchild->d_inode); /* we're gonna truncate it first in order to avoid possible deadlock: * P1 P2 @@ -3706,6 +3706,9 @@ int filter_destroy(struct obd_export *exp, struct obdo *oa, GOTO(cleanup, rc = PTR_ERR(handle)); } + /* Locking order: i_mutex -> journal_lock -> dqptr_sem. LU-952 */ + ll_vfs_dq_init(dchild->d_inode); + iattr.ia_valid = ATTR_SIZE; iattr.ia_size = 0; rc = fsfilt_setattr(obd, dchild, handle, &iattr, 1); diff --git a/lustre/obdfilter/filter_io_26.c b/lustre/obdfilter/filter_io_26.c index abd93d9..dbd90d6 100644 --- a/lustre/obdfilter/filter_io_26.c +++ b/lustre/obdfilter/filter_io_26.c @@ -691,7 +691,6 @@ int filter_commitrw_write(struct obd_export *exp, struct obdo *oa, push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL); cleanup_phase = 2; - ll_vfs_dq_init(inode); fsfilt_check_slow(obd, now, "quota init"); retry: @@ -711,6 +710,9 @@ retry: fsfilt_check_slow(obd, now, "brw_start"); + /* Locking order: i_mutex -> journal_lock -> dqptr_sem. LU-952 */ + ll_vfs_dq_init(inode); + i = OBD_MD_FLATIME | OBD_MD_FLMTIME | OBD_MD_FLCTIME; /* If the inode still has SUID+SGID bits set (see filter_precreate())