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) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
32 #define DEBUG_SUBSYSTEM S_ECHO
34 #include <linux/user_namespace.h>
35 #include <linux/uidgid.h>
37 #include <libcfs/libcfs.h>
39 #include <obd_support.h>
40 #include <obd_class.h>
41 #include <lprocfs_status.h>
42 #include <cl_object.h>
43 #include <lustre_fid.h>
44 #include <lustre_lmv.h>
45 #include <lustre_acl.h>
46 #include <uapi/linux/lustre/lustre_ioctl.h>
47 #include <lustre_net.h>
48 #ifdef HAVE_SERVER_SUPPORT
49 # include <md_object.h>
51 #define ETI_NAME_LEN 20
53 #endif /* HAVE_SERVER_SUPPORT */
55 #include "echo_internal.h"
57 /** \defgroup echo_client Echo Client
61 /* echo thread key have a CL_THREAD flag, which set cl_env function directly */
62 #define ECHO_MD_CTX_TAG (LCT_REMEMBER | LCT_MD_THREAD)
63 #define ECHO_DT_CTX_TAG (LCT_REMEMBER | LCT_DT_THREAD)
64 #define ECHO_SES_TAG (LCT_REMEMBER | LCT_SESSION | LCT_SERVER_SESSION)
67 struct cl_device ed_cl;
68 struct echo_client_obd *ed_ec;
70 struct cl_site ed_site_myself;
71 struct lu_site *ed_site;
72 struct lu_device *ed_next;
74 struct lu_client_seq *ed_cl_seq;
75 #ifdef HAVE_SERVER_SUPPORT
76 struct local_oid_storage *ed_los;
77 struct lu_fid ed_root_fid;
78 #endif /* HAVE_SERVER_SUPPORT */
82 struct cl_object eo_cl;
83 struct cl_object_header eo_hdr;
84 struct echo_device *eo_dev;
85 struct list_head eo_obj_chain;
86 struct lov_oinfo *eo_oinfo;
90 struct echo_object_conf {
91 struct cl_object_conf eoc_cl;
92 struct lov_oinfo **eoc_oinfo;
95 #ifdef HAVE_SERVER_SUPPORT
96 static const char echo_md_root_dir_name[] = "ROOT_ECHO";
99 * In order to use the values of members in struct mdd_device,
100 * we define an alias structure here.
102 struct echo_md_device {
103 struct md_device emd_md_dev;
104 struct obd_export *emd_child_exp;
105 struct dt_device *emd_child;
106 struct dt_device *emd_bottom;
107 struct lu_fid emd_root_fid;
108 struct lu_fid emd_local_root_fid;
110 #endif /* HAVE_SERVER_SUPPORT */
112 static int echo_client_setup(const struct lu_env *env,
113 struct obd_device *obd,
114 struct lustre_cfg *lcfg);
115 static int echo_client_cleanup(struct obd_device *obd);
117 /** \defgroup echo_helpers Helper functions
120 static struct echo_device *cl2echo_dev(const struct cl_device *dev)
122 return container_of_safe(dev, struct echo_device, ed_cl);
125 static struct cl_device *echo_dev2cl(struct echo_device *d)
130 static struct echo_device *obd2echo_dev(const struct obd_device *obd)
132 return cl2echo_dev(lu2cl_dev(obd->obd_lu_dev));
135 static struct cl_object *echo_obj2cl(struct echo_object *eco)
140 static struct echo_object *cl2echo_obj(const struct cl_object *o)
142 return container_of(o, struct echo_object, eo_cl);
145 static struct lu_context_key echo_thread_key;
147 static struct echo_thread_info *echo_env_info(const struct lu_env *env)
149 struct echo_thread_info *info;
151 info = lu_context_key_get(&env->le_ctx, &echo_thread_key);
152 LASSERT(info != NULL);
156 static struct echo_object_conf *cl2echo_conf(const struct cl_object_conf *c)
158 return container_of(c, struct echo_object_conf, eoc_cl);
161 #ifdef HAVE_SERVER_SUPPORT
162 static struct echo_md_device *lu2emd_dev(struct lu_device *d)
164 return container_of_safe(d, struct echo_md_device,
165 emd_md_dev.md_lu_dev);
168 static struct lu_device *emd2lu_dev(struct echo_md_device *d)
170 return &d->emd_md_dev.md_lu_dev;
173 static struct seq_server_site *echo_md_seq_site(struct echo_md_device *d)
175 return emd2lu_dev(d)->ld_site->ld_seq_site;
178 static struct obd_device *emd2obd_dev(struct echo_md_device *d)
180 return d->emd_md_dev.md_lu_dev.ld_obd;
182 #endif /* HAVE_SERVER_SUPPORT */
184 /** @} echo_helpers */
186 static int cl_echo_object_put(struct echo_object *eco);
188 struct echo_thread_info {
189 struct echo_object_conf eti_conf;
190 struct lustre_md eti_md;
191 struct lu_fid eti_fid;
192 struct lu_fid eti_fid2;
193 #ifdef HAVE_SERVER_SUPPORT
194 struct md_op_spec eti_spec;
195 struct lov_mds_md_v3 eti_lmm;
196 struct lov_user_md_v3 eti_lum;
197 struct md_attr eti_ma;
198 struct lu_name eti_lname;
199 /* per-thread values, can be re-used */
200 void *eti_big_lmm; /* may be vmalloc'd */
202 char eti_name[ETI_NAME_LEN];
203 struct lu_buf eti_buf;
204 /* If we want to test large ACL, then need to enlarge the buffer. */
205 char eti_xattr_buf[LUSTRE_POSIX_ACL_MAX_SIZE_OLD];
209 /* No session used right now */
210 struct echo_session_info {
214 static struct kmem_cache *echo_object_kmem;
215 static struct kmem_cache *echo_thread_kmem;
216 static struct kmem_cache *echo_session_kmem;
218 static struct lu_kmem_descr echo_caches[] = {
220 .ckd_cache = &echo_object_kmem,
221 .ckd_name = "echo_object_kmem",
222 .ckd_size = sizeof(struct echo_object)
225 .ckd_cache = &echo_thread_kmem,
226 .ckd_name = "echo_thread_kmem",
227 .ckd_size = sizeof(struct echo_thread_info)
230 .ckd_cache = &echo_session_kmem,
231 .ckd_name = "echo_session_kmem",
232 .ckd_size = sizeof(struct echo_session_info)
239 /** \defgroup echo_lu_ops lu_object operations
241 * operations for echo lu object.
245 static int echo_object_init(const struct lu_env *env, struct lu_object *obj,
246 const struct lu_object_conf *conf)
248 struct echo_device *ed = cl2echo_dev(lu2cl_dev(obj->lo_dev));
249 struct echo_client_obd *ec = ed->ed_ec;
250 struct echo_object *eco = cl2echo_obj(lu2cl(obj));
254 struct lu_object *below;
255 struct lu_device *under;
258 below = under->ld_ops->ldo_object_alloc(env, obj->lo_header,
262 lu_object_add(obj, below);
265 if (!ed->ed_next_ismd) {
266 const struct cl_object_conf *cconf = lu2cl_conf(conf);
267 struct echo_object_conf *econf = cl2echo_conf(cconf);
269 LASSERT(econf->eoc_oinfo != NULL);
272 * Transfer the oinfo pointer to eco that it won't be
275 eco->eo_oinfo = *econf->eoc_oinfo;
276 *econf->eoc_oinfo = NULL;
278 eco->eo_oinfo = NULL;
282 cl_object_page_init(lu2cl(obj), 0);
284 spin_lock(&ec->ec_lock);
285 list_add_tail(&eco->eo_obj_chain, &ec->ec_objects);
286 spin_unlock(&ec->ec_lock);
291 static void echo_object_delete(const struct lu_env *env, struct lu_object *obj)
293 struct echo_object *eco = cl2echo_obj(lu2cl(obj));
294 struct echo_client_obd *ec;
298 /* object delete called unconditolally - layer init or not */
299 if (eco->eo_dev == NULL)
302 ec = eco->eo_dev->ed_ec;
304 spin_lock(&ec->ec_lock);
305 list_del_init(&eco->eo_obj_chain);
306 spin_unlock(&ec->ec_lock);
309 OBD_FREE_PTR(eco->eo_oinfo);
312 static void echo_object_free_rcu(struct rcu_head *head)
314 struct echo_object *eco = container_of(head, struct echo_object,
315 eo_hdr.coh_lu.loh_rcu);
317 kmem_cache_free(echo_object_kmem, eco);
320 static void echo_object_free(const struct lu_env *env, struct lu_object *obj)
322 struct echo_object *eco = cl2echo_obj(lu2cl(obj));
327 lu_object_header_fini(obj->lo_header);
329 OBD_FREE_PRE(eco, sizeof(*eco), "slab-freed");
330 call_rcu(&eco->eo_hdr.coh_lu.loh_rcu, echo_object_free_rcu);
334 static int echo_object_print(const struct lu_env *env, void *cookie,
335 lu_printer_t p, const struct lu_object *o)
337 struct echo_object *obj = cl2echo_obj(lu2cl(o));
339 return (*p)(env, cookie, "echoclient-object@%p", obj);
342 static const struct lu_object_operations echo_lu_obj_ops = {
343 .loo_object_init = echo_object_init,
344 .loo_object_delete = echo_object_delete,
345 .loo_object_release = NULL,
346 .loo_object_free = echo_object_free,
347 .loo_object_print = echo_object_print,
348 .loo_object_invariant = NULL
350 /** @} echo_lu_ops */
352 /** \defgroup echo_lu_dev_ops lu_device operations
354 * Operations for echo lu device.
358 static struct lu_object *echo_object_alloc(const struct lu_env *env,
359 const struct lu_object_header *hdr,
360 struct lu_device *dev)
362 struct echo_object *eco;
363 struct lu_object *obj = NULL;
366 /* we're the top dev. */
367 LASSERT(hdr == NULL);
368 OBD_SLAB_ALLOC_PTR_GFP(eco, echo_object_kmem, GFP_NOFS);
370 struct cl_object_header *hdr = &eco->eo_hdr;
372 obj = &echo_obj2cl(eco)->co_lu;
373 cl_object_header_init(hdr);
374 hdr->coh_page_bufsize = round_up(sizeof(struct cl_page), 8);
376 lu_object_init(obj, &hdr->coh_lu, dev);
377 lu_object_add_top(&hdr->coh_lu, obj);
378 obj->lo_ops = &echo_lu_obj_ops;
383 static const struct lu_device_operations echo_device_lu_ops = {
384 .ldo_object_alloc = echo_object_alloc,
387 /** @} echo_lu_dev_ops */
389 /** \defgroup echo_init Setup and teardown
391 * Init and fini functions for echo client.
395 static int echo_site_init(const struct lu_env *env, struct echo_device *ed)
397 struct cl_site *site = &ed->ed_site_myself;
400 /* initialize site */
401 rc = cl_site_init(site, &ed->ed_cl);
403 CERROR("Cannot initialize site for echo client(%d)\n", rc);
407 rc = lu_site_init_finish(&site->cs_lu);
413 ed->ed_site = &site->cs_lu;
417 static void echo_site_fini(const struct lu_env *env, struct echo_device *ed)
420 if (!ed->ed_next_ismd)
421 lu_site_fini(ed->ed_site);
426 static void *echo_thread_key_init(const struct lu_context *ctx,
427 struct lu_context_key *key)
429 struct echo_thread_info *info;
431 OBD_SLAB_ALLOC_PTR_GFP(info, echo_thread_kmem, GFP_NOFS);
433 info = ERR_PTR(-ENOMEM);
437 static void echo_thread_key_fini(const struct lu_context *ctx,
438 struct lu_context_key *key, void *data)
440 struct echo_thread_info *info = data;
442 OBD_SLAB_FREE_PTR(info, echo_thread_kmem);
445 static struct lu_context_key echo_thread_key = {
446 .lct_tags = LCT_CL_THREAD,
447 .lct_init = echo_thread_key_init,
448 .lct_fini = echo_thread_key_fini,
451 static void *echo_session_key_init(const struct lu_context *ctx,
452 struct lu_context_key *key)
454 struct echo_session_info *session;
456 OBD_SLAB_ALLOC_PTR_GFP(session, echo_session_kmem, GFP_NOFS);
458 session = ERR_PTR(-ENOMEM);
462 static void echo_session_key_fini(const struct lu_context *ctx,
463 struct lu_context_key *key, void *data)
465 struct echo_session_info *session = data;
467 OBD_SLAB_FREE_PTR(session, echo_session_kmem);
470 static struct lu_context_key echo_session_key = {
471 .lct_tags = LCT_SESSION,
472 .lct_init = echo_session_key_init,
473 .lct_fini = echo_session_key_fini,
476 LU_TYPE_INIT_FINI(echo, &echo_thread_key, &echo_session_key);
478 #ifdef HAVE_SERVER_SUPPORT
479 # define ECHO_SEQ_WIDTH 0xffffffff
480 static int echo_fid_init(struct echo_device *ed, char *obd_name,
481 struct seq_server_site *ss)
487 OBD_ALLOC_PTR(ed->ed_cl_seq);
491 OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
493 GOTO(out_free_seq, rc = -ENOMEM);
495 snprintf(prefix, MAX_OBD_NAME + 5, "srv-%s", obd_name);
497 /* Init client side sequence-manager */
498 seq_client_init(ed->ed_cl_seq, NULL,
500 prefix, ss->ss_server_seq);
501 ed->ed_cl_seq->lcs_width = ECHO_SEQ_WIDTH;
502 OBD_FREE(prefix, MAX_OBD_NAME + 5);
507 OBD_FREE_PTR(ed->ed_cl_seq);
508 ed->ed_cl_seq = NULL;
512 static int echo_fid_fini(struct obd_device *obd)
514 struct echo_device *ed = obd2echo_dev(obd);
518 seq_client_fini(ed->ed_cl_seq);
519 OBD_FREE_PTR(ed->ed_cl_seq);
520 ed->ed_cl_seq = NULL;
526 static void echo_ed_los_fini(const struct lu_env *env, struct echo_device *ed)
529 if (ed != NULL && ed->ed_next_ismd && ed->ed_los != NULL) {
530 local_oid_storage_fini(env, ed->ed_los);
536 echo_md_local_file_create(const struct lu_env *env, struct echo_md_device *emd,
537 struct local_oid_storage *los,
538 const struct lu_fid *pfid, const char *name,
539 __u32 mode, struct lu_fid *fid)
541 struct dt_object *parent = NULL;
542 struct dt_object *dto = NULL;
546 LASSERT(!fid_is_zero(pfid));
547 parent = dt_locate(env, emd->emd_bottom, pfid);
548 if (unlikely(IS_ERR(parent)))
549 RETURN(PTR_ERR(parent));
551 /* create local file with @fid */
552 dto = local_file_find_or_create_with_fid(env, emd->emd_bottom, fid,
555 GOTO(out_put, rc = PTR_ERR(dto));
557 *fid = *lu_object_fid(&dto->do_lu);
559 * since stack is not fully set up the local_storage uses own stack
560 * and we should drop its object from cache
562 dt_object_put_nocache(env, dto);
566 dt_object_put(env, parent);
571 echo_md_root_get(const struct lu_env *env, struct echo_md_device *emd,
572 struct echo_device *ed)
578 /* Setup local dirs */
579 fid.f_seq = FID_SEQ_LOCAL_NAME;
582 rc = local_oid_storage_init(env, emd->emd_bottom, &fid, &ed->ed_los);
586 lu_echo_root_fid(&fid);
587 if (echo_md_seq_site(emd)->ss_node_id == 0) {
588 rc = echo_md_local_file_create(env, emd, ed->ed_los,
589 &emd->emd_local_root_fid,
590 echo_md_root_dir_name, S_IFDIR |
591 S_IRUGO | S_IWUSR | S_IXUGO,
594 CERROR("%s: create md echo root fid failed: rc = %d\n",
595 emd2obd_dev(emd)->obd_name, rc);
599 ed->ed_root_fid = fid;
603 echo_ed_los_fini(env, ed);
607 #endif /* HAVE_SERVER_SUPPORT */
609 static struct lu_device *echo_device_alloc(const struct lu_env *env,
610 struct lu_device_type *t,
611 struct lustre_cfg *cfg)
613 struct lu_device *next;
614 struct echo_device *ed;
615 struct cl_device *cd;
616 struct obd_device *obd = NULL; /* to keep compiler happy */
617 struct obd_device *tgt;
618 const char *tgt_type_name;
625 GOTO(out, rc = -ENOMEM);
629 rc = cl_device_init(cd, t);
633 cd->cd_lu_dev.ld_ops = &echo_device_lu_ops;
636 obd = class_name2obd(lustre_cfg_string(cfg, 0));
637 LASSERT(obd != NULL);
638 LASSERT(env != NULL);
640 tgt = class_name2obd(lustre_cfg_string(cfg, 1));
642 CERROR("Can not find tgt device %s\n",
643 lustre_cfg_string(cfg, 1));
644 GOTO(out, rc = -ENODEV);
647 next = tgt->obd_lu_dev;
649 if (strcmp(tgt->obd_type->typ_name, LUSTRE_MDT_NAME) == 0) {
650 ed->ed_next_ismd = 1;
651 } else if (strcmp(tgt->obd_type->typ_name, LUSTRE_OST_NAME) == 0 ||
652 strcmp(tgt->obd_type->typ_name, LUSTRE_OSC_NAME) == 0) {
653 ed->ed_next_ismd = 0;
654 rc = echo_site_init(env, ed);
658 GOTO(out, rc = -EINVAL);
663 rc = echo_client_setup(env, obd, cfg);
667 ed->ed_ec = &obd->u.echo_client;
670 if (ed->ed_next_ismd) {
671 #ifdef HAVE_SERVER_SUPPORT
672 /* Suppose to connect to some Metadata layer */
673 struct lu_site *ls = NULL;
674 struct lu_device *ld = NULL;
675 struct md_device *md = NULL;
676 struct echo_md_device *emd = NULL;
680 CERROR("%s is not lu device type!\n",
681 lustre_cfg_string(cfg, 1));
682 GOTO(out, rc = -EINVAL);
685 tgt_type_name = lustre_cfg_string(cfg, 2);
686 if (!tgt_type_name) {
687 CERROR("%s no type name for echo %s setup\n",
688 lustre_cfg_string(cfg, 1),
689 tgt->obd_type->typ_name);
690 GOTO(out, rc = -EINVAL);
695 spin_lock(&ls->ls_ld_lock);
696 list_for_each_entry(ld, &ls->ls_ld_linkage, ld_linkage) {
697 if (strcmp(ld->ld_type->ldt_name, tgt_type_name) == 0) {
702 spin_unlock(&ls->ls_ld_lock);
705 CERROR("%s is not lu device type!\n",
706 lustre_cfg_string(cfg, 1));
707 GOTO(out, rc = -EINVAL);
711 /* For MD echo client, it will use the site in MDS stack */
713 ed->ed_cl.cd_lu_dev.ld_site = ls;
714 rc = echo_fid_init(ed, obd->obd_name, lu_site2seq(ls));
716 CERROR("echo fid init error %d\n", rc);
720 md = lu2md_dev(next);
721 emd = lu2emd_dev(&md->md_lu_dev);
722 rc = echo_md_root_get(env, emd, ed);
724 CERROR("%s: get root error: rc = %d\n",
725 emd2obd_dev(emd)->obd_name, rc);
728 #else /* !HAVE_SERVER_SUPPORT */
730 "Local operations are NOT supported on client side. Only remote operations are supported. Metadata client must be run on server side.\n");
731 GOTO(out, rc = -EOPNOTSUPP);
732 #endif /* HAVE_SERVER_SUPPORT */
735 * if echo client is to be stacked upon ost device, the next is
736 * NULL since ost is not a clio device so far
738 if (next != NULL && !lu_device_is_cl(next))
741 tgt_type_name = tgt->obd_type->typ_name;
743 LASSERT(next != NULL);
745 GOTO(out, rc = -EBUSY);
747 next->ld_site = ed->ed_site;
748 rc = next->ld_type->ldt_ops->ldto_device_init(env, next,
749 next->ld_type->ldt_name,
754 LASSERT(strcmp(tgt_type_name, LUSTRE_OST_NAME) == 0);
759 RETURN(&cd->cd_lu_dev);
765 rc2 = echo_client_cleanup(obd);
767 CERROR("Cleanup obd device %s error(%d)\n",
773 echo_site_fini(env, ed);
776 cl_device_fini(&ed->ed_cl);
788 static int echo_device_init(const struct lu_env *env, struct lu_device *d,
789 const char *name, struct lu_device *next)
795 static struct lu_device *echo_device_fini(const struct lu_env *env,
798 struct echo_device *ed = cl2echo_dev(lu2cl_dev(d));
799 struct lu_device *next = ed->ed_next;
801 while (next && !ed->ed_next_ismd)
802 next = next->ld_type->ldt_ops->ldto_device_fini(env, next);
806 static struct lu_device *echo_device_free(const struct lu_env *env,
809 struct echo_device *ed = cl2echo_dev(lu2cl_dev(d));
810 struct echo_client_obd *ec = ed->ed_ec;
811 struct echo_object *eco;
812 struct lu_device *next = ed->ed_next;
814 CDEBUG(D_INFO, "echo device:%p is going to be freed, next = %p\n",
817 lu_site_purge(env, ed->ed_site, -1);
820 * check if there are objects still alive.
821 * It shouldn't have any object because lu_site_purge would cleanup
822 * all of cached objects. Anyway, probably the echo device is being
823 * parallelly accessed.
825 spin_lock(&ec->ec_lock);
826 list_for_each_entry(eco, &ec->ec_objects, eo_obj_chain)
828 spin_unlock(&ec->ec_lock);
831 lu_site_purge(env, ed->ed_site, -1);
834 "Waiting for the reference of echo object to be dropped\n");
836 /* Wait for the last reference to be dropped. */
837 spin_lock(&ec->ec_lock);
838 while (!list_empty(&ec->ec_objects)) {
839 spin_unlock(&ec->ec_lock);
841 "echo_client still has objects at cleanup time, wait for 1 second\n");
842 schedule_timeout_uninterruptible(cfs_time_seconds(1));
843 lu_site_purge(env, ed->ed_site, -1);
844 spin_lock(&ec->ec_lock);
846 spin_unlock(&ec->ec_lock);
848 LASSERT(list_empty(&ec->ec_locks));
850 CDEBUG(D_INFO, "No object exists, exiting...\n");
852 echo_client_cleanup(d->ld_obd);
853 #ifdef HAVE_SERVER_SUPPORT
854 echo_fid_fini(d->ld_obd);
855 echo_ed_los_fini(env, ed);
857 while (next && !ed->ed_next_ismd)
858 next = next->ld_type->ldt_ops->ldto_device_free(env, next);
860 LASSERT(ed->ed_site == d->ld_site);
861 echo_site_fini(env, ed);
862 cl_device_fini(&ed->ed_cl);
865 cl_env_cache_purge(~0);
870 static const struct lu_device_type_operations echo_device_type_ops = {
871 .ldto_init = echo_type_init,
872 .ldto_fini = echo_type_fini,
874 .ldto_start = echo_type_start,
875 .ldto_stop = echo_type_stop,
877 .ldto_device_alloc = echo_device_alloc,
878 .ldto_device_free = echo_device_free,
879 .ldto_device_init = echo_device_init,
880 .ldto_device_fini = echo_device_fini
883 static struct lu_device_type echo_device_type = {
884 .ldt_tags = LU_DEVICE_CL,
885 .ldt_name = LUSTRE_ECHO_CLIENT_NAME,
886 .ldt_ops = &echo_device_type_ops,
887 .ldt_ctx_tags = LCT_CL_THREAD | LCT_MD_THREAD | LCT_DT_THREAD,
891 /** \defgroup echo_exports Exported operations
893 * exporting functions to echo client
898 /* Interfaces to echo client obd device */
899 static struct echo_object *
900 cl_echo_object_find(struct echo_device *d, const struct ost_id *oi)
903 struct echo_thread_info *info;
904 struct echo_object_conf *conf;
905 struct echo_object *eco;
906 struct cl_object *obj;
907 struct lov_oinfo *oinfo = NULL;
913 LASSERTF(ostid_id(oi) != 0, DOSTID"\n", POSTID(oi));
914 LASSERTF(ostid_seq(oi) == FID_SEQ_ECHO, DOSTID"\n", POSTID(oi));
916 /* Never return an object if the obd is to be freed. */
917 if (echo_dev2cl(d)->cd_lu_dev.ld_obd->obd_stopping)
918 RETURN(ERR_PTR(-ENODEV));
920 env = cl_env_get(&refcheck);
924 info = echo_env_info(env);
925 conf = &info->eti_conf;
927 OBD_ALLOC_PTR(oinfo);
929 GOTO(out, eco = ERR_PTR(-ENOMEM));
932 conf->eoc_cl.u.coc_oinfo = oinfo;
936 * If echo_object_init() is successful then ownership of oinfo
937 * is transferred to the object.
939 conf->eoc_oinfo = &oinfo;
941 fid = &info->eti_fid;
942 rc = ostid_to_fid(fid, oi, 0);
944 GOTO(out, eco = ERR_PTR(rc));
947 * In the function below, .hs_keycmp resolves to
948 * lu_obj_hop_keycmp()
950 /* coverity[overrun-buffer-val] */
951 obj = cl_object_find(env, echo_dev2cl(d), fid, &conf->eoc_cl);
953 GOTO(out, eco = (void *)obj);
955 eco = cl2echo_obj(obj);
956 if (eco->eo_deleted) {
957 cl_object_put(env, obj);
958 eco = ERR_PTR(-EAGAIN);
965 cl_env_put(env, &refcheck);
969 static int cl_echo_object_put(struct echo_object *eco)
972 struct cl_object *obj = echo_obj2cl(eco);
976 env = cl_env_get(&refcheck);
978 RETURN(PTR_ERR(env));
980 /* an external function to kill an object? */
981 if (eco->eo_deleted) {
982 struct lu_object_header *loh = obj->co_lu.lo_header;
984 LASSERT(&eco->eo_hdr == luh2coh(loh));
985 set_bit(LU_OBJECT_HEARD_BANSHEE, &loh->loh_flags);
988 cl_object_put(env, obj);
989 cl_env_put(env, &refcheck);
993 /** @} echo_exports */
995 static u64 last_object_id;
997 #ifdef HAVE_SERVER_SUPPORT
998 static void echo_md_build_name(struct lu_name *lname, char *name,
1001 snprintf(name, ETI_NAME_LEN, "%llu", id);
1002 lname->ln_name = name;
1003 lname->ln_namelen = strlen(name);
1006 /* similar to mdt_attr_get_complex */
1007 static int echo_big_lmm_get(const struct lu_env *env, struct md_object *o,
1010 struct echo_thread_info *info = echo_env_info(env);
1015 LASSERT(ma->ma_lmm_size > 0);
1017 LASSERT(ma->ma_need & (MA_LOV | MA_LMV));
1018 if (ma->ma_need & MA_LOV)
1019 rc = mo_xattr_get(env, o, &LU_BUF_NULL, XATTR_NAME_LOV);
1021 rc = mo_xattr_get(env, o, &LU_BUF_NULL, XATTR_NAME_LMV);
1026 /* big_lmm may need to be grown */
1027 if (info->eti_big_lmmsize < rc) {
1028 int size = size_roundup_power2(rc);
1030 if (info->eti_big_lmmsize > 0) {
1031 /* free old buffer */
1032 LASSERT(info->eti_big_lmm);
1033 OBD_FREE_LARGE(info->eti_big_lmm,
1034 info->eti_big_lmmsize);
1035 info->eti_big_lmm = NULL;
1036 info->eti_big_lmmsize = 0;
1039 OBD_ALLOC_LARGE(info->eti_big_lmm, size);
1040 if (!info->eti_big_lmm)
1042 info->eti_big_lmmsize = size;
1044 LASSERT(info->eti_big_lmmsize >= rc);
1046 info->eti_buf.lb_buf = info->eti_big_lmm;
1047 info->eti_buf.lb_len = info->eti_big_lmmsize;
1048 if (ma->ma_need & MA_LOV)
1049 rc = mo_xattr_get(env, o, &info->eti_buf, XATTR_NAME_LOV);
1051 rc = mo_xattr_get(env, o, &info->eti_buf, XATTR_NAME_LMV);
1055 if (ma->ma_need & MA_LOV)
1056 ma->ma_valid |= MA_LOV;
1058 ma->ma_valid |= MA_LMV;
1060 ma->ma_lmm = info->eti_big_lmm;
1061 ma->ma_lmm_size = rc;
1066 static int echo_attr_get_complex(const struct lu_env *env,
1067 struct md_object *next,
1070 struct echo_thread_info *info = echo_env_info(env);
1071 struct lu_buf *buf = &info->eti_buf;
1072 umode_t mode = lu_object_attr(&next->mo_lu);
1079 if (ma->ma_need & MA_INODE) {
1080 rc = mo_attr_get(env, next, ma);
1083 ma->ma_valid |= MA_INODE;
1086 if ((ma->ma_need & MA_LOV) && (S_ISREG(mode) || S_ISDIR(mode))) {
1087 LASSERT(ma->ma_lmm_size > 0);
1088 buf->lb_buf = ma->ma_lmm;
1089 buf->lb_len = ma->ma_lmm_size;
1090 rc2 = mo_xattr_get(env, next, buf, XATTR_NAME_LOV);
1092 ma->ma_lmm_size = rc2;
1093 ma->ma_valid |= MA_LOV;
1094 } else if (rc2 == -ENODATA) {
1096 ma->ma_lmm_size = 0;
1097 } else if (rc2 == -ERANGE) {
1098 rc2 = echo_big_lmm_get(env, next, ma);
1100 GOTO(out, rc = rc2);
1102 GOTO(out, rc = rc2);
1106 if ((ma->ma_need & MA_LMV) && S_ISDIR(mode)) {
1107 LASSERT(ma->ma_lmm_size > 0);
1108 buf->lb_buf = ma->ma_lmm;
1109 buf->lb_len = ma->ma_lmm_size;
1110 rc2 = mo_xattr_get(env, next, buf, XATTR_NAME_LMV);
1112 ma->ma_lmm_size = rc2;
1113 ma->ma_valid |= MA_LMV;
1114 } else if (rc2 == -ENODATA) {
1116 ma->ma_lmm_size = 0;
1117 } else if (rc2 == -ERANGE) {
1118 rc2 = echo_big_lmm_get(env, next, ma);
1120 GOTO(out, rc = rc2);
1122 GOTO(out, rc = rc2);
1126 #ifdef CONFIG_LUSTRE_FS_POSIX_ACL
1127 if ((ma->ma_need & MA_ACL_DEF) && S_ISDIR(mode)) {
1128 buf->lb_buf = ma->ma_acl;
1129 buf->lb_len = ma->ma_acl_size;
1130 rc2 = mo_xattr_get(env, next, buf, XATTR_NAME_ACL_DEFAULT);
1132 ma->ma_acl_size = rc2;
1133 ma->ma_valid |= MA_ACL_DEF;
1134 } else if (rc2 == -ENODATA) {
1136 ma->ma_acl_size = 0;
1138 GOTO(out, rc = rc2);
1143 CDEBUG(D_INODE, "after getattr rc = %d, ma_valid = %#llx ma_lmm=%p\n",
1144 rc, ma->ma_valid, ma->ma_lmm);
1149 echo_md_create_internal(const struct lu_env *env, struct echo_device *ed,
1150 struct md_object *parent, struct lu_fid *fid,
1151 struct lu_name *lname, struct md_op_spec *spec,
1154 struct lu_object *ec_child, *child;
1155 struct lu_device *ld = ed->ed_next;
1156 struct echo_thread_info *info = echo_env_info(env);
1157 struct lu_fid *fid2 = &info->eti_fid2;
1158 struct lu_object_conf conf = { .loc_flags = LOC_F_NEW };
1163 rc = mdo_lookup(env, parent, lname, fid2, spec);
1166 else if (rc != -ENOENT)
1169 ec_child = lu_object_find_at(env, &ed->ed_cl.cd_lu_dev,
1171 if (IS_ERR(ec_child)) {
1172 CERROR("Can not find the child "DFID": rc = %ld\n", PFID(fid),
1174 RETURN(PTR_ERR(ec_child));
1177 child = lu_object_locate(ec_child->lo_header, ld->ld_type);
1179 CERROR("Can not locate the child "DFID"\n", PFID(fid));
1180 GOTO(out_put, rc = -EINVAL);
1183 CDEBUG(D_RPCTRACE, "Start creating object "DFID" %s %p\n",
1184 PFID(lu_object_fid(&parent->mo_lu)), lname->ln_name, parent);
1187 * Do not perform lookup sanity check. We know that name does not exist.
1189 spec->sp_cr_lookup = 0;
1190 rc = mdo_create(env, parent, lname, lu2md(child), spec, ma);
1192 CERROR("Can not create child "DFID": rc = %d\n", PFID(fid), rc);
1195 CDEBUG(D_RPCTRACE, "End creating object "DFID" %s %p rc = %d\n",
1196 PFID(lu_object_fid(&parent->mo_lu)), lname->ln_name, parent, rc);
1199 lu_object_put(env, ec_child);
1203 static int echo_set_lmm_size(const struct lu_env *env, struct lu_device *ld,
1206 struct echo_thread_info *info = echo_env_info(env);
1208 if (strcmp(ld->ld_type->ldt_name, LUSTRE_MDD_NAME)) {
1209 ma->ma_lmm = (void *)&info->eti_lmm;
1210 ma->ma_lmm_size = sizeof(info->eti_lmm);
1212 LASSERT(info->eti_big_lmmsize);
1213 ma->ma_lmm = info->eti_big_lmm;
1214 ma->ma_lmm_size = info->eti_big_lmmsize;
1221 echo_md_dir_stripe_choose(const struct lu_env *env, struct echo_device *ed,
1222 struct lu_object *obj, const char *name,
1223 unsigned int namelen, __u64 id,
1224 struct lu_object **new_parent)
1226 struct echo_thread_info *info = echo_env_info(env);
1227 struct md_attr *ma = &info->eti_ma;
1228 struct lmv_mds_md_v1 *lmv;
1229 struct lu_device *ld = ed->ed_next;
1231 struct lu_name tmp_ln_name;
1232 struct lu_fid stripe_fid;
1233 struct lu_object *stripe_obj;
1236 LASSERT(obj != NULL);
1237 LASSERT(S_ISDIR(obj->lo_header->loh_attr));
1239 memset(ma, 0, sizeof(*ma));
1240 echo_set_lmm_size(env, ld, ma);
1241 ma->ma_need = MA_LMV;
1242 rc = echo_attr_get_complex(env, lu2md(obj), ma);
1244 CERROR("Can not getattr child "DFID": rc = %d\n",
1245 PFID(lu_object_fid(obj)), rc);
1249 if (!(ma->ma_valid & MA_LMV)) {
1254 lmv = (struct lmv_mds_md_v1 *)ma->ma_lmm;
1255 if (!lmv_is_sane(lmv)) {
1257 CERROR("Invalid mds md magic %x "DFID": rc = %d\n",
1258 le32_to_cpu(lmv->lmv_magic), PFID(lu_object_fid(obj)),
1264 tmp_ln_name.ln_name = name;
1265 tmp_ln_name.ln_namelen = namelen;
1268 echo_md_build_name(&tmp_ln_name, info->eti_name, id);
1271 idx = lmv_name_to_stripe_index(lmv, tmp_ln_name.ln_name,
1272 tmp_ln_name.ln_namelen);
1274 LASSERT(idx < le32_to_cpu(lmv->lmv_stripe_count));
1275 fid_le_to_cpu(&stripe_fid, &lmv->lmv_stripe_fids[idx]);
1277 stripe_obj = lu_object_find_at(env, &ed->ed_cl.cd_lu_dev, &stripe_fid,
1279 if (IS_ERR(stripe_obj)) {
1280 rc = PTR_ERR(stripe_obj);
1281 CERROR("Can not find the parent "DFID": rc = %d\n",
1282 PFID(&stripe_fid), rc);
1286 *new_parent = lu_object_locate(stripe_obj->lo_header, ld->ld_type);
1288 lu_object_put(env, stripe_obj);
1295 static int echo_create_md_object(const struct lu_env *env,
1296 struct echo_device *ed,
1297 struct lu_object *ec_parent,
1299 char *name, int namelen,
1300 __u64 id, __u32 mode, int count,
1301 int stripe_count, int stripe_offset)
1303 struct lu_object *parent;
1304 struct lu_object *new_parent;
1305 struct echo_thread_info *info = echo_env_info(env);
1306 struct lu_name *lname = &info->eti_lname;
1307 struct md_op_spec *spec = &info->eti_spec;
1308 struct md_attr *ma = &info->eti_ma;
1309 struct lu_device *ld = ed->ed_next;
1317 parent = lu_object_locate(ec_parent->lo_header, ld->ld_type);
1321 rc = echo_md_dir_stripe_choose(env, ed, parent, name, namelen,
1326 LASSERT(new_parent != NULL);
1327 memset(ma, 0, sizeof(*ma));
1328 memset(spec, 0, sizeof(*spec));
1329 echo_set_lmm_size(env, ld, ma);
1330 if (stripe_count != 0) {
1331 spec->sp_cr_flags |= MDS_FMODE_WRITE;
1332 if (stripe_count != -1) {
1333 if (S_ISDIR(mode)) {
1334 struct lmv_user_md *lmu;
1336 lmu = (struct lmv_user_md *)&info->eti_lum;
1337 lmu->lum_magic = LMV_USER_MAGIC;
1338 lmu->lum_stripe_offset = stripe_offset;
1339 lmu->lum_stripe_count = stripe_count;
1340 lmu->lum_hash_type = LMV_HASH_TYPE_FNV_1A_64;
1341 spec->u.sp_ea.eadata = lmu;
1342 spec->u.sp_ea.eadatalen = sizeof(*lmu);
1344 struct lov_user_md_v3 *lum = &info->eti_lum;
1346 lum->lmm_magic = LOV_USER_MAGIC_V3;
1347 lum->lmm_stripe_count = stripe_count;
1348 lum->lmm_stripe_offset = stripe_offset;
1349 lum->lmm_pattern = LOV_PATTERN_NONE;
1350 spec->u.sp_ea.eadata = lum;
1351 spec->u.sp_ea.eadatalen = sizeof(*lum);
1353 spec->sp_cr_flags |= MDS_OPEN_HAS_EA;
1357 ma->ma_attr.la_mode = mode;
1358 ma->ma_attr.la_valid = LA_CTIME | LA_MODE;
1359 ma->ma_attr.la_ctime = ktime_get_real_seconds();
1362 lname->ln_name = name;
1363 lname->ln_namelen = namelen;
1364 /* If name is specified, only create one object by name */
1365 rc = echo_md_create_internal(env, ed, lu2md(new_parent), fid,
1370 /* Create multiple object sequenced by id */
1371 for (i = 0; i < count; i++) {
1372 char *tmp_name = info->eti_name;
1374 echo_md_build_name(lname, tmp_name, id);
1376 rc = echo_md_create_internal(env, ed, lu2md(new_parent),
1377 fid, lname, spec, ma);
1379 CERROR("Can not create child %s: rc = %d\n", tmp_name,
1388 if (new_parent != parent)
1389 lu_object_put(env, new_parent);
1394 static struct lu_object *echo_md_lookup(const struct lu_env *env,
1395 struct echo_device *ed,
1396 struct md_object *parent,
1397 struct lu_name *lname)
1399 struct echo_thread_info *info = echo_env_info(env);
1400 struct lu_fid *fid = &info->eti_fid;
1401 struct lu_object *child;
1405 CDEBUG(D_INFO, "lookup %s in parent "DFID" %p\n", lname->ln_name,
1408 rc = mdo_lookup(env, parent, lname, fid, NULL);
1410 CERROR("lookup %s: rc = %d\n", lname->ln_name, rc);
1411 RETURN(ERR_PTR(rc));
1415 * In the function below, .hs_keycmp resolves to
1416 * lu_obj_hop_keycmp()
1418 /* coverity[overrun-buffer-val] */
1419 child = lu_object_find_at(env, &ed->ed_cl.cd_lu_dev, fid, NULL);
1424 static int echo_setattr_object(const struct lu_env *env,
1425 struct echo_device *ed,
1426 struct lu_object *ec_parent,
1427 __u64 id, int count)
1429 struct lu_object *parent;
1430 struct lu_object *new_parent;
1431 struct echo_thread_info *info = echo_env_info(env);
1432 struct lu_name *lname = &info->eti_lname;
1433 char *name = info->eti_name;
1434 struct lu_device *ld = ed->ed_next;
1435 struct lu_buf *buf = &info->eti_buf;
1443 parent = lu_object_locate(ec_parent->lo_header, ld->ld_type);
1447 rc = echo_md_dir_stripe_choose(env, ed, parent, NULL, 0, id,
1452 for (i = 0; i < count; i++) {
1453 struct lu_object *ec_child, *child;
1455 echo_md_build_name(lname, name, id);
1457 ec_child = echo_md_lookup(env, ed, lu2md(new_parent), lname);
1458 if (IS_ERR(ec_child)) {
1459 rc = PTR_ERR(ec_child);
1460 CERROR("Can't find child %s: rc = %d\n",
1461 lname->ln_name, rc);
1465 child = lu_object_locate(ec_child->lo_header, ld->ld_type);
1467 CERROR("Can not locate the child %s\n", lname->ln_name);
1468 lu_object_put(env, ec_child);
1473 CDEBUG(D_RPCTRACE, "Start setattr object "DFID"\n",
1474 PFID(lu_object_fid(child)));
1476 buf->lb_buf = info->eti_xattr_buf;
1477 buf->lb_len = sizeof(info->eti_xattr_buf);
1479 sprintf(name, "%s.test1", XATTR_USER_PREFIX);
1480 rc = mo_xattr_set(env, lu2md(child), buf, name,
1483 CERROR("Can not setattr child "DFID": rc = %d\n",
1484 PFID(lu_object_fid(child)), rc);
1485 lu_object_put(env, ec_child);
1488 CDEBUG(D_RPCTRACE, "End setattr object "DFID"\n",
1489 PFID(lu_object_fid(child)));
1491 lu_object_put(env, ec_child);
1494 if (new_parent != parent)
1495 lu_object_put(env, new_parent);
1500 static int echo_getattr_object(const struct lu_env *env,
1501 struct echo_device *ed,
1502 struct lu_object *ec_parent,
1503 __u64 id, int count)
1505 struct lu_object *parent;
1506 struct lu_object *new_parent;
1507 struct echo_thread_info *info = echo_env_info(env);
1508 struct lu_name *lname = &info->eti_lname;
1509 char *name = info->eti_name;
1510 struct md_attr *ma = &info->eti_ma;
1511 struct lu_device *ld = ed->ed_next;
1519 parent = lu_object_locate(ec_parent->lo_header, ld->ld_type);
1523 rc = echo_md_dir_stripe_choose(env, ed, parent, NULL, 0, id,
1528 memset(ma, 0, sizeof(*ma));
1529 ma->ma_need |= MA_INODE | MA_LOV | MA_PFID | MA_HSM | MA_ACL_DEF;
1530 ma->ma_acl = info->eti_xattr_buf;
1531 ma->ma_acl_size = sizeof(info->eti_xattr_buf);
1533 for (i = 0; i < count; i++) {
1534 struct lu_object *ec_child, *child;
1537 echo_md_build_name(lname, name, id);
1538 echo_set_lmm_size(env, ld, ma);
1540 ec_child = echo_md_lookup(env, ed, lu2md(new_parent), lname);
1541 if (IS_ERR(ec_child)) {
1542 CERROR("Can't find child %s: rc = %ld\n",
1543 lname->ln_name, PTR_ERR(ec_child));
1544 RETURN(PTR_ERR(ec_child));
1547 child = lu_object_locate(ec_child->lo_header, ld->ld_type);
1549 CERROR("Can not locate the child %s\n", lname->ln_name);
1550 lu_object_put(env, ec_child);
1554 CDEBUG(D_RPCTRACE, "Start getattr object "DFID"\n",
1555 PFID(lu_object_fid(child)));
1556 rc = echo_attr_get_complex(env, lu2md(child), ma);
1558 CERROR("Can not getattr child "DFID": rc = %d\n",
1559 PFID(lu_object_fid(child)), rc);
1560 lu_object_put(env, ec_child);
1563 CDEBUG(D_RPCTRACE, "End getattr object "DFID"\n",
1564 PFID(lu_object_fid(child)));
1566 lu_object_put(env, ec_child);
1569 if (new_parent != parent)
1570 lu_object_put(env, new_parent);
1575 static int echo_lookup_object(const struct lu_env *env,
1576 struct echo_device *ed,
1577 struct lu_object *ec_parent,
1578 __u64 id, int count)
1580 struct lu_object *parent;
1581 struct lu_object *new_parent;
1582 struct echo_thread_info *info = echo_env_info(env);
1583 struct lu_name *lname = &info->eti_lname;
1584 char *name = info->eti_name;
1585 struct lu_fid *fid = &info->eti_fid;
1586 struct lu_device *ld = ed->ed_next;
1592 parent = lu_object_locate(ec_parent->lo_header, ld->ld_type);
1596 rc = echo_md_dir_stripe_choose(env, ed, parent, NULL, 0, id,
1601 /*prepare the requests*/
1602 for (i = 0; i < count; i++) {
1603 echo_md_build_name(lname, name, id);
1605 CDEBUG(D_RPCTRACE, "Start lookup object "DFID" %s %p\n",
1606 PFID(lu_object_fid(new_parent)), lname->ln_name,
1609 rc = mdo_lookup(env, lu2md(new_parent), lname, fid, NULL);
1611 CERROR("Can not lookup child %s: rc = %d\n", name, rc);
1615 CDEBUG(D_RPCTRACE, "End lookup object "DFID" %s %p\n",
1616 PFID(lu_object_fid(new_parent)), lname->ln_name,
1622 if (new_parent != parent)
1623 lu_object_put(env, new_parent);
1628 static int echo_md_destroy_internal(const struct lu_env *env,
1629 struct echo_device *ed,
1630 struct md_object *parent,
1631 struct lu_name *lname,
1634 struct lu_device *ld = ed->ed_next;
1635 struct lu_object *ec_child;
1636 struct lu_object *child;
1641 ec_child = echo_md_lookup(env, ed, parent, lname);
1642 if (IS_ERR(ec_child)) {
1643 CERROR("Can't find child %s: rc = %ld\n", lname->ln_name,
1645 RETURN(PTR_ERR(ec_child));
1648 child = lu_object_locate(ec_child->lo_header, ld->ld_type);
1650 CERROR("Can not locate the child %s\n", lname->ln_name);
1651 GOTO(out_put, rc = -EINVAL);
1654 if (lu_object_remote(child)) {
1655 CERROR("Can not destroy remote object %s: rc = %d\n",
1656 lname->ln_name, -EPERM);
1657 GOTO(out_put, rc = -EPERM);
1659 CDEBUG(D_RPCTRACE, "Start destroy object "DFID" %s %p\n",
1660 PFID(lu_object_fid(&parent->mo_lu)), lname->ln_name, parent);
1662 rc = mdo_unlink(env, parent, lu2md(child), lname, ma, 0);
1664 CERROR("Can not unlink child %s: rc = %d\n",
1665 lname->ln_name, rc);
1668 CDEBUG(D_RPCTRACE, "End destroy object "DFID" %s %p\n",
1669 PFID(lu_object_fid(&parent->mo_lu)), lname->ln_name, parent);
1671 lu_object_put(env, ec_child);
1675 static int echo_destroy_object(const struct lu_env *env,
1676 struct echo_device *ed,
1677 struct lu_object *ec_parent,
1678 char *name, int namelen,
1679 __u64 id, __u32 mode,
1682 struct echo_thread_info *info = echo_env_info(env);
1683 struct lu_name *lname = &info->eti_lname;
1684 struct md_attr *ma = &info->eti_ma;
1685 struct lu_device *ld = ed->ed_next;
1686 struct lu_object *parent;
1687 struct lu_object *new_parent;
1692 parent = lu_object_locate(ec_parent->lo_header, ld->ld_type);
1696 rc = echo_md_dir_stripe_choose(env, ed, parent, name, namelen,
1701 memset(ma, 0, sizeof(*ma));
1702 ma->ma_attr.la_mode = mode;
1703 ma->ma_attr.la_valid = LA_CTIME;
1704 ma->ma_attr.la_ctime = ktime_get_real_seconds();
1705 ma->ma_need = MA_INODE;
1709 lname->ln_name = name;
1710 lname->ln_namelen = namelen;
1711 rc = echo_md_destroy_internal(env, ed, lu2md(new_parent), lname,
1716 /*prepare the requests*/
1717 for (i = 0; i < count; i++) {
1718 char *tmp_name = info->eti_name;
1721 echo_md_build_name(lname, tmp_name, id);
1723 rc = echo_md_destroy_internal(env, ed, lu2md(new_parent), lname,
1726 CERROR("Can not unlink child %s: rc = %d\n", name, rc);
1733 if (new_parent != parent)
1734 lu_object_put(env, new_parent);
1739 static struct lu_object *echo_resolve_path(const struct lu_env *env,
1740 struct echo_device *ed, char *path,
1743 struct lu_device *ld = ed->ed_next;
1744 struct echo_thread_info *info = echo_env_info(env);
1745 struct lu_fid *fid = &info->eti_fid;
1746 struct lu_name *lname = &info->eti_lname;
1747 struct lu_object *parent = NULL;
1748 struct lu_object *child = NULL;
1752 *fid = ed->ed_root_fid;
1755 * In the function below, .hs_keycmp resolves to
1756 * lu_obj_hop_keycmp()
1758 /* coverity[overrun-buffer-val] */
1759 parent = lu_object_find_at(env, &ed->ed_cl.cd_lu_dev, fid, NULL);
1760 if (IS_ERR(parent)) {
1761 CERROR("Can not find the parent "DFID": rc = %ld\n",
1762 PFID(fid), PTR_ERR(parent));
1767 struct lu_object *ld_parent;
1770 e = strsep(&path, "/");
1775 if (!path || path[0] == '\0')
1781 lname->ln_namelen = strlen(e);
1783 ld_parent = lu_object_locate(parent->lo_header, ld->ld_type);
1785 lu_object_put(env, parent);
1790 child = echo_md_lookup(env, ed, lu2md(ld_parent), lname);
1791 lu_object_put(env, parent);
1792 if (IS_ERR(child)) {
1793 rc = (int)PTR_ERR(child);
1794 CERROR("lookup %s under parent "DFID": rc = %d\n",
1795 lname->ln_name, PFID(lu_object_fid(ld_parent)),
1802 RETURN(ERR_PTR(rc));
1807 static void echo_ucred_init(struct lu_env *env)
1809 struct lu_ucred *ucred = lu_ucred(env);
1810 kernel_cap_t kcap = current_cap();
1812 ucred->uc_valid = UCRED_INVALID;
1814 ucred->uc_suppgids[0] = -1;
1815 ucred->uc_suppgids[1] = -1;
1817 ucred->uc_uid = ucred->uc_o_uid =
1818 from_kuid(&init_user_ns, current_uid());
1819 ucred->uc_gid = ucred->uc_o_gid =
1820 from_kgid(&init_user_ns, current_gid());
1821 ucred->uc_fsuid = ucred->uc_o_fsuid =
1822 from_kuid(&init_user_ns, current_fsuid());
1823 ucred->uc_fsgid = ucred->uc_o_fsgid =
1824 from_kgid(&init_user_ns, current_fsgid());
1825 ucred->uc_cap = current_cap();
1827 /* remove fs privilege for non-root user. */
1828 if (ucred->uc_fsuid) {
1829 kcap = cap_drop_nfsd_set(kcap);
1830 kcap = cap_drop_fs_set(kcap);
1832 ucred->uc_cap = kcap;
1833 ucred->uc_valid = UCRED_NEW;
1834 /* do not let rbac interfere with obdecho */
1835 ucred->uc_rbac_file_perms = 1;
1836 ucred->uc_rbac_dne_ops = 1;
1837 ucred->uc_rbac_quota_ops = 1;
1838 ucred->uc_rbac_byfid_ops = 1;
1839 ucred->uc_rbac_chlg_ops = 1;
1840 ucred->uc_rbac_fscrypt_admin = 1;
1843 static void echo_ucred_fini(struct lu_env *env)
1845 struct lu_ucred *ucred = lu_ucred(env);
1847 ucred->uc_valid = UCRED_INIT;
1850 static int echo_md_handler(struct echo_device *ed, int command,
1851 char *path, int path_len, __u64 id, int count,
1852 struct obd_ioctl_data *data)
1854 struct echo_thread_info *info;
1855 struct lu_device *ld = ed->ed_next;
1858 struct lu_object *parent;
1860 int namelen = data->ioc_plen2;
1865 CERROR("MD echo client is not being initialized properly\n");
1869 if (strcmp(ld->ld_type->ldt_name, LUSTRE_MDD_NAME)) {
1870 CERROR("Only support MDD layer right now!\n");
1874 env = cl_env_get(&refcheck);
1876 RETURN(PTR_ERR(env));
1878 rc = lu_env_refill_by_tags(env, ECHO_MD_CTX_TAG, ECHO_SES_TAG);
1882 /* init big_lmm buffer */
1883 info = echo_env_info(env);
1884 LASSERT(info->eti_big_lmm == NULL);
1885 OBD_ALLOC_LARGE(info->eti_big_lmm, MIN_MD_SIZE);
1886 if (!info->eti_big_lmm)
1887 GOTO(out_env, rc = -ENOMEM);
1888 info->eti_big_lmmsize = MIN_MD_SIZE;
1890 parent = echo_resolve_path(env, ed, path, path_len);
1891 if (IS_ERR(parent)) {
1892 CERROR("Can not resolve the path %s: rc = %ld\n", path,
1894 GOTO(out_free, rc = PTR_ERR(parent));
1898 OBD_ALLOC(name, namelen + 1);
1900 GOTO(out_put, rc = -ENOMEM);
1901 if (copy_from_user(name, data->ioc_pbuf2, namelen))
1902 GOTO(out_name, rc = -EFAULT);
1905 echo_ucred_init(env);
1908 case ECHO_MD_CREATE:
1909 case ECHO_MD_MKDIR: {
1910 struct echo_thread_info *info = echo_env_info(env);
1911 __u32 mode = data->ioc_obdo2.o_mode;
1912 struct lu_fid *fid = &info->eti_fid;
1913 int stripe_count = (int)data->ioc_obdo2.o_misc;
1914 int stripe_index = (int)data->ioc_obdo2.o_stripe_idx;
1916 rc = ostid_to_fid(fid, &data->ioc_obdo1.o_oi, 0);
1921 * In the function below, .hs_keycmp resolves to
1922 * lu_obj_hop_keycmp()
1924 /* coverity[overrun-buffer-val] */
1925 rc = echo_create_md_object(env, ed, parent, fid, name, namelen,
1926 id, mode, count, stripe_count,
1930 case ECHO_MD_DESTROY:
1931 case ECHO_MD_RMDIR: {
1932 __u32 mode = data->ioc_obdo2.o_mode;
1934 rc = echo_destroy_object(env, ed, parent, name, namelen,
1938 case ECHO_MD_LOOKUP:
1939 rc = echo_lookup_object(env, ed, parent, id, count);
1941 case ECHO_MD_GETATTR:
1942 rc = echo_getattr_object(env, ed, parent, id, count);
1944 case ECHO_MD_SETATTR:
1945 rc = echo_setattr_object(env, ed, parent, id, count);
1948 CERROR("unknown command %d\n", command);
1952 echo_ucred_fini(env);
1956 OBD_FREE(name, namelen + 1);
1958 lu_object_put(env, parent);
1960 LASSERT(info->eti_big_lmm);
1961 OBD_FREE_LARGE(info->eti_big_lmm, info->eti_big_lmmsize);
1962 info->eti_big_lmm = NULL;
1963 info->eti_big_lmmsize = 0;
1965 cl_env_put(env, &refcheck);
1968 #endif /* HAVE_SERVER_SUPPORT */
1970 static int echo_create_object(const struct lu_env *env, struct echo_device *ed,
1973 struct echo_object *eco;
1974 struct echo_client_obd *ec = ed->ed_ec;
1979 if (!(oa->o_valid & OBD_MD_FLID) ||
1980 !(oa->o_valid & OBD_MD_FLGROUP) ||
1981 !fid_seq_is_echo(ostid_seq(&oa->o_oi))) {
1982 CERROR("invalid oid "DOSTID"\n", POSTID(&oa->o_oi));
1986 if (ostid_id(&oa->o_oi) == 0) {
1987 rc = ostid_set_id(&oa->o_oi, ++last_object_id);
1992 rc = obd_create(env, ec->ec_exp, oa);
1994 CERROR("Cannot create objects: rc = %d\n", rc);
2000 oa->o_valid |= OBD_MD_FLID;
2002 eco = cl_echo_object_find(ed, &oa->o_oi);
2004 GOTO(failed, rc = PTR_ERR(eco));
2005 cl_echo_object_put(eco);
2007 CDEBUG(D_INFO, "oa oid "DOSTID"\n", POSTID(&oa->o_oi));
2011 if (created && rc != 0)
2012 obd_destroy(env, ec->ec_exp, oa);
2015 CERROR("create object failed with: rc = %d\n", rc);
2020 static int echo_get_object(struct echo_object **ecop, struct echo_device *ed,
2023 struct echo_object *eco;
2027 if (!(oa->o_valid & OBD_MD_FLID) ||
2028 !(oa->o_valid & OBD_MD_FLGROUP) ||
2029 ostid_id(&oa->o_oi) == 0) {
2030 CERROR("invalid oid "DOSTID"\n", POSTID(&oa->o_oi));
2035 eco = cl_echo_object_find(ed, &oa->o_oi);
2044 static void echo_put_object(struct echo_object *eco)
2048 rc = cl_echo_object_put(eco);
2050 CERROR("%s: echo client drop an object failed: rc = %d\n",
2051 eco->eo_dev->ed_ec->ec_exp->exp_obd->obd_name, rc);
2054 static void echo_client_page_debug_setup(struct page *page, int rw, u64 id,
2055 u64 offset, u64 count)
2062 /* no partial pages on the client */
2063 LASSERT(count == PAGE_SIZE);
2067 for (delta = 0; delta < PAGE_SIZE; delta += OBD_ECHO_BLOCK_SIZE) {
2068 if (rw == OBD_BRW_WRITE) {
2069 stripe_off = offset + delta;
2072 stripe_off = 0xdeadbeef00c0ffeeULL;
2073 stripe_id = 0xdeadbeef00c0ffeeULL;
2075 block_debug_setup(addr + delta, OBD_ECHO_BLOCK_SIZE,
2076 stripe_off, stripe_id);
2083 echo_client_page_debug_check(struct page *page, u64 id, u64 offset, u64 count)
2092 /* no partial pages on the client */
2093 LASSERT(count == PAGE_SIZE);
2097 for (rc = delta = 0; delta < PAGE_SIZE; delta += OBD_ECHO_BLOCK_SIZE) {
2098 stripe_off = offset + delta;
2101 rc2 = block_debug_check("test_brw",
2102 addr + delta, OBD_ECHO_BLOCK_SIZE,
2103 stripe_off, stripe_id);
2105 CERROR("Error in echo object %#llx\n", id);
2114 static int echo_client_prep_commit(const struct lu_env *env,
2115 struct obd_export *exp, int rw,
2116 struct obdo *oa, struct echo_object *eco,
2117 u64 offset, u64 count,
2118 u64 batch, int async)
2120 struct obd_ioobj ioo;
2121 struct niobuf_local *lnb;
2122 struct niobuf_remote rnb;
2124 u64 npages, tot_pages, apc;
2125 int i, ret = 0, brw_flags = 0;
2128 if (count <= 0 || (count & ~PAGE_MASK) != 0)
2131 apc = npages = batch >> PAGE_SHIFT;
2132 tot_pages = count >> PAGE_SHIFT;
2134 OBD_ALLOC_PTR_ARRAY_LARGE(lnb, apc);
2138 if (rw == OBD_BRW_WRITE && async)
2139 brw_flags |= OBD_BRW_ASYNC;
2141 obdo_to_ioobj(oa, &ioo);
2145 for (; tot_pages > 0; tot_pages -= npages) {
2148 if (tot_pages < npages)
2151 rnb.rnb_offset = off;
2152 rnb.rnb_len = npages * PAGE_SIZE;
2153 rnb.rnb_flags = brw_flags;
2155 off += npages * PAGE_SIZE;
2158 ret = obd_preprw(env, rw, exp, oa, 1, &ioo, &rnb, &lpages, lnb);
2162 for (i = 0; i < lpages; i++) {
2163 struct page *page = lnb[i].lnb_page;
2165 /* read past eof? */
2166 if (!page && lnb[i].lnb_rc == 0)
2170 lnb[i].lnb_flags |= OBD_BRW_ASYNC;
2172 if (ostid_id(&oa->o_oi) == ECHO_PERSISTENT_OBJID ||
2173 (oa->o_valid & OBD_MD_FLFLAGS) == 0 ||
2174 (oa->o_flags & OBD_FL_DEBUG_CHECK) == 0)
2177 if (rw == OBD_BRW_WRITE)
2178 echo_client_page_debug_setup(page, rw,
2179 ostid_id(&oa->o_oi),
2180 lnb[i].lnb_file_offset,
2183 echo_client_page_debug_check(page,
2184 ostid_id(&oa->o_oi),
2185 lnb[i].lnb_file_offset,
2189 ret = obd_commitrw(env, rw, exp, oa, 1, &ioo, &rnb, npages, lnb,
2190 ret, rnb.rnb_len, ktime_set(0, 0));
2194 /* Reuse env context. */
2195 lu_context_exit((struct lu_context *)&env->le_ctx);
2196 lu_context_enter((struct lu_context *)&env->le_ctx);
2200 OBD_FREE_PTR_ARRAY_LARGE(lnb, apc);
2205 static int echo_client_brw_ioctl(const struct lu_env *env, int rw,
2206 struct obd_export *exp,
2207 struct obd_ioctl_data *data)
2209 struct obd_device *obd = class_exp2obd(exp);
2210 struct echo_device *ed = obd2echo_dev(obd);
2211 struct echo_client_obd *ec = ed->ed_ec;
2212 struct obdo *oa = &data->ioc_obdo1;
2213 struct echo_object *eco;
2219 LASSERT(oa->o_valid & OBD_MD_FLGROUP);
2221 rc = echo_get_object(&eco, ed, oa);
2225 oa->o_valid &= ~OBD_MD_FLHANDLE;
2227 /* OFD/obdfilter works only via prep/commit */
2228 test_mode = (long)data->ioc_pbuf1;
2229 if (!ed->ed_next && test_mode != 3) {
2231 data->ioc_plen1 = data->ioc_count;
2237 /* Truncate batch size to maximum */
2238 if (data->ioc_plen1 > PTLRPC_MAX_BRW_SIZE)
2239 data->ioc_plen1 = PTLRPC_MAX_BRW_SIZE;
2241 switch (test_mode) {
2243 rc = echo_client_prep_commit(env, ec->ec_exp, rw, oa, eco,
2244 data->ioc_offset, data->ioc_count,
2245 data->ioc_plen1, async);
2251 echo_put_object(eco);
2257 echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
2258 void *karg, void __user *uarg)
2260 #ifdef HAVE_SERVER_SUPPORT
2261 struct tgt_session_info *tsi;
2263 struct obd_device *obd = exp->exp_obd;
2264 struct echo_device *ed = obd2echo_dev(obd);
2265 struct echo_client_obd *ec = ed->ed_ec;
2266 struct echo_object *eco;
2267 struct obd_ioctl_data *data;
2269 unsigned long env_tags = 0;
2273 int rw = OBD_BRW_READ;
2277 CDEBUG(D_IOCTL, "%s: cmd=%x len=%u karg=%pK uarg=%pK\n",
2278 exp->exp_obd->obd_name, cmd, len, karg, uarg);
2279 if (unlikely(karg == NULL))
2280 RETURN(OBD_IOC_ERROR(obd->obd_name, cmd, "karg=NULL", rc));
2283 oa = &data->ioc_obdo1;
2284 if (!(oa->o_valid & OBD_MD_FLGROUP)) {
2285 oa->o_valid |= OBD_MD_FLGROUP;
2286 ostid_set_seq_echo(&oa->o_oi);
2289 /* This FID is unpacked just for validation at this point */
2290 rc = ostid_to_fid(&fid, &oa->o_oi, 0);
2294 env = cl_env_get(&refcheck);
2296 RETURN(PTR_ERR(env));
2300 #ifdef HAVE_SERVER_SUPPORT
2301 if (cmd == OBD_IOC_ECHO_MD || cmd == OBD_IOC_ECHO_ALLOC_SEQ)
2302 env_tags = ECHO_MD_CTX_TAG;
2305 env_tags = ECHO_DT_CTX_TAG;
2307 rc = lu_env_refill_by_tags(env, env_tags, ECHO_SES_TAG);
2311 #ifdef HAVE_SERVER_SUPPORT
2312 tsi = tgt_ses_info(env);
2313 /* treat as local operation */
2314 tsi->tsi_exp = NULL;
2315 tsi->tsi_jobid = NULL;
2319 case OBD_IOC_CREATE: /* may create echo object */
2320 if (!capable(CAP_SYS_ADMIN))
2321 GOTO(out, rc = -EPERM);
2323 rc = echo_create_object(env, ed, oa);
2326 #ifdef HAVE_SERVER_SUPPORT
2327 case OBD_IOC_ECHO_MD: {
2334 if (!capable(CAP_SYS_ADMIN))
2335 GOTO(out, rc = -EPERM);
2337 count = data->ioc_count;
2338 cmd = data->ioc_command;
2340 id = data->ioc_obdo2.o_oi.oi.oi_id;
2341 dirlen = data->ioc_plen1;
2342 OBD_ALLOC(dir, dirlen + 1);
2344 GOTO(out, rc = -ENOMEM);
2346 if (copy_from_user(dir, data->ioc_pbuf1, dirlen)) {
2347 OBD_FREE(dir, data->ioc_plen1 + 1);
2348 GOTO(out, rc = -EFAULT);
2351 rc = echo_md_handler(ed, cmd, dir, dirlen, id, count, data);
2352 OBD_FREE(dir, dirlen + 1);
2355 case OBD_IOC_ECHO_ALLOC_SEQ: {
2359 if (!capable(CAP_SYS_ADMIN))
2360 GOTO(out, rc = -EPERM);
2362 rc = seq_client_get_seq(env, ed->ed_cl_seq, &seq);
2364 CERROR("%s: Can not alloc seq: rc = %d\n",
2369 if (copy_to_user(data->ioc_pbuf1, &seq, data->ioc_plen1))
2372 max_count = LUSTRE_METADATA_SEQ_MAX_WIDTH;
2373 if (copy_to_user(data->ioc_pbuf2, &max_count,
2378 #endif /* HAVE_SERVER_SUPPORT */
2379 case OBD_IOC_DESTROY:
2380 if (!capable(CAP_SYS_ADMIN))
2381 GOTO(out, rc = -EPERM);
2383 rc = echo_get_object(&eco, ed, oa);
2385 rc = obd_destroy(env, ec->ec_exp, oa);
2387 eco->eo_deleted = 1;
2388 echo_put_object(eco);
2392 case OBD_IOC_GETATTR:
2393 rc = echo_get_object(&eco, ed, oa);
2395 rc = obd_getattr(env, ec->ec_exp, oa);
2396 echo_put_object(eco);
2400 case OBD_IOC_SETATTR:
2401 if (!capable(CAP_SYS_ADMIN))
2402 GOTO(out, rc = -EPERM);
2404 rc = echo_get_object(&eco, ed, oa);
2406 rc = obd_setattr(env, ec->ec_exp, oa);
2407 echo_put_object(eco);
2411 case OBD_IOC_BRW_WRITE:
2412 if (!capable(CAP_SYS_ADMIN))
2413 GOTO(out, rc = -EPERM);
2417 case OBD_IOC_BRW_READ:
2418 rc = echo_client_brw_ioctl(env, rw, exp, data);
2421 rc = OBD_IOC_ERROR(obd->obd_name, cmd, "unrecognized", -ENOTTY);
2428 cl_env_put(env, &refcheck);
2433 static int echo_client_setup(const struct lu_env *env,
2434 struct obd_device *obd, struct lustre_cfg *lcfg)
2436 struct echo_client_obd *ec = &obd->u.echo_client;
2437 struct obd_device *tgt;
2438 struct obd_uuid echo_uuid = { "ECHO_UUID" };
2439 struct obd_connect_data *ocd = NULL;
2443 if (lcfg->lcfg_bufcount < 2 || LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
2444 CERROR("requires a TARGET OBD name\n");
2448 tgt = class_name2obd(lustre_cfg_string(lcfg, 1));
2449 if (!tgt || !tgt->obd_attached || !tgt->obd_set_up) {
2450 CERROR("device not attached or not set up (%s)\n",
2451 lustre_cfg_string(lcfg, 1));
2455 spin_lock_init(&ec->ec_lock);
2456 INIT_LIST_HEAD(&ec->ec_objects);
2457 INIT_LIST_HEAD(&ec->ec_locks);
2460 lu_context_tags_update(ECHO_DT_CTX_TAG);
2461 lu_session_tags_update(ECHO_SES_TAG);
2463 if (!strcmp(tgt->obd_type->typ_name, LUSTRE_MDT_NAME)) {
2464 #ifdef HAVE_SERVER_SUPPORT
2465 lu_context_tags_update(ECHO_MD_CTX_TAG);
2468 "Local operations are NOT supported on client side. Only remote operations are supported. Metadata client must be run on server side.\n");
2473 OBD_ALLOC(ocd, sizeof(*ocd));
2475 CERROR("Can't alloc ocd connecting to %s\n",
2476 lustre_cfg_string(lcfg, 1));
2480 ocd->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_REQPORTAL |
2481 OBD_CONNECT_BRW_SIZE |
2482 OBD_CONNECT_GRANT | OBD_CONNECT_FULL20 |
2483 OBD_CONNECT_64BITHASH | OBD_CONNECT_LVB_TYPE |
2484 OBD_CONNECT_FID | OBD_CONNECT_FLAGS2;
2485 ocd->ocd_connect_flags2 = OBD_CONNECT2_REP_MBITS;
2487 ocd->ocd_brw_size = DT_MAX_BRW_SIZE;
2488 ocd->ocd_version = LUSTRE_VERSION_CODE;
2489 ocd->ocd_group = FID_SEQ_ECHO;
2491 rc = obd_connect(env, &ec->ec_exp, tgt, &echo_uuid, ocd, NULL);
2493 /* Turn off pinger because it connects to tgt obd directly. */
2494 spin_lock(&tgt->obd_dev_lock);
2495 list_del_init(&ec->ec_exp->exp_obd_chain_timed);
2496 spin_unlock(&tgt->obd_dev_lock);
2499 OBD_FREE(ocd, sizeof(*ocd));
2502 CERROR("fail to connect to device %s\n",
2503 lustre_cfg_string(lcfg, 1));
2510 static int echo_client_cleanup(struct obd_device *obd)
2512 struct echo_device *ed = obd2echo_dev(obd);
2513 struct echo_client_obd *ec = &obd->u.echo_client;
2517 /*Do nothing for Metadata echo client*/
2521 lu_session_tags_clear(ECHO_SES_TAG & ~LCT_SESSION);
2522 lu_context_tags_clear(ECHO_DT_CTX_TAG);
2523 if (ed->ed_next_ismd) {
2524 #ifdef HAVE_SERVER_SUPPORT
2525 lu_context_tags_clear(ECHO_MD_CTX_TAG);
2528 "This is client-side only module, does not support metadata echo client.\n");
2533 if (!list_empty(&obd->obd_exports)) {
2534 CERROR("still has clients!\n");
2538 LASSERT(refcount_read(&ec->ec_exp->exp_handle.h_ref) > 0);
2539 rc = obd_disconnect(ec->ec_exp);
2541 CERROR("fail to disconnect device: %d\n", rc);
2546 static int echo_client_connect(const struct lu_env *env,
2547 struct obd_export **exp,
2548 struct obd_device *src, struct obd_uuid *cluuid,
2549 struct obd_connect_data *data, void *localdata)
2552 struct lustre_handle conn = { 0 };
2555 rc = class_connect(&conn, src, cluuid);
2557 *exp = class_conn2export(&conn);
2562 static int echo_client_disconnect(struct obd_export *exp)
2568 GOTO(out, rc = -EINVAL);
2570 rc = class_disconnect(exp);
2576 static const struct obd_ops echo_client_obd_ops = {
2577 .o_owner = THIS_MODULE,
2578 .o_iocontrol = echo_client_iocontrol,
2579 .o_connect = echo_client_connect,
2580 .o_disconnect = echo_client_disconnect
2583 static int __init obdecho_init(void)
2588 LCONSOLE_INFO("Echo OBD driver; http://www.lustre.org/\n");
2590 LASSERT(PAGE_SIZE % OBD_ECHO_BLOCK_SIZE == 0);
2592 # ifdef HAVE_SERVER_SUPPORT
2593 rc = echo_persistent_pages_init();
2597 rc = class_register_type(&echo_obd_ops, NULL, true,
2598 LUSTRE_ECHO_NAME, &echo_srv_type);
2603 rc = lu_kmem_init(echo_caches);
2605 rc = class_register_type(&echo_client_obd_ops, NULL, false,
2606 LUSTRE_ECHO_CLIENT_NAME,
2609 lu_kmem_fini(echo_caches);
2612 # ifdef HAVE_SERVER_SUPPORT
2616 class_unregister_type(LUSTRE_ECHO_NAME);
2618 echo_persistent_pages_fini();
2624 static void __exit obdecho_exit(void)
2626 class_unregister_type(LUSTRE_ECHO_CLIENT_NAME);
2627 lu_kmem_fini(echo_caches);
2629 #ifdef HAVE_SERVER_SUPPORT
2630 class_unregister_type(LUSTRE_ECHO_NAME);
2631 echo_persistent_pages_fini();
2635 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
2636 MODULE_DESCRIPTION("Lustre Echo Client test driver");
2637 MODULE_VERSION(LUSTRE_VERSION_STRING);
2638 MODULE_LICENSE("GPL");
2640 module_init(obdecho_init);
2641 module_exit(obdecho_exit);
2643 /** @} echo_client */