Whamcloud - gitweb
LU-3068 build: fix 'incorrect expression' errors
[fs/lustre-release.git] / lustre / obdclass / genops.c
index e22b7f8..436aa4d 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Whamcloud, Inc.
+ * Copyright (c) 2011, 2012, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -125,6 +125,12 @@ struct obd_type *class_get_type(const char *name)
                if (strcmp(modname, "obdfilter") == 0)
                        modname = "ofd";
 
+               if (strcmp(modname, LUSTRE_LWP_NAME) == 0)
+                       modname = LUSTRE_OSP_NAME;
+
+               if (!strncmp(modname, LUSTRE_MDS_NAME, strlen(LUSTRE_MDS_NAME)))
+                       modname = LUSTRE_MDT_NAME;
+
                 if (!cfs_request_module("%s", modname)) {
                         CDEBUG(D_INFO, "Loaded module '%s'\n", modname);
                         type = class_search_type(name);
@@ -309,8 +315,7 @@ struct obd_device *class_newdev(const char *type_name, const char *name)
         for (i = 0; i < class_devno_max(); i++) {
                 struct obd_device *obd = class_num2obd(i);
 
-                if (obd && obd->obd_name &&
-                    (strcmp(name, obd->obd_name) == 0)) {
+               if (obd && (strcmp(name, obd->obd_name) == 0)) {
                         CERROR("Device %s already exists at %d, won't add\n",
                                name, i);
                         if (result) {
@@ -391,7 +396,7 @@ int class_name2dev(const char *name)
         for (i = 0; i < class_devno_max(); i++) {
                 struct obd_device *obd = class_num2obd(i);
 
-                if (obd && obd->obd_name && strcmp(name, obd->obd_name) == 0) {
+               if (obd && strcmp(name, obd->obd_name) == 0) {
                         /* Make sure we finished attaching before we give
                            out any references */
                         LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
@@ -476,6 +481,27 @@ struct obd_device *class_num2obd(int num)
 }
 EXPORT_SYMBOL(class_num2obd);
 
+/**
+ * Get obd devices count. Device in any
+ *    state are counted
+ * \retval obd device count
+ */
+int get_devices_count(void)
+{
+       int index, max_index = class_devno_max(), dev_count = 0;
+
+       read_lock(&obd_dev_lock);
+       for (index = 0; index <= max_index; index++) {
+               struct obd_device *obd = class_num2obd(index);
+               if (obd != NULL)
+                       dev_count++;
+       }
+       read_unlock(&obd_dev_lock);
+
+       return dev_count;
+}
+EXPORT_SYMBOL(get_devices_count);
+
 void class_obd_list(void)
 {
         char *status;
@@ -1010,6 +1036,7 @@ struct obd_import *class_new_import(struct obd_device *obd)
         if (imp == NULL)
                 return NULL;
 
+       CFS_INIT_LIST_HEAD(&imp->imp_pinger_chain);
         CFS_INIT_LIST_HEAD(&imp->imp_zombie_chain);
         CFS_INIT_LIST_HEAD(&imp->imp_replay_list);
         CFS_INIT_LIST_HEAD(&imp->imp_sending_list);
@@ -1130,12 +1157,21 @@ void class_export_recovery_cleanup(struct obd_export *exp)
        spin_lock(&obd->obd_recovery_task_lock);
        if (exp->exp_delayed)
                obd->obd_delayed_clients--;
-       if (obd->obd_recovering && exp->exp_in_recovery) {
-               spin_lock(&exp->exp_lock);
-               exp->exp_in_recovery = 0;
-               spin_unlock(&exp->exp_lock);
-               LASSERT_ATOMIC_POS(&obd->obd_connected_clients);
-               cfs_atomic_dec(&obd->obd_connected_clients);
+       if (obd->obd_recovering) {
+               if (exp->exp_in_recovery) {
+                       spin_lock(&exp->exp_lock);
+                       exp->exp_in_recovery = 0;
+                       spin_unlock(&exp->exp_lock);
+                       LASSERT_ATOMIC_POS(&obd->obd_connected_clients);
+                       cfs_atomic_dec(&obd->obd_connected_clients);
+               }
+
+               /* if called during recovery then should update
+                * obd_stale_clients counter,
+                * lightweight exports are not counted */
+               if (exp->exp_failed &&
+                   (exp_connect_flags(exp) & OBD_CONNECT_LIGHTWEIGHT) == 0)
+                       exp->exp_obd->obd_stale_clients++;
        }
        spin_unlock(&obd->obd_recovery_task_lock);
        /** Cleanup req replay fields */
@@ -1145,7 +1181,7 @@ void class_export_recovery_cleanup(struct obd_export *exp)
                spin_unlock(&exp->exp_lock);
                LASSERT(cfs_atomic_read(&obd->obd_req_replay_clients));
                cfs_atomic_dec(&obd->obd_req_replay_clients);
-        }
+       }
        /** Cleanup lock replay data */
        if (exp->exp_lock_replay_needed) {
                spin_lock(&exp->exp_lock);
@@ -1310,7 +1346,7 @@ void class_disconnect_stale_exports(struct obd_device *obd,
                        continue;
 
                spin_lock(&exp->exp_lock);
-               if (test_export(exp)) {
+               if (exp->exp_failed || test_export(exp)) {
                        spin_unlock(&exp->exp_lock);
                        continue;
                }
@@ -1327,14 +1363,13 @@ void class_disconnect_stale_exports(struct obd_device *obd,
         }
        spin_unlock(&obd->obd_dev_lock);
 
-        if (evicted) {
-                LCONSOLE_WARN("%s: disconnecting %d stale clients\n",
-                              obd->obd_name, evicted);
-                obd->obd_stale_clients += evicted;
-        }
-        class_disconnect_export_list(&work_list, exp_flags_from_obd(obd) |
-                                                 OBD_OPT_ABORT_RECOV);
-        EXIT;
+       if (evicted)
+               LCONSOLE_WARN("%s: disconnecting %d stale clients\n",
+                             obd->obd_name, evicted);
+
+       class_disconnect_export_list(&work_list, exp_flags_from_obd(obd) |
+                                                OBD_OPT_ABORT_RECOV);
+       EXIT;
 }
 EXPORT_SYMBOL(class_disconnect_stale_exports);
 
@@ -1416,9 +1451,10 @@ int obd_export_evict_by_nid(struct obd_device *obd, const char *nid)
                 LASSERTF(doomed_exp != obd->obd_self_export,
                          "self-export is hashed by NID?\n");
                 exports_evicted++;
-                CWARN("%s: evict NID '%s' (%s) #%d at adminstrative request\n",
-                       obd->obd_name, nid, doomed_exp->exp_client_uuid.uuid,
-                       exports_evicted);
+               LCONSOLE_WARN("%s: evicting %s (at %s) by administrative "
+                             "request\n", obd->obd_name,
+                             obd_uuid2str(&doomed_exp->exp_client_uuid),
+                             obd_export_nid2str(doomed_exp));
                 class_fail_export(doomed_exp);
                 class_export_put(doomed_exp);
         } while (1);