Whamcloud - gitweb
LU-7950 osp: Remove assigned but not used variable
[fs/lustre-release.git] / lustre / osp / osp_dev.c
index 528e589..f20d8c6 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2014, Intel Corporation.
+ * Copyright (c) 2012, 2015, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 #define DEBUG_SUBSYSTEM S_MDS
 
 #include <linux/kthread.h>
-#include <obd_class.h>
+
 #include <lustre_ioctl.h>
-#include <lustre_param.h>
 #include <lustre_log.h>
+#include <lustre_obdo.h>
+#include <lustre_param.h>
+#include <obd_class.h>
 
 #include "osp_internal.h"
 
@@ -453,10 +455,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
@@ -475,8 +478,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);
 
@@ -564,7 +566,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);
 
@@ -634,6 +636,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);
@@ -719,9 +723,13 @@ static int osp_statfs(const struct lu_env *env, struct dt_device *dev,
                      struct obd_statfs *sfs)
 {
        struct osp_device *d = dt2osp_dev(dev);
+       struct obd_import *imp = d->opd_obd->u.cli.cl_import;
 
        ENTRY;
 
+       if (imp->imp_state == LUSTRE_IMP_CLOSED)
+               RETURN(-ESHUTDOWN);
+
        if (unlikely(d->opd_imp_active == 0))
                RETURN(-ENOTCONN);
 
@@ -805,7 +813,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 "LPU64"\n",
               d->opd_obd->obd_name, id, d->opd_syn_last_processed_id);
 
        /* wait till all-in-line are processed */
@@ -838,26 +846,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;
                }
@@ -1314,21 +1323,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);
 
@@ -1423,10 +1429,10 @@ static int osp_obd_connect(const struct lu_env *env, struct obd_export **exp,
        *ocd = *data;
 
        imp->imp_connect_flags_orig = ocd->ocd_connect_flags;
+       imp->imp_connect_flags2_orig = ocd->ocd_connect_flags2;
 
        ocd->ocd_version = LUSTRE_VERSION_CODE;
        ocd->ocd_index = data->ocd_index;
-       imp->imp_connect_flags_orig = ocd->ocd_connect_flags;
 
        rc = ptlrpc_connect_import(imp);
        if (rc) {
@@ -1569,6 +1575,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:
@@ -1586,11 +1593,15 @@ static int osp_import_event(struct obd_device *obd, struct obd_import *imp,
                break;
        case IMP_EVENT_INACTIVE:
                d->opd_imp_active = 0;
+               d->opd_imp_connected = 0;
+               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);
                }
 
@@ -1603,6 +1614,7 @@ static int osp_import_event(struct obd_device *obd, struct obd_import *imp,
                        d->opd_new_connection = 1;
                d->opd_imp_connected = 1;
                d->opd_imp_seen_connected = 1;
+               d->opd_obd->obd_inactive = 0;
                if (d->opd_connect_mdt)
                        break;
 
@@ -1613,6 +1625,9 @@ static int osp_import_event(struct obd_device *obd, struct obd_import *imp,
                CDEBUG(D_HA, "got connected\n");
                break;
        case IMP_EVENT_INVALIDATE:
+               if (d->opd_connect_mdt)
+                       osp_invalidate_request(d);
+
                if (obd->obd_namespace == NULL)
                        break;
                ldlm_namespace_cleanup(obd->obd_namespace, LDLM_FL_LOCAL_ONLY);
@@ -1646,7 +1661,7 @@ static int osp_import_event(struct obd_device *obd, struct obd_import *imp,
  * \retval negative    negative errno if the ioctl handling failed.
  */
 static int osp_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
-                        void *karg, void *uarg)
+                        void *karg, void __user *uarg)
 {
        struct obd_device       *obd = exp->exp_obd;
        struct osp_device       *d;
@@ -1689,23 +1704,6 @@ static int osp_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
 }
 
 
-static int osp_set_info_async(const struct lu_env *env,
-                             struct obd_export *exp,
-                             u32 keylen, void *key,
-                             u32 vallen, void *val,
-                             struct ptlrpc_request_set *set)
-{
-       ENTRY;
-
-       if (KEY_IS(KEY_SPTLRPC_CONF)) {
-               sptlrpc_conf_client_adapt(exp->exp_obd);
-               RETURN(0);
-       }
-
-       CERROR("Unknown key %s\n", (char *)key);
-       RETURN(-EINVAL);
-}
-
 /**
  * Implementation of obd_ops::o_get_info
  *
@@ -1748,6 +1746,58 @@ static int osp_obd_get_info(const struct lu_env *env, struct obd_export *exp,
        RETURN(rc);
 }
 
+static int osp_obd_set_info_async(const struct lu_env *env,
+                                 struct obd_export *exp,
+                                 u32 keylen, void *key,
+                                 u32 vallen, void *val,
+                                 struct ptlrpc_request_set *set)
+{
+       struct obd_device       *obd = exp->exp_obd;
+       struct obd_import       *imp = obd->u.cli.cl_import;
+       struct osp_device       *osp;
+       struct ptlrpc_request   *req;
+       char                    *tmp;
+       int                      rc;
+
+       if (KEY_IS(KEY_SPTLRPC_CONF)) {
+               sptlrpc_conf_client_adapt(exp->exp_obd);
+               RETURN(0);
+       }
+
+       LASSERT(set != NULL);
+       if (!obd->obd_set_up || obd->obd_stopping)
+               RETURN(-EAGAIN);
+       osp = lu2osp_dev(obd->obd_lu_dev);
+
+       req = ptlrpc_request_alloc(imp, &RQF_OBD_SET_INFO);
+       if (req == NULL)
+               RETURN(-ENOMEM);
+
+       req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_KEY,
+                            RCL_CLIENT, keylen);
+       req_capsule_set_size(&req->rq_pill, &RMF_SETINFO_VAL,
+                            RCL_CLIENT, vallen);
+       if (osp->opd_connect_mdt)
+               rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SET_INFO);
+       else
+               rc = ptlrpc_request_pack(req, LUSTRE_OST_VERSION, OST_SET_INFO);
+       if (rc) {
+               ptlrpc_request_free(req);
+               RETURN(rc);
+       }
+
+       tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_KEY);
+       memcpy(tmp, key, keylen);
+       tmp = req_capsule_client_get(&req->rq_pill, &RMF_SETINFO_VAL);
+       memcpy(tmp, val, vallen);
+
+       ptlrpc_request_set_replen(req);
+       ptlrpc_set_add_req(set, req);
+       ptlrpc_check_set(NULL, set);
+
+       RETURN(0);
+}
+
 /**
  * Implementation of obd_ops: o_fid_alloc
  *
@@ -1841,13 +1891,13 @@ static struct obd_ops osp_obd_device_ops = {
        .o_connect      = osp_obd_connect,
        .o_disconnect   = osp_obd_disconnect,
        .o_get_info     = osp_obd_get_info,
+       .o_set_info_async = osp_obd_set_info_async,
        .o_import_event = osp_import_event,
        .o_iocontrol    = osp_iocontrol,
        .o_statfs       = osp_obd_statfs,
        .o_fid_init     = client_fid_init,
        .o_fid_fini     = client_fid_fini,
        .o_fid_alloc    = osp_fid_alloc,
-       .o_set_info_async   = osp_set_info_async,
 };
 
 struct llog_operations osp_mds_ost_orig_logops;
@@ -1864,7 +1914,7 @@ struct llog_operations osp_mds_ost_orig_logops;
  * \retval 0           0 if initialization succeeds.
  * \retval negative    negative errno if initialization failed.
  */
-static int __init osp_mod_init(void)
+static int __init osp_init(void)
 {
        struct obd_type *type;
        int rc;
@@ -1916,17 +1966,17 @@ static int __init osp_mod_init(void)
  * This callback is called when kernel unloads OSP module from memory, and
  * it will deregister OSP and LWP device type from obd_types (\see class_obd.c).
  */
-static void __exit osp_mod_exit(void)
+static void __exit osp_exit(void)
 {
        class_unregister_type(LUSTRE_LWP_NAME);
        class_unregister_type(LUSTRE_OSP_NAME);
        lu_kmem_fini(osp_caches);
 }
 
-MODULE_AUTHOR("Intel, Inc. <http://www.intel.com/>");
-MODULE_DESCRIPTION("Lustre OST Proxy Device ("LUSTRE_OSP_NAME")");
+MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
+MODULE_DESCRIPTION("Lustre OSD Storage Proxy ("LUSTRE_OSP_NAME")");
 MODULE_VERSION(LUSTRE_VERSION_STRING);
 MODULE_LICENSE("GPL");
 
-module_init(osp_mod_init);
-module_exit(osp_mod_exit);
+module_init(osp_init);
+module_exit(osp_exit);