Whamcloud - gitweb
Add flock support.
[fs/lustre-release.git] / lustre / llite / file.c
index 2890551..0ac8d65 100644 (file)
@@ -74,7 +74,7 @@ int ll_mdc_close(struct obd_export *mdc_exp, struct inode *inode,
                        inode->i_ino, rc);
         }
         if (rc == 0) {
-                rc = ll_objects_destroy(req, file->f_dentry->d_inode);
+                rc = ll_objects_destroy(req, file->f_dentry->d_inode, 1);
                 if (rc)
                         CERROR("inode %lu ll_objects destroy: rc = %d\n",
                                inode->i_ino, rc);
@@ -229,8 +229,6 @@ int ll_file_open(struct inode *inode, struct file *file)
         if (rc)
                 LBUG();
 
-        ll_intent_drop_lock(it);
-
         if (!S_ISREG(inode->i_mode))
                 GOTO(out, rc);
 
@@ -318,15 +316,27 @@ static int ll_lock_to_stripe_offset(struct inode *inode, struct ldlm_lock *lock)
         ENTRY;
 
         if (lsm->lsm_stripe_count == 1)
-                RETURN(0);
+                GOTO(check, stripe = 0);
 
         /* get our offset in the lov */
         rc = obd_get_info(exp, sizeof(key), &key, &vallen, &stripe);
         if (rc != 0) {
                 CERROR("obd_get_info: rc = %d\n", rc);
-                LBUG();
+                RETURN(rc);
         }
         LASSERT(stripe < lsm->lsm_stripe_count);
+
+check:
+        if (lsm->lsm_oinfo[stripe].loi_id != lock->l_resource->lr_name.name[0]||
+            lsm->lsm_oinfo[stripe].loi_gr != lock->l_resource->lr_name.name[2]){
+                LDLM_ERROR(lock, "resource doesn't match object "LPU64"/"LPU64
+                           " inode=%lu/%u (%p)\n",
+                           lsm->lsm_oinfo[stripe].loi_id,
+                           lsm->lsm_oinfo[stripe].loi_gr,
+                           inode->i_ino, inode->i_generation, inode);
+                RETURN(-ELDLM_NO_LOCK_DATA);
+        }
+
         RETURN(stripe);
 }
 
@@ -405,7 +415,7 @@ void ll_pgcache_remove_extent(struct inode *inode, struct lov_stripe_md *lsm,
                         break;
                 }
 
-                conditional_schedule();
+                cond_resched();
 
                 page = find_get_page(inode->i_mapping, i);
                 if (page == NULL)
@@ -491,6 +501,8 @@ static int ll_extent_lock_callback(struct ldlm_lock *lock,
                 lsm = lli->lli_smd;
 
                 stripe = ll_lock_to_stripe_offset(inode, lock);
+                if (stripe < 0)
+                        goto iput;
                 ll_pgcache_remove_extent(inode, lsm, lock, stripe);
 
                 down(&inode->i_sem);
@@ -538,6 +550,8 @@ int ll_async_completion_ast(struct ldlm_lock *lock, int flags, void *data)
         LDLM_DEBUG(lock, "client-side async enqueue: granted/glimpsed");
 
         stripe = ll_lock_to_stripe_offset(inode, lock);
+        if (stripe < 0)
+                goto iput;
 
         if (lock->l_lvb_len) {
                 struct lov_stripe_md *lsm = lli->lli_smd;
@@ -555,6 +569,7 @@ int ll_async_completion_ast(struct ldlm_lock *lock, int flags, void *data)
                 up(&inode->i_sem);
         }
 
+iput:
         iput(inode);
         wake_up(&lock->l_waitq);
 
@@ -570,7 +585,7 @@ static int ll_glimpse_callback(struct ldlm_lock *lock, void *reqp)
         struct inode *inode = ll_inode_from_lock(lock);
         struct ll_inode_info *lli;
         struct ost_lvb *lvb;
-        int rc, size = sizeof(*lvb), stripe = 0;
+        int rc, size = sizeof(*lvb), stripe;
         ENTRY;
 
         if (inode == NULL)
@@ -582,8 +597,9 @@ static int ll_glimpse_callback(struct ldlm_lock *lock, void *reqp)
                 GOTO(iput, rc = -ELDLM_NO_LOCK_DATA);
 
         /* First, find out which stripe index this lock corresponds to. */
-        if (lli->lli_smd->lsm_stripe_count > 1)
-                stripe = ll_lock_to_stripe_offset(inode, lock);
+        stripe = ll_lock_to_stripe_offset(inode, lock);
+        if (stripe < 0)
+                GOTO(iput, rc = -ELDLM_NO_LOCK_DATA);
 
         rc = lustre_pack_reply(req, 1, &size, NULL);
         if (rc) {
@@ -1281,12 +1297,21 @@ int ll_file_flock(struct file *file, int cmd, struct file_lock *file_lock)
 
         switch (cmd) {
         case F_SETLKW:
+#ifdef F_SETLKW64
+        case F_SETLKW64:
+#endif
                 flags = 0;
                 break;
         case F_SETLK:
+#ifdef F_SETLK64
+        case F_SETLK64:
+#endif
                 flags = LDLM_FL_BLOCK_NOWAIT;
                 break;
         case F_GETLK:
+#ifdef F_GETLK64
+        case F_GETLK64:
+#endif
                 flags = LDLM_FL_TEST_LOCK;
                 /* Save the old mode so that if the mode in the lock changes we
                  * can decrement the appropriate reader or writer refcount. */
@@ -1302,7 +1327,8 @@ int ll_file_flock(struct file *file, int cmd, struct file_lock *file_lock)
                flags, mode, flock.l_flock.start, flock.l_flock.end);
 
         obddev = md_get_real_obd(sbi->ll_mdc_exp, NULL, 0);
-        rc = ldlm_cli_enqueue(sbi->ll_mdc_exp, NULL, obddev->obd_namespace,
+        rc = ldlm_cli_enqueue(obddev->obd_self_export, NULL,
+                              obddev->obd_namespace,
                               res_id, LDLM_FLOCK, &flock, mode, &flags,
                               NULL, ldlm_flock_completion_ast, NULL, file_lock,
                               NULL, 0, NULL, &lockh);
@@ -1414,7 +1440,7 @@ struct file_operations ll_file_operations = {
         .sendfile       = generic_file_sendfile,
 #endif
         .fsync          = ll_fsync,
-        //.lock           ll_file_flock
+        .lock           = ll_file_flock
 };
 
 struct inode_operations ll_file_inode_operations = {