Whamcloud - gitweb
LU-8753 osp: add rpc generation
[fs/lustre-release.git] / lustre / osp / osp_dev.c
index 505e484..138bb43 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -27,7 +23,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2015, Intel Corporation.
+ * Copyright (c) 2012, 2016, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -455,10 +451,11 @@ static void osp_last_used_fini(const struct lu_env *env, struct osp_device *osp)
  */
 static int osp_disconnect(struct osp_device *d)
 {
+       struct obd_device *obd = d->opd_obd;
        struct obd_import *imp;
        int rc = 0;
 
-       imp = d->opd_obd->u.cli.cl_import;
+       imp = obd->u.cli.cl_import;
 
        /* Mark import deactivated now, so we don't try to reconnect if any
         * of the cleanup RPCs fails (e.g. ldlm cancel, etc).  We don't
@@ -477,8 +474,7 @@ static int osp_disconnect(struct osp_device *d)
 
        rc = ptlrpc_disconnect_import(imp, 0);
        if (rc != 0)
-               CERROR("%s: can't disconnect: rc = %d\n",
-                      d->opd_obd->obd_name, rc);
+               CERROR("%s: can't disconnect: rc = %d\n", obd->obd_name, rc);
 
        ptlrpc_invalidate_import(imp);
 
@@ -514,6 +510,7 @@ static int osp_update_init(struct osp_device *osp)
        INIT_LIST_HEAD(&osp->opd_update->ou_list);
        osp->opd_update->ou_rpc_version = 1;
        osp->opd_update->ou_version = 1;
+       osp->opd_update->ou_generation = 0;
 
        /* start thread handling sending updates to the remote MDT */
        task = kthread_run(osp_send_update_thread, osp,
@@ -566,7 +563,7 @@ static void osp_update_fini(const struct lu_env *env, struct osp_device *osp)
                LASSERT(our->our_th != NULL);
                osp_trans_callback(env, our->our_th, -EIO);
                /* our will be destroyed in osp_thandle_put() */
-               osp_thandle_put(our->our_th);
+               osp_thandle_put(env, our->our_th);
        }
        spin_unlock(&ou->ou_lock);
 
@@ -636,6 +633,8 @@ static int osp_process_config(const struct lu_env *env,
        case LCFG_PRE_CLEANUP:
                rc = osp_disconnect(d);
                osp_update_fini(env, d);
+               if (obd->obd_namespace != NULL)
+                       ldlm_namespace_free_prior(obd->obd_namespace, NULL, 1);
                break;
        case LCFG_CLEANUP:
                lu_dev_del_linkage(dev->ld_site, dev);
@@ -750,12 +749,14 @@ static int osp_statfs(const struct lu_env *env, struct dt_device *dev,
        sfs->os_fprecreated = fid_oid(&d->opd_pre_last_created_fid) -
                              fid_oid(&d->opd_pre_used_fid);
        sfs->os_fprecreated -= d->opd_pre_reserved;
+       LASSERTF(sfs->os_fprecreated <= OST_MAX_PRECREATE * 2,
+                "last_created "DFID", next_fid "DFID", reserved %llu\n",
+                PFID(&d->opd_pre_last_created_fid), PFID(&d->opd_pre_used_fid),
+                d->opd_pre_reserved);
        spin_unlock(&d->opd_pre_lock);
 
-       LASSERT(sfs->os_fprecreated <= OST_MAX_PRECREATE * 2);
-
-       CDEBUG(D_OTHER, "%s: "LPU64" blocks, "LPU64" free, "LPU64" avail, "
-              LPU64" files, "LPU64" free files\n", d->opd_obd->obd_name,
+       CDEBUG(D_OTHER, "%s: %llu blocks, %llu free, %llu avail, "
+              "%llu files, %llu free files\n", d->opd_obd->obd_name,
               sfs->os_blocks, sfs->os_bfree, sfs->os_bavail,
               sfs->os_files, sfs->os_ffree);
        RETURN(0);
@@ -811,7 +812,7 @@ static int osp_sync(const struct lu_env *env, struct dt_device *dev)
        if (rc != 0)
                GOTO(out, rc);
 
-       CDEBUG(D_CACHE, "%s: id: used %lu, processed %lu\n",
+       CDEBUG(D_CACHE, "%s: id: used %lu, processed %llu\n",
               d->opd_obd->obd_name, id, d->opd_syn_last_processed_id);
 
        /* wait till all-in-line are processed */
@@ -844,26 +845,27 @@ static int osp_sync(const struct lu_env *env, struct dt_device *dev)
        atomic_inc(&d->opd_syn_barrier);
 
        CDEBUG(D_CACHE, "%s: %u in flight\n", d->opd_obd->obd_name,
-              d->opd_syn_rpc_in_flight);
+              atomic_read(&d->opd_syn_rpc_in_flight));
 
        /* wait till all-in-flight are replied, so executed by the target */
        /* XXX: this is used by LFSCK at the moment, which doesn't require
         *      all the changes to be committed, but in general it'd be
         *      better to wait till commit */
-       while (d->opd_syn_rpc_in_flight > 0) {
+       while (atomic_read(&d->opd_syn_rpc_in_flight) > 0) {
 
-               old = d->opd_syn_rpc_in_flight;
+               old = atomic_read(&d->opd_syn_rpc_in_flight);
 
                expire = cfs_time_shift(obd_timeout);
                lwi = LWI_TIMEOUT(expire - cfs_time_current(),
                                  osp_sync_timeout, d);
                l_wait_event(d->opd_syn_barrier_waitq,
-                               d->opd_syn_rpc_in_flight == 0, &lwi);
+                            atomic_read(&d->opd_syn_rpc_in_flight) == 0,
+                            &lwi);
 
-               if (d->opd_syn_rpc_in_flight == 0)
+               if (atomic_read(&d->opd_syn_rpc_in_flight) == 0)
                        break;
 
-               if (d->opd_syn_rpc_in_flight != old) {
+               if (atomic_read(&d->opd_syn_rpc_in_flight) != old) {
                        /* some progress have been made */
                        continue;
                }
@@ -1320,21 +1322,18 @@ static struct lu_device *osp_device_fini(const struct lu_env *env,
                                         struct lu_device *ld)
 {
        struct osp_device *osp = lu2osp_dev(ld);
-       struct obd_import *imp;
        int                rc;
 
        ENTRY;
 
        if (osp->opd_async_requests != NULL) {
-               osp_update_request_destroy(osp->opd_async_requests);
+               osp_update_request_destroy(env, osp->opd_async_requests);
                osp->opd_async_requests = NULL;
        }
 
        if (osp->opd_storage_exp)
                obd_disconnect(osp->opd_storage_exp);
 
-       imp = osp->opd_obd->u.cli.cl_import;
-
        if (osp->opd_symlink)
                lprocfs_remove(&osp->opd_symlink);
 
@@ -1575,6 +1574,7 @@ static int osp_import_event(struct obd_device *obd, struct obd_import *imp,
                            enum obd_import_event event)
 {
        struct osp_device *d = lu2osp_dev(obd->obd_lu_dev);
+       int rc;
 
        switch (event) {
        case IMP_EVENT_DISCON:
@@ -1596,9 +1596,11 @@ static int osp_import_event(struct obd_device *obd, struct obd_import *imp,
                d->opd_obd->obd_inactive = 1;
                if (d->opd_connect_mdt)
                        break;
-
                if (d->opd_pre != NULL) {
-                       osp_pre_update_status(d, -ENODEV);
+                       /* Import is invalid, we can`t get stripes so
+                        * wakeup waiters */
+                       rc = imp->imp_deactive ? -ESHUTDOWN : -ENODEV;
+                       osp_pre_update_status(d, rc);
                        wake_up(&d->opd_pre_waitq);
                }