Whamcloud - gitweb
b=13872
authoryury <yury>
Mon, 5 Nov 2007 15:17:14 +0000 (15:17 +0000)
committeryury <yury>
Mon, 5 Nov 2007 15:17:14 +0000 (15:17 +0000)
r=adilger,nathan
- cleanups and fixes in ldlm lru resize and ldlm code.

lustre/include/lustre_dlm.h
lustre/include/lustre_export.h
lustre/ldlm/l_lock.c
lustre/ldlm/ldlm_flock.c
lustre/ldlm/ldlm_lib.c
lustre/ldlm/ldlm_lock.c
lustre/ldlm/ldlm_lockd.c
lustre/ldlm/ldlm_pool.c
lustre/ldlm/ldlm_request.c
lustre/ldlm/ldlm_resource.c

index 09e0c35..ebcc6bb 100644 (file)
@@ -43,8 +43,8 @@ typedef enum {
 } ldlm_error_t;
 
 typedef enum {
-        LDLM_NAMESPACE_SERVER = 0,
-        LDLM_NAMESPACE_CLIENT = 1
+        LDLM_NAMESPACE_SERVER = 1 << 0,
+        LDLM_NAMESPACE_CLIENT = 1 << 1
 } ldlm_side_t;
 
 #define LDLM_FL_LOCK_CHANGED   0x000001 /* extent, mode, or resource changed */
@@ -341,10 +341,30 @@ struct ldlm_namespace {
         struct adaptive_timeout ns_at_estimate;/* estimated lock callback time*/
 };
 
+static inline int ns_is_client(struct ldlm_namespace *ns)
+{
+        LASSERT(ns != NULL);
+        LASSERT(!(ns->ns_client & ~(LDLM_NAMESPACE_CLIENT | 
+                                    LDLM_NAMESPACE_SERVER)));
+        LASSERT(ns->ns_client == LDLM_NAMESPACE_CLIENT ||
+                ns->ns_client == LDLM_NAMESPACE_SERVER);
+        return ns->ns_client == LDLM_NAMESPACE_CLIENT;
+}
+
+static inline int ns_is_server(struct ldlm_namespace *ns)
+{
+        LASSERT(ns != NULL);
+        LASSERT(!(ns->ns_client & ~(LDLM_NAMESPACE_CLIENT | 
+                                    LDLM_NAMESPACE_SERVER)));
+        LASSERT(ns->ns_client == LDLM_NAMESPACE_CLIENT ||
+                ns->ns_client == LDLM_NAMESPACE_SERVER);
+        return ns->ns_client == LDLM_NAMESPACE_SERVER;
+}
+
 static inline int ns_connect_lru_resize(struct ldlm_namespace *ns)
 {
         LASSERT(ns != NULL);
-        return ns->ns_connect_flags & OBD_CONNECT_LRU_RESIZE;
+        return !!(ns->ns_connect_flags & OBD_CONNECT_LRU_RESIZE);
 }
 
 /*
@@ -574,8 +594,8 @@ int ldlm_request_cancel(struct ptlrpc_request *req,
                         struct ldlm_request *dlm_req, int first);
 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
 int ldlm_refresh_waiting_lock(struct ldlm_lock *lock);
-int ldlm_get_ref(ldlm_side_t client);
-void ldlm_put_ref(ldlm_side_t client, int force);
+int ldlm_get_ref(void);
+void ldlm_put_ref(int force);
 
 /* ldlm_lock.c */
 ldlm_processing_policy ldlm_get_processing_policy(struct ldlm_resource *res);
@@ -767,8 +787,8 @@ struct ldlm_resource * lock_res_and_lock(struct ldlm_lock *lock);
 void unlock_res_and_lock(struct ldlm_lock *lock);
 
 /* ldlm_pool.c */
-int ldlm_pools_init(ldlm_side_t client);
 void ldlm_pools_recalc(ldlm_side_t client);
+int ldlm_pools_init(void);
 void ldlm_pools_fini(void);
 void ldlm_pools_wakeup(void);
 
index ef3d8c2..df68b2d 100644 (file)
@@ -110,20 +110,22 @@ struct obd_export {
 
 static inline int exp_connect_cancelset(struct obd_export *exp)
 {
-        return exp ? exp->exp_connect_flags & OBD_CONNECT_CANCELSET : 0;
+        return exp ? !!(exp->exp_connect_flags & OBD_CONNECT_CANCELSET) : 0;
 }
 
 static inline int exp_connect_lru_resize(struct obd_export *exp)
 {
         LASSERT(exp != NULL);
-        return exp->exp_connect_flags & OBD_CONNECT_LRU_RESIZE;
+        return !!(exp->exp_connect_flags & OBD_CONNECT_LRU_RESIZE);
 }
 
 static inline int imp_connect_lru_resize(struct obd_import *imp)
 {
+        struct obd_connect_data *ocd;
+
         LASSERT(imp != NULL);
-        return imp->imp_connect_data.ocd_connect_flags & 
-                      OBD_CONNECT_LRU_RESIZE;
+        ocd = &imp->imp_connect_data;
+        return !!(ocd->ocd_connect_flags & OBD_CONNECT_LRU_RESIZE);
 }
 
 struct exp_uuid_cb_data {
index fdb8548..e23a755 100644 (file)
@@ -43,7 +43,7 @@ struct ldlm_resource * lock_res_and_lock(struct ldlm_lock *lock)
 {
         struct ldlm_resource *res = lock->l_resource;
 
-        if (!res->lr_namespace->ns_client) {
+        if (ns_is_server(res->lr_namespace)) {
                 /* on server-side resource of lock doesn't change */
                 lock_res(res);
                 return res;
@@ -59,7 +59,7 @@ void unlock_res_and_lock(struct ldlm_lock *lock)
 {
         struct ldlm_resource *res = lock->l_resource;
 
-        if (!res->lr_namespace->ns_client) {
+        if (ns_is_server(res->lr_namespace)) {
                 /* on server-side resource of lock doesn't change */
                 unlock_res(res);
                 return;
index 1047b89..fc0cbf0 100644 (file)
@@ -137,7 +137,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, int *flags, int first_enq,
         struct ldlm_lock *new = req;
         struct ldlm_lock *new2 = NULL;
         ldlm_mode_t mode = req->l_req_mode;
-        int local = ns->ns_client;
+        int local = ns_is_client(ns);
         int added = (mode == LCK_NL);
         int overlaps = 0;
         int splitted = 0;
index 817fd2d..fa45e04 100644 (file)
@@ -286,7 +286,7 @@ int client_obd_setup(struct obd_device *obddev, obd_count len, void *buf)
         } else {
                 cli->cl_max_rpcs_in_flight = OSC_MAX_RIF_DEFAULT;
         }
-        rc = ldlm_get_ref(LDLM_NAMESPACE_CLIENT);
+        rc = ldlm_get_ref();
         if (rc) {
                 CERROR("ldlm_get_ref failed: %d\n", rc);
                 GOTO(err, rc);
@@ -337,7 +337,7 @@ int client_obd_setup(struct obd_device *obddev, obd_count len, void *buf)
 err_import:
         class_destroy_import(imp);
 err_ldlm:
-        ldlm_put_ref(LDLM_NAMESPACE_CLIENT, 0);
+        ldlm_put_ref(0);
 err:
         RETURN(rc);
 
@@ -346,7 +346,7 @@ err:
 int client_obd_cleanup(struct obd_device *obddev)
 {
         ENTRY;
-        ldlm_put_ref(LDLM_NAMESPACE_CLIENT, obddev->obd_force);
+        ldlm_put_ref(obddev->obd_force);
         RETURN(0);
 }
 
index 1a51e03..4154fff 100644 (file)
@@ -359,7 +359,7 @@ int ldlm_lock_change_resource(struct ldlm_namespace *ns, struct ldlm_lock *lock,
         int type;
         ENTRY;
 
-        LASSERT(ns->ns_client != 0);
+        LASSERT(ns_is_client(ns));
 
         lock_res_and_lock(lock);
         if (memcmp(&new_resid, &lock->l_resource->lr_name,
@@ -620,7 +620,7 @@ void ldlm_lock_decref_internal(struct ldlm_lock *lock, __u32 mode)
             (lock->l_flags & LDLM_FL_CBPENDING)) {
                 /* If we received a blocked AST and this was the last reference,
                  * run the callback. */
-                if (ns->ns_client == LDLM_NAMESPACE_SERVER && lock->l_export)
+                if (ns_is_server(ns) && lock->l_export)
                         CERROR("FL_CBPENDING set on non-local lock--just a "
                                "warning\n");
 
@@ -632,7 +632,7 @@ void ldlm_lock_decref_internal(struct ldlm_lock *lock, __u32 mode)
                 if ((lock->l_flags & LDLM_FL_ATOMIC_CB) ||
                     ldlm_bl_to_thread(ns, NULL, lock, 0) != 0)
                         ldlm_handle_bl_callback(ns, NULL, lock);
-        } else if (ns->ns_client == LDLM_NAMESPACE_CLIENT &&
+        } else if (ns_is_client(ns) &&
                    !lock->l_readers && !lock->l_writers &&
                    !(lock->l_flags & LDLM_FL_NO_LRU)) {
                 /* If this is a client-side namespace and this was the last
@@ -1144,7 +1144,7 @@ ldlm_error_t ldlm_lock_enqueue(struct ldlm_namespace *ns,
 {
         struct ldlm_lock *lock = *lockp;
         struct ldlm_resource *res = lock->l_resource;
-        int local = res->lr_namespace->ns_client;
+        int local = ns_is_client(res->lr_namespace);
         ldlm_processing_policy policy;
         ldlm_error_t rc = ELDLM_OK;
         ENTRY;
@@ -1442,7 +1442,7 @@ void ldlm_reprocess_all(struct ldlm_resource *res)
         ENTRY;
 
         /* Local lock trees don't get reprocessed. */
-        if (res->lr_namespace->ns_client) {
+        if (ns_is_client(res->lr_namespace)) {
                 EXIT;
                 return;
         }
@@ -1669,7 +1669,7 @@ struct ldlm_resource *ldlm_lock_convert(struct ldlm_lock *lock, int new_mode,
         ldlm_resource_unlink_lock(lock);
 
         /* If this is a local resource, put it on the appropriate list. */
-        if (res->lr_namespace->ns_client) {
+        if (ns_is_client(res->lr_namespace)) {
                 if (*flags & (LDLM_FL_BLOCK_CONV | LDLM_FL_BLOCK_GRANTED)) {
                         ldlm_resource_add_lock(res, &res->lr_converting, lock);
                 } else {
index 46318b5..aac218c 100644 (file)
@@ -1680,16 +1680,16 @@ static int ldlm_bl_thread_main(void *arg)
 
 #endif
 
-static int ldlm_setup(ldlm_side_t client);
-static int ldlm_cleanup(ldlm_side_t client, int force);
+static int ldlm_setup(void);
+static int ldlm_cleanup(int force);
 
-int ldlm_get_ref(ldlm_side_t client)
+int ldlm_get_ref(void)
 {
         int rc = 0;
         ENTRY;
         mutex_down(&ldlm_ref_sem);
         if (++ldlm_refcount == 1) {
-                rc = ldlm_setup(client);
+                rc = ldlm_setup();
                 if (rc)
                         ldlm_refcount--;
         }
@@ -1698,12 +1698,12 @@ int ldlm_get_ref(ldlm_side_t client)
         RETURN(rc);
 }
 
-void ldlm_put_ref(ldlm_side_t client, int force)
+void ldlm_put_ref(int force)
 {
         ENTRY;
         mutex_down(&ldlm_ref_sem);
         if (ldlm_refcount == 1) {
-                int rc = ldlm_cleanup(client, force);
+                int rc = ldlm_cleanup(force);
                 if (rc)
                         CERROR("ldlm_cleanup failed: %d\n", rc);
                 else
@@ -1716,7 +1716,7 @@ void ldlm_put_ref(ldlm_side_t client, int force)
         EXIT;
 }
 
-static int ldlm_setup(ldlm_side_t client)
+static int ldlm_setup(void)
 {
         struct ldlm_bl_pool *blp;
         int rc = 0;
@@ -1819,7 +1819,7 @@ static int ldlm_setup(ldlm_side_t client)
 #endif
 
 #ifdef __KERNEL__
-        rc = ldlm_pools_init(client);
+        rc = ldlm_pools_init();
         if (rc)
                 GOTO(out_thread, rc);
 #endif
@@ -1842,7 +1842,7 @@ static int ldlm_setup(ldlm_side_t client)
         return rc;
 }
 
-static int ldlm_cleanup(ldlm_side_t client, int force)
+static int ldlm_cleanup(int force)
 {
 #ifdef __KERNEL__
         struct ldlm_bl_pool *blp = ldlm_state->ldlm_bl_pool;
index 70c6eb9..704b4cd 100644 (file)
@@ -337,7 +337,7 @@ EXPORT_SYMBOL(ldlm_pool_shrink);
 int ldlm_pool_setup(struct ldlm_pool *pl, __u32 limit)
 {
         ENTRY;
-        if (ldlm_pl2ns(pl)->ns_client == LDLM_NAMESPACE_SERVER)
+        if (ns_is_server(ldlm_pl2ns(pl)))
                 ldlm_pool_set_limit(pl, limit);
         RETURN(0);
 }
@@ -368,7 +368,7 @@ static int lprocfs_rd_pool_state(char *page, char **start, off_t off,
                        pl->pl_name);
         nr += snprintf(page + nr, count - nr, "  SLV: "LPU64"\n", slv);
 
-        if (ldlm_pl2ns(pl)->ns_client == LDLM_NAMESPACE_CLIENT) {
+        if (ns_is_client(ldlm_pl2ns(pl))) {
                 nr += snprintf(page + nr, count - nr, "  LVF: %d\n",
                                atomic_read(&pl->pl_lock_volume_factor));
         }
@@ -465,11 +465,11 @@ static int ldlm_pool_proc_init(struct ldlm_pool *pl)
         snprintf(var_name, MAX_STRING_SIZE, "grant_step");
         pool_vars[0].data = &pl->pl_grant_step;
         pool_vars[0].read_fptr = lprocfs_rd_atomic;
-        if (ns->ns_client == LDLM_NAMESPACE_SERVER)
+        if (ns_is_server(ns))
                 pool_vars[0].write_fptr = lprocfs_wr_atomic;
         lprocfs_add_vars(pl->pl_proc_dir, pool_vars, 0);
 
-        if (ns->ns_client == LDLM_NAMESPACE_CLIENT) {
+        if (ns_is_client(ns)) {
                 snprintf(var_name, MAX_STRING_SIZE, "lock_volume_factor");
                 pool_vars[0].data = &pl->pl_lock_volume_factor;
                 pool_vars[0].read_fptr = lprocfs_rd_uint;
@@ -589,7 +589,7 @@ void ldlm_pool_add(struct ldlm_pool *pl, struct ldlm_lock *lock)
         /* No need to recalc client pools here as this is already done 
          * on enqueue/cancel and locks to cancel already packed to the
          * rpc. */
-        if (ldlm_pl2ns(pl)->ns_client == LDLM_NAMESPACE_SERVER)
+        if (ns_is_server(ldlm_pl2ns(pl)))
                 ldlm_pool_recalc(pl);
         EXIT;
 }
@@ -604,7 +604,7 @@ void ldlm_pool_del(struct ldlm_pool *pl, struct ldlm_lock *lock)
         atomic_dec(&pl->pl_grant_speed);
         
         /* Same as in ldlm_pool_add() */
-        if (ldlm_pl2ns(pl)->ns_client == LDLM_NAMESPACE_SERVER)
+        if (ns_is_server(ldlm_pl2ns(pl)))
                 ldlm_pool_recalc(pl);
         EXIT;
 }
@@ -825,8 +825,8 @@ static int ldlm_pools_thread_main(void *arg)
                 struct l_wait_info lwi;
 
                 /* Recal all pools on this tick. */
-                ldlm_pools_recalc(LDLM_NAMESPACE_CLIENT);
                 ldlm_pools_recalc(LDLM_NAMESPACE_SERVER);
+                ldlm_pools_recalc(LDLM_NAMESPACE_CLIENT);
                 
                 /* Wait until the next check time, or until we're
                  * stopped. */
@@ -853,7 +853,7 @@ static int ldlm_pools_thread_main(void *arg)
         complete_and_exit(&ldlm_pools_comp, 0);
 }
 
-static int ldlm_pools_thread_start(ldlm_side_t client)
+static int ldlm_pools_thread_start(void)
 {
         struct l_wait_info lwi = { 0 };
         int rc;
@@ -866,7 +866,6 @@ static int ldlm_pools_thread_start(ldlm_side_t client)
         if (ldlm_pools_thread == NULL)
                 RETURN(-ENOMEM);
 
-        ldlm_pools_thread->t_id = client;
         init_completion(&ldlm_pools_comp);
         cfs_waitq_init(&ldlm_pools_thread->t_ctl_waitq);
 
@@ -907,12 +906,12 @@ static void ldlm_pools_thread_stop(void)
         EXIT;
 }
 
-int ldlm_pools_init(ldlm_side_t client)
+int ldlm_pools_init(void)
 {
         int rc;
         ENTRY;
 
-        rc = ldlm_pools_thread_start(client);
+        rc = ldlm_pools_thread_start();
         if (rc == 0) {
                 ldlm_pools_srv_shrinker = set_shrinker(DEFAULT_SEEKS,
                                                        ldlm_pools_srv_shrink);
@@ -1007,7 +1006,7 @@ void ldlm_pool_set_limit(struct ldlm_pool *pl, __u32 limit)
 }
 EXPORT_SYMBOL(ldlm_pool_set_limit);
 
-int ldlm_pools_init(ldlm_side_t client)
+int ldlm_pools_init(void)
 {
         return 0;
 }
index 69cd046..fa8a5cd 100644 (file)
@@ -273,7 +273,7 @@ int ldlm_cli_enqueue_local(struct ldlm_namespace *ns, struct ldlm_res_id res_id,
         ENTRY;
 
         LASSERT(!(*flags & LDLM_FL_REPLAY));
-        if (ns->ns_client) {
+        if (ns_is_client(ns)) {
                 CERROR("Trying to enqueue local lock in a shadow namespace\n");
                 LBUG();
         }
@@ -700,7 +700,7 @@ static int ldlm_cli_convert_local(struct ldlm_lock *lock, int new_mode,
         struct ldlm_resource *res;
         int rc;
         ENTRY;
-        if (lock->l_resource->lr_namespace->ns_client) {
+        if (ns_is_client(lock->l_resource->lr_namespace)) {
                 CERROR("Trying to cancel local lock\n");
                 LBUG();
         }
@@ -826,7 +826,7 @@ static int ldlm_cli_cancel_local(struct ldlm_lock *lock)
                 }
                 ldlm_lock_cancel(lock);
         } else {
-                if (lock->l_resource->lr_namespace->ns_client) {
+                if (ns_is_client(lock->l_resource->lr_namespace)) {
                         LDLM_ERROR(lock, "Trying to cancel local lock");
                         LBUG();
                 }
@@ -1437,7 +1437,7 @@ int ldlm_cli_join_lru(struct ldlm_namespace *ns,
         int count = 0;
         ENTRY;
 
-        LASSERT(ns->ns_client == LDLM_NAMESPACE_CLIENT);
+        LASSERT(ns_is_client(ns));
 
         res = ldlm_resource_get(ns, NULL, *res_id, LDLM_EXTENT, 0);
         if (res == NULL)
index 7640874..fd8c563 100644 (file)
@@ -213,7 +213,7 @@ void ldlm_proc_namespace(struct ldlm_namespace *ns)
         lock_vars[0].read_fptr = lprocfs_rd_atomic;
         lprocfs_add_vars(ldlm_ns_proc_dir, lock_vars, 0);
 
-        if (ns->ns_client) {
+        if (ns_is_client(ns)) {
                 snprintf(lock_name, MAX_STRING_SIZE, "%s/lock_unused_count",
                          ns->ns_name);
                 lock_vars[0].data = &ns->ns_nr_unused;
@@ -269,7 +269,7 @@ struct ldlm_namespace *ldlm_namespace_new(char *name, ldlm_side_t client,
         int rc, idx, namelen;
         ENTRY;
 
-        rc = ldlm_get_ref(client);
+        rc = ldlm_get_ref();
         if (rc) {
                 CERROR("ldlm_get_ref failed: %d\n", rc);
                 RETURN(NULL);
@@ -339,7 +339,7 @@ out_hash:
 out_ns:
         OBD_FREE_PTR(ns);
 out_ref:
-        ldlm_put_ref(client, 0);
+        ldlm_put_ref(0);
         RETURN(NULL);
 }
 
@@ -354,7 +354,7 @@ static void cleanup_resource(struct ldlm_resource *res, struct list_head *q,
                              int flags)
 {
         struct list_head *tmp;
-        int rc = 0, client = res->lr_namespace->ns_client;
+        int rc = 0, client = ns_is_client(res->lr_namespace);
         int local_only = (flags & LDLM_FL_LOCAL_ONLY);
         ENTRY;
 
@@ -508,7 +508,6 @@ int ldlm_namespace_free_prior(struct ldlm_namespace *ns)
 
 int ldlm_namespace_free_post(struct ldlm_namespace *ns, int force)
 {
-        ldlm_side_t client;
         ENTRY;
         if (!ns)
                 RETURN(ELDLM_OK);
@@ -525,12 +524,10 @@ int ldlm_namespace_free_post(struct ldlm_namespace *ns, int force)
                 }
         }
 #endif
-        client = ns->ns_client;
-        POISON(ns->ns_hash, 0x5a, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
         OBD_VFREE(ns->ns_hash, sizeof(*ns->ns_hash) * RES_HASH_SIZE);
         OBD_FREE(ns->ns_name, strlen(ns->ns_name) + 1);
         OBD_FREE_PTR(ns);
-        ldlm_put_ref(client, force);
+        ldlm_put_ref(force);
         RETURN(ELDLM_OK);
 }
 
@@ -937,8 +934,9 @@ void ldlm_namespace_dump(int level, struct ldlm_namespace *ns)
         if (!((libcfs_debug | D_ERROR) & level))
                 return;
 
-        CDEBUG(level, "--- Namespace: %s (rc: %d, client: %d)\n", 
-               ns->ns_name, ns->ns_refcount, ns->ns_client);
+        CDEBUG(level, "--- Namespace: %s (rc: %d, side: %s)\n", 
+               ns->ns_name, ns->ns_refcount, 
+               ns_is_client(ns) ? "client" : "server");
 
         if (cfs_time_before(cfs_time_current(), ns->ns_next_dump))
                 return;