4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2010, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/obdecho/echo.c
34 * Author: Peter Braam <braam@clusterfs.com>
35 * Author: Andreas Dilger <adilger@clusterfs.com>
38 #define DEBUG_SUBSYSTEM S_ECHO
40 #include <obd_support.h>
41 #include <obd_class.h>
42 #include <lustre_debug.h>
43 #include <lustre_dlm.h>
44 #include <lprocfs_status.h>
46 #include "echo_internal.h"
49 * The echo objid needs to be below 2^32, because regular FID numbers are
50 * limited to 2^32 objects in f_oid for the FID_SEQ_ECHO range. b=23335
52 #define ECHO_INIT_OID 0x10000000ULL
53 #define ECHO_HANDLE_MAGIC 0xabcd0123fedc9876ULL
55 #define ECHO_PERSISTENT_PAGES (ECHO_PERSISTENT_SIZE >> PAGE_SHIFT)
56 static struct page *echo_persistent_pages[ECHO_PERSISTENT_PAGES];
59 LPROC_ECHO_READ_BYTES = 1,
60 LPROC_ECHO_WRITE_BYTES = 2,
61 LPROC_ECHO_LAST = LPROC_ECHO_WRITE_BYTES + 1
64 struct echo_srv_device {
65 struct lu_device esd_dev;
66 struct lu_target esd_lut;
69 static inline struct echo_srv_device *echo_srv_dev(struct lu_device *d)
71 return container_of_safe(d, struct echo_srv_device, esd_dev);
74 static inline struct obd_device *echo_srv_obd(struct echo_srv_device *esd)
76 return esd->esd_dev.ld_obd;
79 static int echo_connect(const struct lu_env *env,
80 struct obd_export **exp, struct obd_device *obd,
81 struct obd_uuid *cluuid, struct obd_connect_data *data,
84 struct lustre_handle conn = { 0 };
87 data->ocd_connect_flags &= ECHO_CONNECT_SUPPORTED;
89 if (data->ocd_connect_flags & OBD_CONNECT_FLAGS2)
90 data->ocd_connect_flags2 &= ECHO_CONNECT_SUPPORTED2;
92 rc = class_connect(&conn, obd, cluuid);
94 CERROR("can't connect %d\n", rc);
97 *exp = class_conn2export(&conn);
102 static int echo_disconnect(struct obd_export *exp)
104 LASSERT(exp != NULL);
106 return server_disconnect_export(exp);
109 static int echo_init_export(struct obd_export *exp)
111 return ldlm_init_export(exp);
114 static int echo_destroy_export(struct obd_export *exp)
118 target_destroy_export(exp);
119 ldlm_destroy_export(exp);
124 static u64 echo_next_id(struct obd_device *obd)
128 spin_lock(&obd->u.echo.eo_lock);
129 id = ++obd->u.echo.eo_lastino;
130 spin_unlock(&obd->u.echo.eo_lock);
136 echo_page_debug_setup(struct page *page, int rw, u64 id,
137 __u64 offset, int len)
139 int page_offset = offset & ~PAGE_MASK;
140 char *addr = ((char *)kmap(page)) + page_offset;
142 if (len % OBD_ECHO_BLOCK_SIZE != 0)
143 CERROR("Unexpected block size %d\n", len);
146 if (rw & OBD_BRW_READ)
147 block_debug_setup(addr, OBD_ECHO_BLOCK_SIZE,
150 block_debug_setup(addr, OBD_ECHO_BLOCK_SIZE,
151 0xecc0ecc0ecc0ecc0ULL,
152 0xecc0ecc0ecc0ecc0ULL);
154 addr += OBD_ECHO_BLOCK_SIZE;
155 offset += OBD_ECHO_BLOCK_SIZE;
156 len -= OBD_ECHO_BLOCK_SIZE;
163 echo_page_debug_check(struct page *page, u64 id,
164 __u64 offset, int len)
166 int page_offset = offset & ~PAGE_MASK;
167 char *addr = ((char *)kmap(page)) + page_offset;
171 if (len % OBD_ECHO_BLOCK_SIZE != 0)
172 CERROR("Unexpected block size %d\n", len);
175 rc2 = block_debug_check("echo", addr, OBD_ECHO_BLOCK_SIZE,
178 if (rc2 != 0 && rc == 0)
181 addr += OBD_ECHO_BLOCK_SIZE;
182 offset += OBD_ECHO_BLOCK_SIZE;
183 len -= OBD_ECHO_BLOCK_SIZE;
191 static int echo_map_nb_to_lb(struct obdo *oa, struct obd_ioobj *obj,
192 struct niobuf_remote *nb, int *pages,
193 struct niobuf_local *lb, int cmd, int *left)
195 gfp_t gfp_mask = (ostid_id(&obj->ioo_oid) & 1) ?
196 GFP_HIGHUSER : GFP_KERNEL;
197 int ispersistent = ostid_id(&obj->ioo_oid) == ECHO_PERSISTENT_OBJID;
198 int debug_setup = (!ispersistent &&
199 (oa->o_valid & OBD_MD_FLFLAGS) != 0 &&
200 (oa->o_flags & OBD_FL_DEBUG_CHECK) != 0);
201 struct niobuf_local *res = lb;
202 u64 offset = nb->rnb_offset;
203 int len = nb->rnb_len;
206 int plen = PAGE_SIZE - (offset & (PAGE_SIZE - 1));
211 /* check for local buf overflow */
215 res->lnb_file_offset = offset;
217 LASSERT((res->lnb_file_offset & ~PAGE_MASK) +
218 res->lnb_len <= PAGE_SIZE);
221 ((res->lnb_file_offset >> PAGE_SHIFT) <
222 ECHO_PERSISTENT_PAGES)) {
224 echo_persistent_pages[res->lnb_file_offset >>
226 /* Take extra ref so __free_pages() can be called OK */
227 get_page(res->lnb_page);
229 res->lnb_page = alloc_page(gfp_mask);
230 if (!res->lnb_page) {
231 CERROR("can't get page for id " DOSTID"\n",
232 POSTID(&obj->ioo_oid));
235 /* set mapping so page is not considered encrypted */
236 res->lnb_page->mapping = ECHO_MAPPING_UNENCRYPTED;
239 CDEBUG(D_PAGE, "$$$$ get page %p @ %llu for %d\n",
240 res->lnb_page, res->lnb_file_offset, res->lnb_len);
242 if (cmd & OBD_BRW_READ)
243 res->lnb_rc = res->lnb_len;
246 echo_page_debug_setup(res->lnb_page, cmd,
247 ostid_id(&obj->ioo_oid),
248 res->lnb_file_offset,
262 static int echo_finalize_lb(struct obdo *oa, struct obd_ioobj *obj,
263 struct niobuf_remote *rb, int *pgs,
264 struct niobuf_local *lb, int verify)
266 struct niobuf_local *res = lb;
267 u64 start = rb->rnb_offset >> PAGE_SHIFT;
268 u64 end = (rb->rnb_offset + rb->rnb_len + PAGE_SIZE - 1) >>
270 int count = (int)(end - start);
274 for (i = 0; i < count; i++, (*pgs) ++, res++) {
275 struct page *page = res->lnb_page;
279 CERROR("null page objid %llu:%p, buf %d/%d\n",
280 ostid_id(&obj->ioo_oid), page, i,
287 CDEBUG(D_PAGE, "$$$$ use page %p, addr %p@%llu\n",
288 res->lnb_page, addr, res->lnb_file_offset);
291 int vrc = echo_page_debug_check(page,
292 ostid_id(&obj->ioo_oid),
293 res->lnb_file_offset,
295 /* check all the pages always */
296 if (vrc != 0 && rc == 0)
301 /* NB see comment above regarding persistent pages */
308 static int echo_preprw(const struct lu_env *env, int cmd,
309 struct obd_export *export, struct obdo *oa,
310 int objcount, struct obd_ioobj *obj,
311 struct niobuf_remote *nb, int *pages,
312 struct niobuf_local *res)
314 struct obd_device *obd;
321 obd = export->exp_obd;
325 /* Temp fix to stop falling foul of osc_announce_cached() */
326 oa->o_valid &= ~(OBD_MD_FLBLOCKS | OBD_MD_FLGRANT);
328 memset(res, 0, sizeof(*res) * *pages);
330 CDEBUG(D_PAGE, "%s %d obdos with %d IOs\n",
331 cmd == OBD_BRW_READ ? "reading" : "writing", objcount, *pages);
336 for (i = 0; i < objcount; i++, obj++) {
339 for (j = 0 ; j < obj->ioo_bufcnt ; j++, nb++) {
340 rc = echo_map_nb_to_lb(oa, obj, nb, pages,
341 res + *pages, cmd, &left);
343 GOTO(preprw_cleanup, rc);
345 tot_bytes += nb->rnb_len;
349 atomic_add(*pages, &obd->u.echo.eo_prep);
351 if (cmd & OBD_BRW_READ)
352 lprocfs_counter_add(obd->obd_stats, LPROC_ECHO_READ_BYTES,
355 lprocfs_counter_add(obd->obd_stats, LPROC_ECHO_WRITE_BYTES,
358 CDEBUG(D_PAGE, "%d pages allocated after prep\n",
359 atomic_read(&obd->u.echo.eo_prep));
365 * It is possible that we would rather handle errors by allow
366 * any already-set-up pages to complete, rather than tearing them
367 * all down again. I believe that this is what the in-kernel
368 * prep/commit operations do.
370 CERROR("cleaning up %u pages (%d obdos)\n", *pages, objcount);
371 for (i = 0; i < *pages; i++) {
372 kunmap(res[i].lnb_page);
374 * NB if this is a persistent page, __free_page() will just
375 * lose the extra ref gained above
377 __free_page(res[i].lnb_page);
378 res[i].lnb_page = NULL;
379 atomic_dec(&obd->u.echo.eo_prep);
385 static int echo_commitrw(const struct lu_env *env, int cmd,
386 struct obd_export *export, struct obdo *oa,
387 int objcount, struct obd_ioobj *obj,
388 struct niobuf_remote *rb, int niocount,
389 struct niobuf_local *res, int rc)
391 struct obd_device *obd;
397 obd = export->exp_obd;
402 GOTO(commitrw_cleanup, rc);
404 if ((cmd & OBD_BRW_RWMASK) == OBD_BRW_READ) {
405 CDEBUG(D_PAGE, "reading %d obdos with %d IOs\n",
408 CDEBUG(D_PAGE, "writing %d obdos with %d IOs\n",
412 if (niocount && !res) {
413 CERROR("NULL res niobuf with niocount %d\n", niocount);
417 for (i = 0; i < objcount; i++, obj++) {
418 int verify = (rc == 0 &&
419 ostid_id(&obj->ioo_oid) != ECHO_PERSISTENT_OBJID &&
420 (oa->o_valid & OBD_MD_FLFLAGS) != 0 &&
421 (oa->o_flags & OBD_FL_DEBUG_CHECK) != 0);
424 for (j = 0 ; j < obj->ioo_bufcnt ; j++, rb++) {
425 int vrc = echo_finalize_lb(oa, obj, rb, &pgs, &res[pgs],
431 GOTO(commitrw_cleanup, rc = vrc);
438 atomic_sub(pgs, &obd->u.echo.eo_prep);
440 CDEBUG(D_PAGE, "%d pages remain after commit\n",
441 atomic_read(&obd->u.echo.eo_prep));
445 atomic_sub(pgs, &obd->u.echo.eo_prep);
447 CERROR("cleaning up %d pages (%d obdos)\n",
448 niocount - pgs - 1, objcount);
450 while (pgs < niocount) {
451 struct page *page = res[pgs++].lnb_page;
456 /* NB see comment above regarding persistent pages */
458 atomic_dec(&obd->u.echo.eo_prep);
463 LPROC_SEQ_FOPS_RO_TYPE(echo, uuid);
464 static struct lprocfs_vars lprocfs_echo_obd_vars[] = {
466 .fops = &echo_uuid_fops },
470 const struct obd_ops echo_obd_ops = {
471 .o_owner = THIS_MODULE,
472 .o_connect = echo_connect,
473 .o_disconnect = echo_disconnect,
474 .o_init_export = echo_init_export,
475 .o_destroy_export = echo_destroy_export,
476 .o_preprw = echo_preprw,
477 .o_commitrw = echo_commitrw,
481 * Echo Server request handler for OST_CREATE RPC.
483 * This is part of request processing. Its simulates the object
486 * \param[in] tsi target session environment for this request
488 * \retval 0 if successful
489 * \retval negative value on error
491 static int esd_create_hdl(struct tgt_session_info *tsi)
493 const struct obdo *oa = &tsi->tsi_ost_body->oa;
494 struct obd_device *obd = tsi->tsi_exp->exp_obd;
495 struct ost_body *repbody;
500 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
504 if (!(oa->o_mode & S_IFMT)) {
505 CERROR("%s: no type is set in obdo!\n",
506 tsi->tsi_exp->exp_obd->obd_name);
510 if (!(oa->o_valid & OBD_MD_FLTYPE)) {
511 CERROR("%s: invalid o_valid in obdo: %#llx\n",
512 tsi->tsi_exp->exp_obd->obd_name, oa->o_valid);
516 rep_oa = &repbody->oa;
518 if (!fid_seq_is_echo(ostid_seq(&oa->o_oi))) {
519 CERROR("%s: invalid seq %#llx\n",
520 tsi->tsi_exp->exp_obd->obd_name, ostid_seq(&oa->o_oi));
524 ostid_set_seq_echo(&rep_oa->o_oi);
525 ostid_set_id(&rep_oa->o_oi, echo_next_id(obd));
527 CDEBUG(D_INFO, "%s: Create object "DOSTID"\n",
528 tsi->tsi_exp->exp_obd->obd_name, POSTID(&rep_oa->o_oi));
530 rep_oa->o_valid |= OBD_MD_FLID | OBD_MD_FLGROUP;
536 * Echo Server request handler for OST_DESTROY RPC.
538 * This is Echo Server part of request handling. It simulates the objects
541 * \param[in] tsi target session environment for this request
543 * \retval 0 if successful
544 * \retval negative value on error
546 static int esd_destroy_hdl(struct tgt_session_info *tsi)
548 const struct obdo *oa = &tsi->tsi_ost_body->oa;
549 struct obd_device *obd = tsi->tsi_exp->exp_obd;
550 struct ost_body *repbody;
555 oid = ostid_id(&oa->o_oi);
558 if (!(oa->o_valid & OBD_MD_FLID)) {
559 CERROR("%s: obdo missing FLID valid flag: %#llx\n",
560 tsi->tsi_exp->exp_obd->obd_name, oa->o_valid);
564 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
566 if (ostid_id(&oa->o_oi) > obd->u.echo.eo_lastino ||
567 ostid_id(&oa->o_oi) < ECHO_INIT_OID) {
568 CERROR("%s: bad objid to destroy: "DOSTID"\n",
569 tsi->tsi_exp->exp_obd->obd_name, POSTID(&oa->o_oi));
573 CDEBUG(D_INFO, "%s: Destroy object "DOSTID"\n",
574 tsi->tsi_exp->exp_obd->obd_name, POSTID(&oa->o_oi));
576 repbody->oa.o_oi = oa->o_oi;
581 * Echo Server request handler for OST_GETATTR RPC.
583 * This is Echo Server part of request handling. It returns an object
584 * attributes to the client. All objects have the same attributes in
587 * \param[in] tsi target session environment for this request
589 * \retval 0 if successful
590 * \retval negative value on error
592 static int esd_getattr_hdl(struct tgt_session_info *tsi)
594 const struct obdo *oa = &tsi->tsi_ost_body->oa;
595 struct obd_device *obd = tsi->tsi_exp->exp_obd;
596 struct ost_body *repbody;
600 if (!(oa->o_valid & OBD_MD_FLID)) {
601 CERROR("%s: obdo missing FLID valid flag: %#llx\n",
602 tsi->tsi_exp->exp_obd->obd_name, oa->o_valid);
606 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
610 repbody->oa.o_oi = oa->o_oi;
611 repbody->oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
613 obdo_cpy_md(&repbody->oa, &obd->u.echo.eo_oa, oa->o_valid);
615 repbody->oa.o_valid |= OBD_MD_FLFLAGS;
616 repbody->oa.o_flags = OBD_FL_FLUSH;
622 * Echo Server request handler for OST_SETATTR RPC.
624 * This is Echo Server part of request handling. It sets common
625 * attributes from request to the Echo Server objects.
627 * \param[in] tsi target session environment for this request
629 * \retval 0 if successful
630 * \retval negative value on error
632 static int esd_setattr_hdl(struct tgt_session_info *tsi)
634 struct ost_body *body = tsi->tsi_ost_body;
635 struct obd_device *obd = tsi->tsi_exp->exp_obd;
636 struct ost_body *repbody;
640 if (!(body->oa.o_valid & OBD_MD_FLID)) {
641 CERROR("%s: obdo missing FLID valid flag: %#llx\n",
642 tsi->tsi_exp->exp_obd->obd_name,
647 repbody = req_capsule_server_get(tsi->tsi_pill, &RMF_OST_BODY);
651 repbody->oa.o_oi = body->oa.o_oi;
652 repbody->oa.o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
654 obd->u.echo.eo_oa = body->oa;
659 #define OBD_FAIL_OST_READ_NET OBD_FAIL_OST_BRW_NET
660 #define OBD_FAIL_OST_WRITE_NET OBD_FAIL_OST_BRW_NET
661 #define OST_BRW_READ OST_READ
662 #define OST_BRW_WRITE OST_WRITE
665 * Table of Echo Server specific request handlers
667 * This table contains all opcodes accepted by Echo Server and
668 * specifies handlers for them. The tgt_request_handler()
669 * uses such table from each target to process incoming
672 static struct tgt_handler esd_tgt_handlers[] = {
673 TGT_RPC_HANDLER(OST_FIRST_OPC, 0, OST_CONNECT, tgt_connect,
674 &RQF_CONNECT, LUSTRE_OBD_VERSION),
675 TGT_RPC_HANDLER(OST_FIRST_OPC, 0, OST_DISCONNECT, tgt_disconnect,
676 &RQF_OST_DISCONNECT, LUSTRE_OBD_VERSION),
677 TGT_OST_HDL(HAS_BODY | HAS_REPLY, OST_GETATTR, esd_getattr_hdl),
678 TGT_OST_HDL(HAS_BODY | HAS_REPLY | IS_MUTABLE, OST_SETATTR,
680 TGT_OST_HDL(HAS_REPLY | IS_MUTABLE, OST_CREATE, esd_create_hdl),
681 TGT_OST_HDL(HAS_REPLY | IS_MUTABLE, OST_DESTROY, esd_destroy_hdl),
682 TGT_OST_HDL(HAS_BODY | HAS_REPLY, OST_BRW_READ, tgt_brw_read),
683 TGT_OST_HDL(HAS_BODY | IS_MUTABLE, OST_BRW_WRITE, tgt_brw_write),
686 static struct tgt_opc_slice esd_common_slice[] = {
688 .tos_opc_start = OST_FIRST_OPC,
689 .tos_opc_end = OST_LAST_OPC,
690 .tos_hs = esd_tgt_handlers
693 .tos_opc_start = OBD_FIRST_OPC,
694 .tos_opc_end = OBD_LAST_OPC,
695 .tos_hs = tgt_obd_handlers
698 .tos_opc_start = LDLM_FIRST_OPC,
699 .tos_opc_end = LDLM_LAST_OPC,
700 .tos_hs = tgt_dlm_handlers
703 .tos_opc_start = SEC_FIRST_OPC,
704 .tos_opc_end = SEC_LAST_OPC,
705 .tos_hs = tgt_sec_ctx_handlers
713 * lu_device_operations matrix for ECHO SRV device is NULL,
714 * this device is just serving incoming requests immediately
715 * without building a stack of lu_devices.
717 static struct lu_device_operations echo_srv_lu_ops = { 0 };
720 * Initialize Echo Server device with parameters in the config log \a cfg.
722 * This is the main starting point of Echo Server initialization. It fills all
723 * parameters with their initial values and starts Echo Server.
725 * \param[in] env execution environment
726 * \param[in] m Echo Server device
727 * \param[in] ldt LU device type of Echo Server
728 * \param[in] cfg configuration log
730 * \retval 0 if successful
731 * \retval negative value on error
733 static int echo_srv_init0(const struct lu_env *env,
734 struct echo_srv_device *esd,
735 struct lu_device_type *ldt, struct lustre_cfg *cfg)
737 const char *dev = lustre_cfg_string(cfg, 0);
738 struct obd_device *obd;
744 obd = class_name2obd(dev);
746 CERROR("Cannot find obd with name %s\n", dev);
750 spin_lock_init(&obd->u.echo.eo_lock);
751 obd->u.echo.eo_lastino = ECHO_INIT_OID;
753 esd->esd_dev.ld_ops = &echo_srv_lu_ops;
754 esd->esd_dev.ld_obd = obd;
755 /* set this lu_device to obd, because error handling need it */
756 obd->obd_lu_dev = &esd->esd_dev;
758 /* No connection accepted until configurations will finish */
759 spin_lock(&obd->obd_dev_lock);
760 obd->obd_no_conn = 1;
761 spin_unlock(&obd->obd_dev_lock);
763 /* non-replayable target */
764 obd->obd_replayable = 0;
766 snprintf(ns_name, sizeof(ns_name), "echotgt-%s", obd->obd_uuid.uuid);
767 obd->obd_namespace = ldlm_namespace_new(obd, ns_name,
768 LDLM_NAMESPACE_SERVER,
769 LDLM_NAMESPACE_MODEST,
771 if (!obd->obd_namespace)
774 obd->obd_vars = lprocfs_echo_obd_vars;
775 if (!lprocfs_obd_setup(obd, true) &&
776 lprocfs_alloc_obd_stats(obd, LPROC_ECHO_LAST) == 0) {
777 lprocfs_counter_init(obd->obd_stats, LPROC_ECHO_READ_BYTES,
778 LPROCFS_CNTR_AVGMINMAX,
779 "read_bytes", "bytes");
780 lprocfs_counter_init(obd->obd_stats, LPROC_ECHO_WRITE_BYTES,
781 LPROCFS_CNTR_AVGMINMAX,
782 "write_bytes", "bytes");
785 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
786 "echo_ldlm_cb_client", &obd->obd_ldlm_client);
788 rc = tgt_init(env, &esd->esd_lut, obd, NULL, esd_common_slice,
789 OBD_FAIL_OST_ALL_REQUEST_NET,
790 OBD_FAIL_OST_ALL_REPLY_NET);
794 spin_lock(&obd->obd_dev_lock);
795 obd->obd_no_conn = 0;
796 spin_unlock(&obd->obd_dev_lock);
801 ldlm_namespace_free(obd->obd_namespace, NULL, obd->obd_force);
802 obd->obd_namespace = NULL;
804 lprocfs_obd_cleanup(obd);
805 lprocfs_free_obd_stats(obd);
810 * Stop the Echo Server device.
812 * This function stops the Echo Server device and all its subsystems.
813 * This is the end of Echo Server lifecycle.
815 * \param[in] env execution environment
816 * \param[in] esd ESD device
818 static void echo_srv_fini(const struct lu_env *env,
819 struct echo_srv_device *esd)
821 struct obd_device *obd = echo_srv_obd(esd);
822 struct lu_device *d = &esd->esd_dev;
827 class_disconnect_exports(obd);
828 if (obd->obd_namespace)
829 ldlm_namespace_free_prior(obd->obd_namespace, NULL,
832 obd_exports_barrier(obd);
833 obd_zombie_barrier();
835 tgt_fini(env, &esd->esd_lut);
837 if (obd->obd_namespace) {
838 ldlm_namespace_free_post(obd->obd_namespace);
839 obd->obd_namespace = NULL;
842 lprocfs_obd_cleanup(obd);
843 lprocfs_free_obd_stats(obd);
845 leaked = atomic_read(&obd->u.echo.eo_prep);
847 CERROR("%d prep/commitrw pages leaked\n", leaked);
849 LASSERT(atomic_read(&d->ld_ref) == 0);
854 * Implementation of lu_device_type_operations::ldto_device_fini.
856 * Finalize device. Dual to echo_srv_device_init(). It is called from
857 * obd_precleanup() and stops the current device.
859 * \param[in] env execution environment
860 * \param[in] d LU device of ESD
864 static struct lu_device *echo_srv_device_fini(const struct lu_env *env,
868 echo_srv_fini(env, echo_srv_dev(d));
873 * Implementation of lu_device_type_operations::ldto_device_free.
875 * Free Echo Server device. Dual to echo_srv_device_alloc().
877 * \param[in] env execution environment
878 * \param[in] d LU device of ESD
882 static struct lu_device *echo_srv_device_free(const struct lu_env *env,
885 struct echo_srv_device *esd = echo_srv_dev(d);
887 lu_device_fini(&esd->esd_dev);
893 * Implementation of lu_device_type_operations::ldto_device_alloc.
895 * This function allocates the new Echo Server device. It is called from
896 * obd_setup() if OBD device had lu_device_type defined.
898 * \param[in] env execution environment
899 * \param[in] t lu_device_type of ESD device
900 * \param[in] cfg configuration log
902 * \retval pointer to the lu_device of just allocated OFD
903 * \retval ERR_PTR of return value on error
905 static struct lu_device *echo_srv_device_alloc(const struct lu_env *env,
906 struct lu_device_type *t,
907 struct lustre_cfg *cfg)
909 struct echo_srv_device *esd;
915 return ERR_PTR(-ENOMEM);
918 lu_device_init(l, t);
919 rc = echo_srv_init0(env, esd, t, cfg);
921 echo_srv_device_free(env, l);
928 static const struct lu_device_type_operations echo_srv_type_ops = {
929 .ldto_device_alloc = echo_srv_device_alloc,
930 .ldto_device_free = echo_srv_device_free,
931 .ldto_device_fini = echo_srv_device_fini
934 struct lu_device_type echo_srv_type = {
935 .ldt_tags = LU_DEVICE_DT,
936 .ldt_name = LUSTRE_ECHO_NAME,
937 .ldt_ops = &echo_srv_type_ops,
938 .ldt_ctx_tags = LCT_DT_THREAD,
941 void echo_persistent_pages_fini(void)
945 for (i = 0; i < ECHO_PERSISTENT_PAGES; i++)
946 if (echo_persistent_pages[i]) {
947 __free_page(echo_persistent_pages[i]);
948 echo_persistent_pages[i] = NULL;
952 int echo_persistent_pages_init(void)
957 for (i = 0; i < ECHO_PERSISTENT_PAGES; i++) {
958 gfp_t gfp_mask = (i < ECHO_PERSISTENT_PAGES / 2) ?
959 GFP_KERNEL : GFP_HIGHUSER;
961 pg = alloc_page(gfp_mask);
963 echo_persistent_pages_fini();
967 memset(kmap(pg), 0, PAGE_SIZE);
969 /* set mapping so page is not considered encrypted */
970 pg->mapping = ECHO_MAPPING_UNENCRYPTED;
972 echo_persistent_pages[i] = pg;