Whamcloud - gitweb
LU-3157 llite: A not locked mutex can be unlocked.
[fs/lustre-release.git] / lustre / llite / file.c
index cc55607..85c3944 100644 (file)
@@ -55,7 +55,11 @@ struct ll_file_data *ll_file_data_get(void)
        struct ll_file_data *fd;
 
        OBD_SLAB_ALLOC_PTR_GFP(fd, ll_file_data_slab, CFS_ALLOC_IO);
+       if (fd == NULL)
+               return NULL;
+
        fd->fd_write_failed = false;
+
        return fd;
 }
 
@@ -95,8 +99,9 @@ static void ll_prepare_close(struct inode *inode, struct md_op_data *op_data,
 {
         ENTRY;
 
-        op_data->op_attr.ia_valid = ATTR_MODE | ATTR_ATIME_SET |
-                                 ATTR_MTIME_SET | ATTR_CTIME_SET;
+       op_data->op_attr.ia_valid = ATTR_MODE | ATTR_ATIME | ATTR_ATIME_SET |
+                                       ATTR_MTIME | ATTR_MTIME_SET |
+                                       ATTR_CTIME | ATTR_CTIME_SET;
 
         if (!(och->och_flags & FMODE_WRITE))
                 goto out;
@@ -521,12 +526,12 @@ int ll_file_open(struct inode *inode, struct file *file)
         it = file->private_data; /* XXX: compat macro */
         file->private_data = NULL; /* prevent ll_local_open assertion */
 
-        fd = ll_file_data_get();
-        if (fd == NULL)
-                GOTO(out_och_free, rc = -ENOMEM);
+       fd = ll_file_data_get();
+       if (fd == NULL)
+               GOTO(out_openerr, rc = -ENOMEM);
 
-        fd->fd_file = file;
-        if (S_ISDIR(inode->i_mode)) {
+       fd->fd_file = file;
+       if (S_ISDIR(inode->i_mode)) {
                spin_lock(&lli->lli_sa_lock);
                if (lli->lli_opendir_key == NULL && lli->lli_sai == NULL &&
                    lli->lli_opendir_pid == 0) {
@@ -535,7 +540,7 @@ int ll_file_open(struct inode *inode, struct file *file)
                        opendir_set = 1;
                }
                spin_unlock(&lli->lli_sa_lock);
-        }
+       }
 
         if (inode->i_sb->s_root == file->f_dentry) {
                 LUSTRE_FPRIVATE(file) = fd;
@@ -2662,11 +2667,11 @@ int ll_have_md_lock(struct inode *inode, __u64 *bits,  ldlm_mode_t l_req_mode)
         CDEBUG(D_INFO, "trying to match res "DFID" mode %s\n", PFID(fid),
                ldlm_lockname[mode]);
 
-        flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING | LDLM_FL_TEST_LOCK;
-        for (i = 0; i < MDS_INODELOCK_MAXSHIFT && *bits != 0; i++) {
-                policy.l_inodebits.bits = *bits & (1 << i);
-                if (policy.l_inodebits.bits == 0)
-                        continue;
+       flags = LDLM_FL_BLOCK_GRANTED | LDLM_FL_CBPENDING | LDLM_FL_TEST_LOCK;
+       for (i = 0; i <= MDS_INODELOCK_MAXSHIFT && *bits != 0; i++) {
+               policy.l_inodebits.bits = *bits & (1 << i);
+               if (policy.l_inodebits.bits == 0)
+                       continue;
 
                 if (md_lock_match(ll_i2mdexp(inode), flags, fid, LDLM_IBITS,
                                   &policy, mode, &lockh)) {
@@ -2778,7 +2783,7 @@ int __ll_inode_revalidate_it(struct dentry *dentry, struct lookup_intent *it,
                    here to preserve get_cwd functionality on 2.6.
                    Bug 10503 */
                if (!dentry->d_inode->i_nlink)
-                       d_lustre_invalidate(dentry);
+                       d_lustre_invalidate(dentry, 0);
 
                 ll_lookup_finish_locks(&oit, dentry);
         } else if (!ll_have_md_lock(dentry->d_inode, &ibits, LCK_MINMODE)) {
@@ -3328,6 +3333,9 @@ static int ll_layout_lock_set(struct lustre_handle *lockh, ldlm_mode_t mode,
        LDLM_DEBUG(lock, "File %p/"DFID" being reconfigured: %d.\n",
                inode, PFID(&lli->lli_fid), reconf);
 
+       /* in case this is a caching lock and reinstate with new inode */
+       md_set_lock_data(sbi->ll_md_exp, &lockh->cookie, inode, NULL);
+
        lock_res_and_lock(lock);
        lvb_ready = !!(lock->l_flags & LDLM_FL_LVB_READY);
        unlock_res_and_lock(lock);
@@ -3496,8 +3504,6 @@ again:
 
        ll_finish_md_op_data(op_data);
 
-       md_set_lock_data(sbi->ll_md_exp, &it.d.lustre.it_lock_handle, inode, NULL);
-
        mode = it.d.lustre.it_lock_mode;
        it.d.lustre.it_lock_mode = 0;
        ll_intent_drop_lock(&it);