Whamcloud - gitweb
land 0.5.20.3 b_devel onto HEAD (b_devel will remain)
[fs/lustre-release.git] / lustre / ldlm / ldlm_extent.c
index b334e4a..9b10854 100644 (file)
@@ -1,20 +1,34 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- * Copyright (C) 2002 Cluster File Systems, Inc.
+ *  Copyright (c) 2002 Cluster File Systems, Inc.
+ *   Author: Peter Braam <braam@clusterfs.com>
+ *   Author: Phil Schwan <phil@clusterfs.com>
  *
- * This code is issued under the GNU General Public License.
- * See the file COPYING in this distribution
+ *   This file is part of Lustre, http://www.lustre.org.
  *
- * by Cluster File Systems, Inc.
- * authors, Peter Braam <braam@clusterfs.com> & 
- * Phil Schwan <phil@clusterfs.com>
+ *   Lustre is free software; you can redistribute it and/or
+ *   modify it under the terms of version 2 of the GNU General Public
+ *   License as published by the Free Software Foundation.
+ *
+ *   Lustre is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Lustre; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#define EXPORT_SYMTAB
 #define DEBUG_SUBSYSTEM S_LDLM
+#ifndef __KERNEL__
+# include <liblustre.h>
+#endif
 
 #include <linux/lustre_dlm.h>
+#include <linux/obd_support.h>
+#include <linux/lustre_lib.h>
 
 /* This function will be called to judge if the granted queue of another child
  * (read: another extent) is conflicting and needs its granted queue walked to
@@ -31,6 +45,14 @@ int ldlm_extent_compat(struct ldlm_lock *a, struct ldlm_lock *b)
         RETURN(1);
 }
 
+/* The purpose of this function is to return:
+ * - the maximum extent
+ * - containing the requested extent
+ * - and not overlapping existing extents outside the requested one
+ *
+ * An alternative policy is to not shrink the new extent when conflicts exist.
+ *
+ * To reconstruct our formulas, take a deep breath. */
 static void policy_internal(struct list_head *queue, struct ldlm_extent *req_ex,
                             struct ldlm_extent *new_ex, ldlm_mode_t mode)
 {
@@ -40,17 +62,17 @@ static void policy_internal(struct list_head *queue, struct ldlm_extent *req_ex,
                 struct ldlm_lock *lock;
                 lock = list_entry(tmp, struct ldlm_lock, l_res_link);
 
-                if (lock->l_extent.end < req_ex->start)
+                if (lock->l_extent.end < req_ex->start) {
                         new_ex->start = MIN(lock->l_extent.end, new_ex->start);
-                else {
+                else {
                         if (lock->l_extent.start < req_ex->start &&
                             !lockmode_compat(lock->l_req_mode, mode))
                                 /* Policy: minimize conflict overlap */
                                 new_ex->start = req_ex->start;
                 }
-                if (lock->l_extent.start > req_ex->end)
+                if (lock->l_extent.start > req_ex->end) {
                         new_ex->end = MAX(lock->l_extent.start, new_ex->end);
-                else {
+                else {
                         if (lock->l_extent.end > req_ex->end &&
                             !lockmode_compat(lock->l_req_mode, mode))
                                 /* Policy: minimize conflict overlap */
@@ -59,28 +81,34 @@ static void policy_internal(struct list_head *queue, struct ldlm_extent *req_ex,
         }
 }
 
-/* The purpose of this function is to return:
- * - the maximum extent
- * - containing the requested extent
- * - and not overlapping existing extents outside the requested one
- *
- * An alternative policy is to not shrink the new extent when conflicts exist.
- *
- * To reconstruct our formulas, take a deep breath. */
-int ldlm_extent_policy(struct ldlm_resource *res, struct ldlm_extent *req_ex,
-                       struct ldlm_extent *new_ex, ldlm_mode_t mode, void *data)
+/* apply the internal policy by walking all the lists */
+int ldlm_extent_policy(struct ldlm_namespace *ns, struct ldlm_lock **lockp,
+                       void *req_cookie, ldlm_mode_t mode, int flags,
+                       void *data)
 {
-        new_ex->start = 0;
-        new_ex->end = ~0;
+        struct ldlm_lock *lock = *lockp;
+        struct ldlm_resource *res = lock->l_resource;
+        struct ldlm_extent *req_ex = req_cookie;
+        struct ldlm_extent new_ex;
+        new_ex.start = 0;
+        new_ex.end = ~0;
 
         if (!res)
                 LBUG();
 
-        policy_internal(&res->lr_granted, req_ex, new_ex, mode);
-        policy_internal(&res->lr_converting, req_ex, new_ex, mode);
-        policy_internal(&res->lr_waiting, req_ex, new_ex, mode);
+        l_lock(&ns->ns_lock);
+        policy_internal(&res->lr_granted, req_ex, &new_ex, mode);
+        policy_internal(&res->lr_converting, req_ex, &new_ex, mode);
+        policy_internal(&res->lr_waiting, req_ex, &new_ex, mode);
+        l_unlock(&ns->ns_lock);
+
+        memcpy(&lock->l_extent, &new_ex, sizeof(new_ex));
+
+        LDLM_DEBUG(lock, "new extent "LPU64" -> "LPU64, new_ex.start,
+                   new_ex.end);
 
-        if (new_ex->end != req_ex->end || new_ex->start != req_ex->start)
+        if (new_ex.end != req_ex->end || new_ex.start != req_ex->start)
                 return ELDLM_LOCK_CHANGED;
-        return 0;
+        else 
+                return 0;
 }