Commit 45b2a010 authored by John L. Hammond's avatar John L. Hammond Committed by Greg Kroah-Hartman

staging/lustre/llite: fix open lock matching in ll_md_blocking_ast()

In ll_md_blocking_ast() match open locks before all others, ensuring
that MDS_INODELOCK_OPEN is not cleared from bits by another open lock
with a different mode. Change the int flags parameter of
ll_md_real_close() to fmode_t fmode. Clean up verious style issues in
both functions.
Signed-off-by: default avatarJohn L. Hammond <john.hammond@intel.com>
Reviewed-on: http://review.whamcloud.com/8718
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-4429Reviewed-by: default avatarNiu Yawei <yawei.niu@intel.com>
Reviewed-by: default avatarJinshan Xiong <jinshan.xiong@intel.com>
Reviewed-by: default avatarOleg Drokin <oleg.drokin@intel.com>
Signed-off-by: default avatarOleg Drokin <oleg.drokin@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent da62fa24
...@@ -205,7 +205,7 @@ static int ll_close_inode_openhandle(struct obd_export *md_exp, ...@@ -205,7 +205,7 @@ static int ll_close_inode_openhandle(struct obd_export *md_exp,
return rc; return rc;
} }
int ll_md_real_close(struct inode *inode, int flags) int ll_md_real_close(struct inode *inode, fmode_t fmode)
{ {
struct ll_inode_info *lli = ll_i2info(inode); struct ll_inode_info *lli = ll_i2info(inode);
struct obd_client_handle **och_p; struct obd_client_handle **och_p;
...@@ -213,30 +213,33 @@ int ll_md_real_close(struct inode *inode, int flags) ...@@ -213,30 +213,33 @@ int ll_md_real_close(struct inode *inode, int flags)
__u64 *och_usecount; __u64 *och_usecount;
int rc = 0; int rc = 0;
if (flags & FMODE_WRITE) { if (fmode & FMODE_WRITE) {
och_p = &lli->lli_mds_write_och; och_p = &lli->lli_mds_write_och;
och_usecount = &lli->lli_open_fd_write_count; och_usecount = &lli->lli_open_fd_write_count;
} else if (flags & FMODE_EXEC) { } else if (fmode & FMODE_EXEC) {
och_p = &lli->lli_mds_exec_och; och_p = &lli->lli_mds_exec_och;
och_usecount = &lli->lli_open_fd_exec_count; och_usecount = &lli->lli_open_fd_exec_count;
} else { } else {
LASSERT(flags & FMODE_READ); LASSERT(fmode & FMODE_READ);
och_p = &lli->lli_mds_read_och; och_p = &lli->lli_mds_read_och;
och_usecount = &lli->lli_open_fd_read_count; och_usecount = &lli->lli_open_fd_read_count;
} }
mutex_lock(&lli->lli_och_mutex); mutex_lock(&lli->lli_och_mutex);
if (*och_usecount) { /* There are still users of this handle, so if (*och_usecount > 0) {
skip freeing it. */ /* There are still users of this handle, so skip
* freeing it. */
mutex_unlock(&lli->lli_och_mutex); mutex_unlock(&lli->lli_och_mutex);
return 0; return 0;
} }
och=*och_p; och=*och_p;
*och_p = NULL; *och_p = NULL;
mutex_unlock(&lli->lli_och_mutex); mutex_unlock(&lli->lli_och_mutex);
if (och) { /* There might be a race and somebody have freed this och if (och != NULL) {
already */ /* There might be a race and this handle may already
be closed. */
rc = ll_close_inode_openhandle(ll_i2sbi(inode)->ll_md_exp, rc = ll_close_inode_openhandle(ll_i2sbi(inode)->ll_md_exp,
inode, och, NULL); inode, och, NULL);
} }
......
...@@ -775,7 +775,7 @@ int ll_local_open(struct file *file, ...@@ -775,7 +775,7 @@ int ll_local_open(struct file *file,
int ll_release_openhandle(struct dentry *, struct lookup_intent *); int ll_release_openhandle(struct dentry *, struct lookup_intent *);
int ll_md_close(struct obd_export *md_exp, struct inode *inode, int ll_md_close(struct obd_export *md_exp, struct inode *inode,
struct file *file); struct file *file);
int ll_md_real_close(struct inode *inode, int flags); int ll_md_real_close(struct inode *inode, fmode_t fmode);
void ll_ioepoch_close(struct inode *inode, struct md_op_data *op_data, void ll_ioepoch_close(struct inode *inode, struct md_op_data *op_data,
struct obd_client_handle **och, unsigned long flags); struct obd_client_handle **och, unsigned long flags);
void ll_done_writing_attr(struct inode *inode, struct md_op_data *op_data); void ll_done_writing_attr(struct inode *inode, struct md_op_data *op_data);
......
...@@ -195,101 +195,107 @@ static void ll_invalidate_negative_children(struct inode *dir) ...@@ -195,101 +195,107 @@ static void ll_invalidate_negative_children(struct inode *dir)
int ll_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc, int ll_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
void *data, int flag) void *data, int flag)
{ {
int rc;
struct lustre_handle lockh; struct lustre_handle lockh;
int rc;
switch (flag) { switch (flag) {
case LDLM_CB_BLOCKING: case LDLM_CB_BLOCKING:
ldlm_lock2handle(lock, &lockh); ldlm_lock2handle(lock, &lockh);
rc = ldlm_cli_cancel(&lockh, LCF_ASYNC); rc = ldlm_cli_cancel(&lockh, LCF_ASYNC);
if (rc < 0) { if (rc < 0) {
CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc); CDEBUG(D_INODE, "ldlm_cli_cancel: rc = %d\n", rc);
return rc; return rc;
} }
break; break;
case LDLM_CB_CANCELING: { case LDLM_CB_CANCELING: {
struct inode *inode = ll_inode_from_resource_lock(lock); struct inode *inode = ll_inode_from_resource_lock(lock);
struct ll_inode_info *lli;
__u64 bits = lock->l_policy_data.l_inodebits.bits; __u64 bits = lock->l_policy_data.l_inodebits.bits;
struct lu_fid *fid;
ldlm_mode_t mode = lock->l_req_mode;
/* Inode is set to lock->l_resource->lr_lvb_inode /* Inode is set to lock->l_resource->lr_lvb_inode
* for mdc - bug 24555 */ * for mdc - bug 24555 */
LASSERT(lock->l_ast_data == NULL); LASSERT(lock->l_ast_data == NULL);
/* Invalidate all dentries associated with this inode */
if (inode == NULL) if (inode == NULL)
break; break;
/* Invalidate all dentries associated with this inode */
LASSERT(lock->l_flags & LDLM_FL_CANCELING); LASSERT(lock->l_flags & LDLM_FL_CANCELING);
if (bits & MDS_INODELOCK_XATTR) if (!fid_res_name_eq(ll_inode2fid(inode),
&lock->l_resource->lr_name)) {
LDLM_ERROR(lock, "data mismatch with object "DFID"(%p)",
PFID(ll_inode2fid(inode)), inode);
LBUG();
}
if (bits & MDS_INODELOCK_XATTR) {
ll_xattr_cache_destroy(inode); ll_xattr_cache_destroy(inode);
bits &= ~MDS_INODELOCK_XATTR;
}
/* For OPEN locks we differentiate between lock modes /* For OPEN locks we differentiate between lock modes
* LCK_CR, LCK_CW, LCK_PR - bug 22891 */ * LCK_CR, LCK_CW, LCK_PR - bug 22891 */
if (bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE |
MDS_INODELOCK_LAYOUT | MDS_INODELOCK_PERM))
ll_have_md_lock(inode, &bits, LCK_MINMODE);
if (bits & MDS_INODELOCK_OPEN) if (bits & MDS_INODELOCK_OPEN)
ll_have_md_lock(inode, &bits, mode); ll_have_md_lock(inode, &bits, lock->l_req_mode);
fid = ll_inode2fid(inode);
if (!fid_res_name_eq(fid, &lock->l_resource->lr_name))
LDLM_ERROR(lock, "data mismatch with object "
DFID" (%p)", PFID(fid), inode);
if (bits & MDS_INODELOCK_OPEN) { if (bits & MDS_INODELOCK_OPEN) {
int flags = 0; fmode_t fmode;
switch (lock->l_req_mode) { switch (lock->l_req_mode) {
case LCK_CW: case LCK_CW:
flags = FMODE_WRITE; fmode = FMODE_WRITE;
break; break;
case LCK_PR: case LCK_PR:
flags = FMODE_EXEC; fmode = FMODE_EXEC;
break; break;
case LCK_CR: case LCK_CR:
flags = FMODE_READ; fmode = FMODE_READ;
break; break;
default: default:
CERROR("Unexpected lock mode for OPEN lock " LDLM_ERROR(lock, "bad lock mode for OPEN lock");
"%d, inode %ld\n", lock->l_req_mode, LBUG();
inode->i_ino);
} }
ll_md_real_close(inode, flags);
ll_md_real_close(inode, fmode);
} }
lli = ll_i2info(inode); if (bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE |
MDS_INODELOCK_LAYOUT | MDS_INODELOCK_PERM))
ll_have_md_lock(inode, &bits, LCK_MINMODE);
if (bits & MDS_INODELOCK_LAYOUT) { if (bits & MDS_INODELOCK_LAYOUT) {
struct cl_object_conf conf = { { 0 } }; struct cl_object_conf conf = {
.coc_opc = OBJECT_CONF_INVALIDATE,
.coc_inode = inode,
};
conf.coc_opc = OBJECT_CONF_INVALIDATE;
conf.coc_inode = inode;
rc = ll_layout_conf(inode, &conf); rc = ll_layout_conf(inode, &conf);
if (rc) if (rc < 0)
CDEBUG(D_INODE, "invaliding layout %d.\n", rc); CDEBUG(D_INODE, "cannot invalidate layout of "
DFID": rc = %d\n",
PFID(ll_inode2fid(inode)), rc);
} }
if (bits & MDS_INODELOCK_UPDATE) { if (bits & MDS_INODELOCK_UPDATE) {
struct ll_inode_info *lli = ll_i2info(inode);
spin_lock(&lli->lli_lock); spin_lock(&lli->lli_lock);
lli->lli_flags &= ~LLIF_MDS_SIZE_LOCK; lli->lli_flags &= ~LLIF_MDS_SIZE_LOCK;
spin_unlock(&lli->lli_lock); spin_unlock(&lli->lli_lock);
} }
if (S_ISDIR(inode->i_mode) && if ((bits & MDS_INODELOCK_UPDATE) && S_ISDIR(inode->i_mode)) {
(bits & MDS_INODELOCK_UPDATE)) {
CDEBUG(D_INODE, "invalidating inode %lu\n", CDEBUG(D_INODE, "invalidating inode %lu\n",
inode->i_ino); inode->i_ino);
truncate_inode_pages(inode->i_mapping, 0); truncate_inode_pages(inode->i_mapping, 0);
ll_invalidate_negative_children(inode); ll_invalidate_negative_children(inode);
} }
if (inode->i_sb->s_root && if ((bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM)) &&
inode != inode->i_sb->s_root->d_inode && inode->i_sb->s_root != NULL &&
(bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM))) inode != inode->i_sb->s_root->d_inode)
ll_invalidate_aliases(inode); ll_invalidate_aliases(inode);
iput(inode); iput(inode);
break; break;
} }
......
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