Whamcloud - gitweb
LU-12930 various: use schedule_timeout_*interruptible
[fs/lustre-release.git] / lustre / obdclass / obd_mount_server.c
index aae2e35..d3854db 100644 (file)
@@ -419,7 +419,7 @@ int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
                        RETURN(-ENOMEM);
                }
                memcpy(uuid->uuid, lwpname, strlen(lwpname));
-               *exp = cfs_hash_lookup(lwp->obd_uuid_hash, uuid);
+               *exp = obd_uuid_lookup(lwp, uuid);
                OBD_FREE_PTR(uuid);
        }
 
@@ -476,8 +476,7 @@ void lustre_deregister_lwp_item(struct obd_export **exp)
                CDEBUG(D_MOUNT, "lri reference count %u, repeat: %d\n",
                       atomic_read(&lri->lri_ref), repeat);
                repeat++;
-               set_current_state(TASK_INTERRUPTIBLE);
-               schedule_timeout(cfs_time_seconds(1));
+               schedule_timeout_interruptible(cfs_time_seconds(1));
        }
        lustre_put_lwp_item(lri);
 }
@@ -506,7 +505,7 @@ struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx)
        }
 
        snprintf(lwp_name, sizeof(lwp_name), "%s-MDT%04x", fsname, idx);
-       spin_lock(&lsi->lsi_lwp_lock);
+       mutex_lock(&lsi->lsi_lwp_mutex);
        list_for_each_entry(lwp, &lsi->lsi_lwp_list, obd_lwp_list) {
                char *ptr = strstr(lwp->obd_name, lwp_name);
 
@@ -515,7 +514,7 @@ struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx)
                        break;
                }
        }
-       spin_unlock(&lsi->lsi_lwp_lock);
+       mutex_unlock(&lsi->lsi_lwp_mutex);
 
 err_lmi:
        server_put_mount(dev, false);
@@ -676,9 +675,9 @@ static int lustre_lwp_setup(struct lustre_cfg *lcfg, struct lustre_sb_info *lsi,
        rc = lustre_lwp_connect(obd, strstr(lsi->lsi_svname, "-MDT") != NULL);
        if (rc == 0) {
                obd->u.cli.cl_max_mds_easize = MAX_MD_SIZE;
-               spin_lock(&lsi->lsi_lwp_lock);
+               mutex_lock(&lsi->lsi_lwp_mutex);
                list_add_tail(&obd->obd_lwp_list, &lsi->lsi_lwp_list);
-               spin_unlock(&lsi->lsi_lwp_lock);
+               mutex_unlock(&lsi->lsi_lwp_mutex);
        } else {
                CERROR("%s: connect failed: rc = %d\n", lwpname, rc);
        }
@@ -881,6 +880,20 @@ static int client_lwp_config_process(const struct lu_env *env,
                if (!is_mdc_device(devname))
                        break;
 
+               if (!(cfg->cfg_flags & CFG_F_MARKER)) {
+                       CDEBUG(D_CONFIG, "Skipping add_conn for %s, rec %d\n",
+                              devname, rec->lrh_index);
+                       break;
+               }
+
+               /* add_conn should follow by add_uuid. This
+                * guarantee lwp device was created
+                */
+               if (!(cfg->cfg_flags & CFG_F_SKIP)) {
+                       CWARN("Error at config for %s rec %d, add_conn should follow by add_uuid\n",
+                             devname, rec->lrh_index);
+                       break;
+               }
                ptr = strrchr(devname, '-');
                if (ptr == NULL)
                        break;
@@ -946,6 +959,7 @@ static int lustre_disconnect_lwp(struct super_block *sb)
        if (bufs == NULL)
                GOTO(out, rc = -ENOMEM);
 
+       mutex_lock(&lsi->lsi_lwp_mutex);
        list_for_each_entry(lwp, &lsi->lsi_lwp_list, obd_lwp_list) {
                struct lustre_cfg *lcfg;
 
@@ -958,8 +972,10 @@ static int lustre_disconnect_lwp(struct super_block *sb)
                lustre_cfg_bufs_set_string(bufs, 1, NULL);
                OBD_ALLOC(lcfg, lustre_cfg_len(bufs->lcfg_bufcount,
                                               bufs->lcfg_buflen));
-               if (!lcfg)
-                       GOTO(out, rc = -ENOMEM);
+               if (!lcfg) {
+                       rc = -ENOMEM;
+                       break;
+               }
                lustre_cfg_init(lcfg, LCFG_CLEANUP, bufs);
 
                /* Disconnect import first. NULL is passed for the '@env',
@@ -974,6 +990,7 @@ static int lustre_disconnect_lwp(struct super_block *sb)
                        rc1 = rc;
                }
        }
+       mutex_unlock(&lsi->lsi_lwp_mutex);
 
        GOTO(out, rc);
 
@@ -999,18 +1016,23 @@ static int lustre_stop_lwp(struct super_block *sb)
        int                      rc1 = 0;
        ENTRY;
 
+       mutex_lock(&lsi->lsi_lwp_mutex);
        while (!list_empty(&lsi->lsi_lwp_list)) {
                lwp = list_entry(lsi->lsi_lwp_list.next, struct obd_device,
                                 obd_lwp_list);
                list_del_init(&lwp->obd_lwp_list);
                lwp->obd_force = 1;
+               mutex_unlock(&lsi->lsi_lwp_mutex);
+
                rc = class_manual_cleanup(lwp);
                if (rc != 0) {
                        CERROR("%s: fail to stop LWP: rc = %d\n",
                               lwp->obd_name, rc);
                        rc1 = rc;
                }
+               mutex_lock(&lsi->lsi_lwp_mutex);
        }
+       mutex_unlock(&lsi->lsi_lwp_mutex);
 
        RETURN(rc1 != 0 ? rc1 : rc);
 }
@@ -1092,7 +1114,7 @@ static int server_stop_servers(int lsiflags)
        LASSERTF(type, "Server flags %d, obd %s\n", lsiflags,
                 obd ? obd->obd_name : "NULL");
 
-       type_last = (type->typ_refcnt == 1);
+       type_last = (atomic_read(&type->typ_refcnt) == 1);
 
        class_put_type(type);
        if (obd != NULL && type_last) {
@@ -1101,6 +1123,9 @@ static int server_stop_servers(int lsiflags)
                rc = class_manual_cleanup(obd);
        }
 
+       /* put reference taken by class_search_type */
+       kobject_put(&type->typ_kobj);
+
        mutex_unlock(&server_start_lock);
 
        RETURN(rc);
@@ -1239,9 +1264,8 @@ again:
                        if ((rc == -ESHUTDOWN || rc == -EIO) && ++tried < 5) {
                                /* The connection with MGS is not established.
                                 * Try again after 2 seconds. Interruptable. */
-                               set_current_state(TASK_INTERRUPTIBLE);
-                               schedule_timeout(cfs_time_seconds(2));
-                               set_current_state(TASK_RUNNING);
+                               schedule_timeout_interruptible(
+                                       cfs_time_seconds(2));
                                if (!signal_pending(current))
                                        goto again;
                        }
@@ -1355,6 +1379,10 @@ static int server_start_targets(struct super_block *sb)
        /* hold a type reference and put it at server_stop_servers */
        type = class_get_type(IS_MDT(lsi) ?
                              LUSTRE_MDT_NAME : LUSTRE_OST_NAME);
+       if (!type) {
+               mutex_unlock(&server_start_lock);
+               GOTO(out_stop_service, rc = -ENODEV);
+       }
        lsi->lsi_server_started = 1;
        mutex_unlock(&server_start_lock);
        if (OBD_FAIL_PRECHECK(OBD_FAIL_OBD_STOP_MDS_RACE) &&