+ repbody->oa.o_oi = oa->o_oi;
+ RETURN(0);
+}
+
+/**
+ * Echo Server request handler for OST_GETATTR RPC.
+ *
+ * This is Echo Server part of request handling. It returns an object
+ * attributes to the client. All objects have the same attributes in
+ * Echo Server.
+ *
+ * \param[in] tsi target session environment for this request
+ *
+ * \retval 0 if successful
+ * \retval negative value on error
+ */
+static int esd_getattr_hdl(struct tgt_session_info *tsi)
+{
+ const struct obdo *oa = &tsi->tsi_ost_body->oa;
+ struct obd_device *obd = tsi->tsi_exp->exp_obd;
+ struct ost_body *repbody;
+
+ ENTRY;
+
+ if (!(oa->o_valid & OBD_MD_FLID)) {
+ CERROR("%s: obdo missing FLID valid flag: %#llx\n",
+ tsi->tsi_exp->exp_obd->obd_name, oa->o_valid);
+ RETURN(-EINVAL);
+ }
+
+ repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
+ if (repbody == NULL)
+ RETURN(-ENOMEM);
+
+ repbody->oa.o_oi = oa->o_oi;
+ repbody->oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
+
+ obdo_cpy_md(&repbody->oa, &obd->u.echo.eo_oa, oa->o_valid);
+
+ repbody->oa.o_valid |= OBD_MD_FLFLAGS;
+ repbody->oa.o_flags = OBD_FL_FLUSH;
+
+ RETURN(0);
+}
+
+/**
+ * Echo Server request handler for OST_SETATTR RPC.
+ *
+ * This is Echo Server part of request handling. It sets common
+ * attributes from request to the Echo Server objects.
+ *
+ * \param[in] tsi target session environment for this request
+ *
+ * \retval 0 if successful
+ * \retval negative value on error
+ */
+static int esd_setattr_hdl(struct tgt_session_info *tsi)
+{
+ struct ost_body *body = tsi->tsi_ost_body;
+ struct obd_device *obd = tsi->tsi_exp->exp_obd;
+ struct ost_body *repbody;
+
+ ENTRY;
+
+ if (!(body->oa.o_valid & OBD_MD_FLID)) {
+ CERROR("%s: obdo missing FLID valid flag: %#llx\n",
+ tsi->tsi_exp->exp_obd->obd_name,
+ body->oa.o_valid);
+ RETURN(-EINVAL);
+ }
+
+ repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
+ if (repbody == NULL)
+ RETURN(-ENOMEM);
+
+ repbody->oa.o_oi = body->oa.o_oi;
+ repbody->oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
+
+ obd->u.echo.eo_oa = body->oa;
+
+ RETURN(0);
+}
+
+#define OBD_FAIL_OST_READ_NET OBD_FAIL_OST_BRW_NET
+#define OBD_FAIL_OST_WRITE_NET OBD_FAIL_OST_BRW_NET
+#define OST_BRW_READ OST_READ
+#define OST_BRW_WRITE OST_WRITE
+
+/**
+ * Table of Echo Server specific request handlers
+ *
+ * This table contains all opcodes accepted by Echo Server and
+ * specifies handlers for them. The tgt_request_handler()
+ * uses such table from each target to process incoming
+ * requests.
+ */
+static struct tgt_handler esd_tgt_handlers[] = {
+TGT_RPC_HANDLER(OST_FIRST_OPC, 0, OST_CONNECT, tgt_connect,
+ &RQF_CONNECT, LUSTRE_OBD_VERSION),
+TGT_RPC_HANDLER(OST_FIRST_OPC, 0, OST_DISCONNECT, tgt_disconnect,
+ &RQF_OST_DISCONNECT, LUSTRE_OBD_VERSION),
+TGT_OST_HDL(HABEO_CORPUS | HABEO_REFERO, OST_GETATTR, esd_getattr_hdl),
+TGT_OST_HDL(HABEO_CORPUS | HABEO_REFERO | MUTABOR, OST_SETATTR,
+ esd_setattr_hdl),
+TGT_OST_HDL(HABEO_REFERO | MUTABOR, OST_CREATE, esd_create_hdl),
+TGT_OST_HDL(HABEO_REFERO | MUTABOR, OST_DESTROY, esd_destroy_hdl),
+TGT_OST_HDL(HABEO_CORPUS | HABEO_REFERO, OST_BRW_READ, tgt_brw_read),
+TGT_OST_HDL(HABEO_CORPUS | MUTABOR, OST_BRW_WRITE, tgt_brw_write),
+};
+
+static struct tgt_opc_slice esd_common_slice[] = {
+ {
+ .tos_opc_start = OST_FIRST_OPC,
+ .tos_opc_end = OST_LAST_OPC,
+ .tos_hs = esd_tgt_handlers
+ },
+ {
+ .tos_opc_start = OBD_FIRST_OPC,
+ .tos_opc_end = OBD_LAST_OPC,
+ .tos_hs = tgt_obd_handlers
+ },
+ {
+ .tos_opc_start = LDLM_FIRST_OPC,
+ .tos_opc_end = LDLM_LAST_OPC,
+ .tos_hs = tgt_dlm_handlers
+ },
+ {
+ .tos_opc_start = SEC_FIRST_OPC,
+ .tos_opc_end = SEC_LAST_OPC,
+ .tos_hs = tgt_sec_ctx_handlers
+ },
+ {
+ .tos_hs = NULL
+ }
+};
+
+/**
+ * lu_device_operations matrix for ECHO SRV device is NULL,
+ * this device is just serving incoming requests immediately
+ * without building a stack of lu_devices.
+ */
+static struct lu_device_operations echo_srv_lu_ops = { 0 };
+
+/**
+ * Initialize Echo Server device with parameters in the config log \a cfg.
+ *
+ * This is the main starting point of Echo Server initialization. It fills all
+ * parameters with their initial values and starts Echo Server.
+ *
+ * \param[in] env execution environment
+ * \param[in] m Echo Server device
+ * \param[in] ldt LU device type of Echo Server
+ * \param[in] cfg configuration log
+ *
+ * \retval 0 if successful
+ * \retval negative value on error
+ */
+static int echo_srv_init0(const struct lu_env *env,
+ struct echo_srv_device *esd,
+ struct lu_device_type *ldt, struct lustre_cfg *cfg)
+{
+ const char *dev = lustre_cfg_string(cfg, 0);
+ struct obd_device *obd;
+ char ns_name[48];
+ int rc;
+
+ ENTRY;
+
+ obd = class_name2obd(dev);
+ if (obd == NULL) {
+ CERROR("Cannot find obd with name %s\n", dev);
+ RETURN(-ENODEV);
+ }
+
+ spin_lock_init(&obd->u.echo.eo_lock);
+ obd->u.echo.eo_lastino = ECHO_INIT_OID;
+
+ esd->esd_dev.ld_ops = &echo_srv_lu_ops;
+ esd->esd_dev.ld_obd = obd;
+ /* set this lu_device to obd, because error handling need it */
+ obd->obd_lu_dev = &esd->esd_dev;
+
+ /* No connection accepted until configurations will finish */
+ spin_lock(&obd->obd_dev_lock);
+ obd->obd_no_conn = 1;
+ spin_unlock(&obd->obd_dev_lock);
+
+ /* non-replayable target */
+ obd->obd_replayable = 0;
+
+ snprintf(ns_name, sizeof(ns_name), "echotgt-%s", obd->obd_uuid.uuid);
+ obd->obd_namespace = ldlm_namespace_new(obd, ns_name,
+ LDLM_NAMESPACE_SERVER,
+ LDLM_NAMESPACE_MODEST,
+ LDLM_NS_TYPE_OST);
+ if (obd->obd_namespace == NULL)
+ RETURN(-ENOMEM);
+
+ obd->obd_vars = lprocfs_echo_obd_vars;