+/*
+ * lprocfs helpers still use OBD API, let's keep obd_statfs() support
+ */
+static int osp_obd_statfs(const struct lu_env *env, struct obd_export *exp,
+ struct obd_statfs *osfs, __u64 max_age, __u32 flags)
+{
+ struct obd_statfs *msfs;
+ struct ptlrpc_request *req;
+ struct obd_import *imp = NULL;
+ int rc;
+
+ ENTRY;
+
+ /* Since the request might also come from lprocfs, so we need
+ * sync this with client_disconnect_export Bug15684 */
+ down_read(&exp->exp_obd->u.cli.cl_sem);
+ if (exp->exp_obd->u.cli.cl_import)
+ imp = class_import_get(exp->exp_obd->u.cli.cl_import);
+ up_read(&exp->exp_obd->u.cli.cl_sem);
+ if (!imp)
+ RETURN(-ENODEV);
+
+ /* We could possibly pass max_age in the request (as an absolute
+ * timestamp or a "seconds.usec ago") so the target can avoid doing
+ * extra calls into the filesystem if that isn't necessary (e.g.
+ * during mount that would help a bit). Having relative timestamps
+ * is not so great if request processing is slow, while absolute
+ * timestamps are not ideal because they need time synchronization. */
+ req = ptlrpc_request_alloc(imp, &RQF_OST_STATFS);
+
+ class_import_put(imp);
+
+ if (req == NULL)
+ RETURN(-ENOMEM);
+
+ rc = ptlrpc_request_pack(req, LUSTRE_OST_VERSION, OST_STATFS);
+ if (rc) {
+ ptlrpc_request_free(req);
+ RETURN(rc);
+ }
+ ptlrpc_request_set_replen(req);
+ req->rq_request_portal = OST_CREATE_PORTAL;
+ ptlrpc_at_set_req_timeout(req);
+
+ if (flags & OBD_STATFS_NODELAY) {
+ /* procfs requests not want stat in wait for avoid deadlock */
+ req->rq_no_resend = 1;
+ req->rq_no_delay = 1;
+ }
+
+ rc = ptlrpc_queue_wait(req);
+ if (rc)
+ GOTO(out, rc);
+
+ msfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS);
+ if (msfs == NULL)
+ GOTO(out, rc = -EPROTO);
+
+ *osfs = *msfs;
+
+ EXIT;
+out:
+ ptlrpc_req_finished(req);
+ return rc;
+}
+
+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);
+
+ switch (event) {
+ case IMP_EVENT_DISCON:
+ d->opd_got_disconnected = 1;
+ d->opd_imp_connected = 0;
+ if (d->opd_connect_mdt)
+ break;
+ osp_pre_update_status(d, -ENODEV);
+ cfs_waitq_signal(&d->opd_pre_waitq);
+ CDEBUG(D_HA, "got disconnected\n");
+ break;
+ case IMP_EVENT_INACTIVE:
+ d->opd_imp_active = 0;
+ if (d->opd_connect_mdt)
+ break;
+ osp_pre_update_status(d, -ENODEV);
+ cfs_waitq_signal(&d->opd_pre_waitq);
+ CDEBUG(D_HA, "got inactive\n");
+ break;
+ case IMP_EVENT_ACTIVE:
+ d->opd_imp_active = 1;
+ if (d->opd_got_disconnected)
+ d->opd_new_connection = 1;
+ d->opd_imp_connected = 1;
+ d->opd_imp_seen_connected = 1;
+ if (d->opd_connect_mdt)
+ break;
+ cfs_waitq_signal(&d->opd_pre_waitq);
+ __osp_sync_check_for_work(d);
+ CDEBUG(D_HA, "got connected\n");
+ break;
+ case IMP_EVENT_INVALIDATE:
+ if (obd->obd_namespace == NULL)
+ break;
+ ldlm_namespace_cleanup(obd->obd_namespace, LDLM_FL_LOCAL_ONLY);
+ break;
+ case IMP_EVENT_OCD:
+ case IMP_EVENT_DEACTIVATE:
+ case IMP_EVENT_ACTIVATE:
+ break;
+ default:
+ CERROR("%s: unsupported import event: %#x\n",
+ obd->obd_name, event);
+ }
+ return 0;
+}
+
+static int osp_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
+ void *karg, void *uarg)
+{
+ struct obd_device *obd = exp->exp_obd;
+ struct osp_device *d;
+ struct obd_ioctl_data *data = karg;
+ int rc = 0;
+
+ ENTRY;
+
+ LASSERT(obd->obd_lu_dev);
+ d = lu2osp_dev(obd->obd_lu_dev);
+ LASSERT(d->opd_dt_dev.dd_ops == &osp_dt_ops);
+
+ if (!cfs_try_module_get(THIS_MODULE)) {
+ CERROR("%s: can't get module. Is it alive?", obd->obd_name);
+ return -EINVAL;
+ }
+
+ switch (cmd) {
+ case OBD_IOC_CLIENT_RECOVER:
+ rc = ptlrpc_recover_import(obd->u.cli.cl_import,
+ data->ioc_inlbuf1, 0);
+ if (rc > 0)
+ rc = 0;
+ break;
+ case IOC_OSC_SET_ACTIVE:
+ rc = ptlrpc_set_import_active(obd->u.cli.cl_import,
+ data->ioc_offset);
+ break;
+ case OBD_IOC_PING_TARGET:
+ rc = ptlrpc_obd_ping(obd);
+ break;
+ default:
+ CERROR("%s: unrecognized ioctl %#x by %s\n", obd->obd_name,
+ cmd, cfs_curproc_comm());
+ rc = -ENOTTY;
+ }
+ cfs_module_put(THIS_MODULE);
+ return rc;
+}
+
+static int osp_obd_health_check(const struct lu_env *env,
+ struct obd_device *obd)
+{
+ struct osp_device *d = lu2osp_dev(obd->obd_lu_dev);
+
+ ENTRY;
+
+ /*
+ * 1.8/2.0 behaviour is that OST being connected once at least
+ * is considired "healthy". and one "healty" OST is enough to
+ * allow lustre clients to connect to MDS
+ */
+ LASSERT(d);
+ RETURN(!d->opd_imp_seen_connected);
+}
+