Whamcloud - gitweb
LU-10994 echo: remove client operations from echo objects
[fs/lustre-release.git] / lustre / obdecho / echo_client.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  */
31
32 #define DEBUG_SUBSYSTEM S_ECHO
33
34 #include <linux/user_namespace.h>
35 #include <linux/uidgid.h>
36
37 #include <libcfs/libcfs.h>
38 #include <obd.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>
50
51 #define ETI_NAME_LEN    20
52
53 #endif /* HAVE_SERVER_SUPPORT */
54
55 #include "echo_internal.h"
56
57 /** \defgroup echo_client Echo Client
58  * @{
59  */
60
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)
65
66 struct echo_device {
67         struct cl_device          ed_cl;
68         struct echo_client_obd   *ed_ec;
69
70         struct cl_site            ed_site_myself;
71         struct lu_site           *ed_site;
72         struct lu_device         *ed_next;
73         int                       ed_next_ismd;
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 */
79 };
80
81 struct echo_object {
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;
87         int                     eo_deleted;
88 };
89
90 struct echo_object_conf {
91         struct cl_object_conf   eoc_cl;
92         struct lov_oinfo      **eoc_oinfo;
93 };
94
95 #ifdef HAVE_SERVER_SUPPORT
96 static const char echo_md_root_dir_name[] = "ROOT_ECHO";
97
98 /**
99  * In order to use the values of members in struct mdd_device,
100  * we define an alias structure here.
101  */
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;
109 };
110 #endif /* HAVE_SERVER_SUPPORT */
111
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);
116
117 /** \defgroup echo_helpers Helper functions
118  * @{
119  */
120 static struct echo_device *cl2echo_dev(const struct cl_device *dev)
121 {
122         return container_of_safe(dev, struct echo_device, ed_cl);
123 }
124
125 static struct cl_device *echo_dev2cl(struct echo_device *d)
126 {
127         return &d->ed_cl;
128 }
129
130 static struct echo_device *obd2echo_dev(const struct obd_device *obd)
131 {
132         return cl2echo_dev(lu2cl_dev(obd->obd_lu_dev));
133 }
134
135 static struct cl_object *echo_obj2cl(struct echo_object *eco)
136 {
137         return &eco->eo_cl;
138 }
139
140 static struct echo_object *cl2echo_obj(const struct cl_object *o)
141 {
142         return container_of(o, struct echo_object, eo_cl);
143 }
144
145 static struct lu_context_key echo_thread_key;
146
147 static struct echo_thread_info *echo_env_info(const struct lu_env *env)
148 {
149         struct echo_thread_info *info;
150
151         info = lu_context_key_get(&env->le_ctx, &echo_thread_key);
152         LASSERT(info != NULL);
153         return info;
154 }
155
156 static struct echo_object_conf *cl2echo_conf(const struct cl_object_conf *c)
157 {
158         return container_of(c, struct echo_object_conf, eoc_cl);
159 }
160
161 #ifdef HAVE_SERVER_SUPPORT
162 static struct echo_md_device *lu2emd_dev(struct lu_device *d)
163 {
164         return container_of_safe(d, struct echo_md_device,
165                                  emd_md_dev.md_lu_dev);
166 }
167
168 static struct lu_device *emd2lu_dev(struct echo_md_device *d)
169 {
170         return &d->emd_md_dev.md_lu_dev;
171 }
172
173 static struct seq_server_site *echo_md_seq_site(struct echo_md_device *d)
174 {
175         return emd2lu_dev(d)->ld_site->ld_seq_site;
176 }
177
178 static struct obd_device *emd2obd_dev(struct echo_md_device *d)
179 {
180         return d->emd_md_dev.md_lu_dev.ld_obd;
181 }
182 #endif /* HAVE_SERVER_SUPPORT */
183
184 /** @} echo_helpers */
185
186 static int cl_echo_object_put(struct echo_object *eco);
187
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 */
201         int                     eti_big_lmmsize;
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];
206 #endif
207 };
208
209 /* No session used right now */
210 struct echo_session_info {
211         unsigned long dummy;
212 };
213
214 static struct kmem_cache *echo_object_kmem;
215 static struct kmem_cache *echo_thread_kmem;
216 static struct kmem_cache *echo_session_kmem;
217
218 static struct lu_kmem_descr echo_caches[] = {
219         {
220                 .ckd_cache = &echo_object_kmem,
221                 .ckd_name  = "echo_object_kmem",
222                 .ckd_size  = sizeof(struct echo_object)
223         },
224         {
225                 .ckd_cache = &echo_thread_kmem,
226                 .ckd_name  = "echo_thread_kmem",
227                 .ckd_size  = sizeof(struct echo_thread_info)
228         },
229         {
230                 .ckd_cache = &echo_session_kmem,
231                 .ckd_name  = "echo_session_kmem",
232                 .ckd_size  = sizeof(struct echo_session_info)
233         },
234         {
235                 .ckd_cache = NULL
236         }
237 };
238
239 /** \defgroup echo_lu_ops lu_object operations
240  *
241  * operations for echo lu object.
242  *
243  * @{
244  */
245 static int echo_object_init(const struct lu_env *env, struct lu_object *obj,
246                             const struct lu_object_conf *conf)
247 {
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));
251
252         ENTRY;
253         if (ed->ed_next) {
254                 struct lu_object  *below;
255                 struct lu_device  *under;
256
257                 under = ed->ed_next;
258                 below = under->ld_ops->ldo_object_alloc(env, obj->lo_header,
259                                                         under);
260                 if (!below)
261                         RETURN(-ENOMEM);
262                 lu_object_add(obj, below);
263         }
264
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);
268
269                 LASSERT(econf->eoc_oinfo != NULL);
270
271                 /*
272                  * Transfer the oinfo pointer to eco that it won't be
273                  * freed.
274                  */
275                 eco->eo_oinfo = *econf->eoc_oinfo;
276                 *econf->eoc_oinfo = NULL;
277         } else {
278                 eco->eo_oinfo = NULL;
279         }
280
281         eco->eo_dev = ed;
282         cl_object_page_init(lu2cl(obj), 0);
283
284         spin_lock(&ec->ec_lock);
285         list_add_tail(&eco->eo_obj_chain, &ec->ec_objects);
286         spin_unlock(&ec->ec_lock);
287
288         RETURN(0);
289 }
290
291 static void echo_object_delete(const struct lu_env *env, struct lu_object *obj)
292 {
293         struct echo_object *eco    = cl2echo_obj(lu2cl(obj));
294         struct echo_client_obd *ec;
295
296         ENTRY;
297
298         /* object delete called unconditolally - layer init or not */
299         if (eco->eo_dev == NULL)
300                 return;
301
302         ec = eco->eo_dev->ed_ec;
303
304         spin_lock(&ec->ec_lock);
305         list_del_init(&eco->eo_obj_chain);
306         spin_unlock(&ec->ec_lock);
307
308         if (eco->eo_oinfo)
309                 OBD_FREE_PTR(eco->eo_oinfo);
310 }
311
312 static void echo_object_free_rcu(struct rcu_head *head)
313 {
314         struct echo_object *eco = container_of(head, struct echo_object,
315                                                eo_hdr.coh_lu.loh_rcu);
316
317         kmem_cache_free(echo_object_kmem, eco);
318 }
319
320 static void echo_object_free(const struct lu_env *env, struct lu_object *obj)
321 {
322         struct echo_object *eco    = cl2echo_obj(lu2cl(obj));
323
324         ENTRY;
325
326         lu_object_fini(obj);
327         lu_object_header_fini(obj->lo_header);
328
329         OBD_FREE_PRE(eco, sizeof(*eco), "slab-freed");
330         call_rcu(&eco->eo_hdr.coh_lu.loh_rcu, echo_object_free_rcu);
331         EXIT;
332 }
333
334 static int echo_object_print(const struct lu_env *env, void *cookie,
335                              lu_printer_t p, const struct lu_object *o)
336 {
337         struct echo_object *obj = cl2echo_obj(lu2cl(o));
338
339         return (*p)(env, cookie, "echoclient-object@%p", obj);
340 }
341
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
349 };
350 /** @} echo_lu_ops */
351
352 /** \defgroup echo_lu_dev_ops  lu_device operations
353  *
354  * Operations for echo lu device.
355  *
356  * @{
357  */
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)
361 {
362         struct echo_object *eco;
363         struct lu_object *obj = NULL;
364
365         ENTRY;
366         /* we're the top dev. */
367         LASSERT(hdr == NULL);
368         OBD_SLAB_ALLOC_PTR_GFP(eco, echo_object_kmem, GFP_NOFS);
369         if (eco) {
370                 struct cl_object_header *hdr = &eco->eo_hdr;
371
372                 obj = &echo_obj2cl(eco)->co_lu;
373                 cl_object_header_init(hdr);
374                 hdr->coh_page_bufsize = cfs_size_round(sizeof(struct cl_page));
375
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;
379         }
380         RETURN(obj);
381 }
382
383 static const struct lu_device_operations echo_device_lu_ops = {
384         .ldo_object_alloc   = echo_object_alloc,
385 };
386
387 /** @} echo_lu_dev_ops */
388
389 /** \defgroup echo_init Setup and teardown
390  *
391  * Init and fini functions for echo client.
392  *
393  * @{
394  */
395 static int echo_site_init(const struct lu_env *env, struct echo_device *ed)
396 {
397         struct cl_site *site = &ed->ed_site_myself;
398         int rc;
399
400         /* initialize site */
401         rc = cl_site_init(site, &ed->ed_cl);
402         if (rc) {
403                 CERROR("Cannot initialize site for echo client(%d)\n", rc);
404                 return rc;
405         }
406
407         rc = lu_site_init_finish(&site->cs_lu);
408         if (rc) {
409                 cl_site_fini(site);
410                 return rc;
411         }
412
413         ed->ed_site = &site->cs_lu;
414         return 0;
415 }
416
417 static void echo_site_fini(const struct lu_env *env, struct echo_device *ed)
418 {
419         if (ed->ed_site) {
420                 if (!ed->ed_next_ismd)
421                         lu_site_fini(ed->ed_site);
422                 ed->ed_site = NULL;
423         }
424 }
425
426 static void *echo_thread_key_init(const struct lu_context *ctx,
427                                   struct lu_context_key *key)
428 {
429         struct echo_thread_info *info;
430
431         OBD_SLAB_ALLOC_PTR_GFP(info, echo_thread_kmem, GFP_NOFS);
432         if (!info)
433                 info = ERR_PTR(-ENOMEM);
434         return info;
435 }
436
437 static void echo_thread_key_fini(const struct lu_context *ctx,
438                                  struct lu_context_key *key, void *data)
439 {
440         struct echo_thread_info *info = data;
441
442         OBD_SLAB_FREE_PTR(info, echo_thread_kmem);
443 }
444
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,
449 };
450
451 static void *echo_session_key_init(const struct lu_context *ctx,
452                                   struct lu_context_key *key)
453 {
454         struct echo_session_info *session;
455
456         OBD_SLAB_ALLOC_PTR_GFP(session, echo_session_kmem, GFP_NOFS);
457         if (!session)
458                 session = ERR_PTR(-ENOMEM);
459         return session;
460 }
461
462 static void echo_session_key_fini(const struct lu_context *ctx,
463                                   struct lu_context_key *key, void *data)
464 {
465         struct echo_session_info *session = data;
466
467         OBD_SLAB_FREE_PTR(session, echo_session_kmem);
468 }
469
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,
474 };
475
476 LU_TYPE_INIT_FINI(echo, &echo_thread_key, &echo_session_key);
477
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)
482 {
483         char *prefix;
484         int rc;
485
486         ENTRY;
487         OBD_ALLOC_PTR(ed->ed_cl_seq);
488         if (!ed->ed_cl_seq)
489                 RETURN(-ENOMEM);
490
491         OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
492         if (!prefix)
493                 GOTO(out_free_seq, rc = -ENOMEM);
494
495         snprintf(prefix, MAX_OBD_NAME + 5, "srv-%s", obd_name);
496
497         /* Init client side sequence-manager */
498         seq_client_init(ed->ed_cl_seq, NULL,
499                         LUSTRE_SEQ_METADATA,
500                         prefix, ss->ss_server_seq);
501         ed->ed_cl_seq->lcs_width = ECHO_SEQ_WIDTH;
502         OBD_FREE(prefix, MAX_OBD_NAME + 5);
503
504         RETURN(0);
505
506 out_free_seq:
507         OBD_FREE_PTR(ed->ed_cl_seq);
508         ed->ed_cl_seq = NULL;
509         RETURN(rc);
510 }
511
512 static int echo_fid_fini(struct obd_device *obd)
513 {
514         struct echo_device *ed = obd2echo_dev(obd);
515
516         ENTRY;
517         if (ed->ed_cl_seq) {
518                 seq_client_fini(ed->ed_cl_seq);
519                 OBD_FREE_PTR(ed->ed_cl_seq);
520                 ed->ed_cl_seq = NULL;
521         }
522
523         RETURN(0);
524 }
525
526 static void echo_ed_los_fini(const struct lu_env *env, struct echo_device *ed)
527 {
528         ENTRY;
529         if (ed != NULL && ed->ed_next_ismd && ed->ed_los != NULL) {
530                 local_oid_storage_fini(env, ed->ed_los);
531                 ed->ed_los = NULL;
532         }
533 }
534
535 static int
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)
540 {
541         struct dt_object        *parent = NULL;
542         struct dt_object        *dto = NULL;
543         int                      rc = 0;
544
545         ENTRY;
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));
550
551         /* create local file with @fid */
552         dto = local_file_find_or_create_with_fid(env, emd->emd_bottom, fid,
553                                                  parent, name, mode);
554         if (IS_ERR(dto))
555                 GOTO(out_put, rc = PTR_ERR(dto));
556
557         *fid = *lu_object_fid(&dto->do_lu);
558         /*
559          * since stack is not fully set up the local_storage uses own stack
560          * and we should drop its object from cache
561          */
562         dt_object_put_nocache(env, dto);
563
564         EXIT;
565 out_put:
566         dt_object_put(env, parent);
567         RETURN(rc);
568 }
569
570 static int
571 echo_md_root_get(const struct lu_env *env, struct echo_md_device *emd,
572                  struct echo_device *ed)
573 {
574         struct lu_fid fid;
575         int rc = 0;
576
577         ENTRY;
578         /* Setup local dirs */
579         fid.f_seq = FID_SEQ_LOCAL_NAME;
580         fid.f_oid = 1;
581         fid.f_ver = 0;
582         rc = local_oid_storage_init(env, emd->emd_bottom, &fid, &ed->ed_los);
583         if (rc != 0)
584                 RETURN(rc);
585
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,
592                                                &fid);
593                 if (rc != 0) {
594                         CERROR("%s: create md echo root fid failed: rc = %d\n",
595                                emd2obd_dev(emd)->obd_name, rc);
596                         GOTO(out_los, rc);
597                 }
598         }
599         ed->ed_root_fid = fid;
600
601         RETURN(0);
602 out_los:
603         echo_ed_los_fini(env, ed);
604
605         RETURN(rc);
606 }
607 #endif /* HAVE_SERVER_SUPPORT */
608
609 static struct lu_device *echo_device_alloc(const struct lu_env *env,
610                                            struct lu_device_type *t,
611                                            struct lustre_cfg *cfg)
612 {
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;
619         int rc;
620         int cleanup = 0;
621
622         ENTRY;
623         OBD_ALLOC_PTR(ed);
624         if (!ed)
625                 GOTO(out, rc = -ENOMEM);
626
627         cleanup = 1;
628         cd = &ed->ed_cl;
629         rc = cl_device_init(cd, t);
630         if (rc)
631                 GOTO(out, rc);
632
633         cd->cd_lu_dev.ld_ops = &echo_device_lu_ops;
634
635         cleanup = 2;
636         obd = class_name2obd(lustre_cfg_string(cfg, 0));
637         LASSERT(obd != NULL);
638         LASSERT(env != NULL);
639
640         tgt = class_name2obd(lustre_cfg_string(cfg, 1));
641         if (!tgt) {
642                 CERROR("Can not find tgt device %s\n",
643                         lustre_cfg_string(cfg, 1));
644                 GOTO(out, rc = -ENODEV);
645         }
646
647         next = tgt->obd_lu_dev;
648
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);
655                 if (rc)
656                         GOTO(out, rc);
657         } else {
658                 GOTO(out, rc = -EINVAL);
659         }
660
661         cleanup = 3;
662
663         rc = echo_client_setup(env, obd, cfg);
664         if (rc)
665                 GOTO(out, rc);
666
667         ed->ed_ec = &obd->u.echo_client;
668         cleanup = 4;
669
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;
677                 int                      found = 0;
678
679                 if (!next) {
680                         CERROR("%s is not lu device type!\n",
681                                lustre_cfg_string(cfg, 1));
682                         GOTO(out, rc = -EINVAL);
683                 }
684
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);
691                 }
692
693                 ls = next->ld_site;
694
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) {
698                                 found = 1;
699                                 break;
700                         }
701                 }
702                 spin_unlock(&ls->ls_ld_lock);
703
704                 if (found == 0) {
705                         CERROR("%s is not lu device type!\n",
706                                lustre_cfg_string(cfg, 1));
707                         GOTO(out, rc = -EINVAL);
708                 }
709
710                 next = ld;
711                 /* For MD echo client, it will use the site in MDS stack */
712                 ed->ed_site = ls;
713                 ed->ed_cl.cd_lu_dev.ld_site = ls;
714                 rc = echo_fid_init(ed, obd->obd_name, lu_site2seq(ls));
715                 if (rc) {
716                         CERROR("echo fid init error %d\n", rc);
717                         GOTO(out, rc);
718                 }
719
720                 md = lu2md_dev(next);
721                 emd = lu2emd_dev(&md->md_lu_dev);
722                 rc = echo_md_root_get(env, emd, ed);
723                 if (rc != 0) {
724                         CERROR("%s: get root error: rc = %d\n",
725                                 emd2obd_dev(emd)->obd_name, rc);
726                         GOTO(out, rc);
727                 }
728 #else /* !HAVE_SERVER_SUPPORT */
729                 CERROR(
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 */
733         } else {
734                 /*
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
737                  */
738                 if (next != NULL && !lu_device_is_cl(next))
739                         next = NULL;
740
741                 tgt_type_name = tgt->obd_type->typ_name;
742                 if (next) {
743                         LASSERT(next != NULL);
744                         if (next->ld_site)
745                                 GOTO(out, rc = -EBUSY);
746
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,
750                                                         NULL);
751                         if (rc)
752                                 GOTO(out, rc);
753                 } else {
754                         LASSERT(strcmp(tgt_type_name, LUSTRE_OST_NAME) == 0);
755                 }
756         }
757
758         ed->ed_next = next;
759         RETURN(&cd->cd_lu_dev);
760 out:
761         switch (cleanup) {
762         case 4: {
763                 int rc2;
764
765                 rc2 = echo_client_cleanup(obd);
766                 if (rc2)
767                         CERROR("Cleanup obd device %s error(%d)\n",
768                                obd->obd_name, rc2);
769         }
770         fallthrough;
771
772         case 3:
773                 echo_site_fini(env, ed);
774                 fallthrough;
775         case 2:
776                 cl_device_fini(&ed->ed_cl);
777                 fallthrough;
778         case 1:
779                 OBD_FREE_PTR(ed);
780                 fallthrough;
781         case 0:
782         default:
783                 break;
784         }
785         return ERR_PTR(rc);
786 }
787
788 static int echo_device_init(const struct lu_env *env, struct lu_device *d,
789                             const char *name, struct lu_device *next)
790 {
791         LBUG();
792         return 0;
793 }
794
795 static struct lu_device *echo_device_fini(const struct lu_env *env,
796                                           struct lu_device *d)
797 {
798         struct echo_device *ed = cl2echo_dev(lu2cl_dev(d));
799         struct lu_device *next = ed->ed_next;
800
801         while (next && !ed->ed_next_ismd)
802                 next = next->ld_type->ldt_ops->ldto_device_fini(env, next);
803         return NULL;
804 }
805
806 static struct lu_device *echo_device_free(const struct lu_env *env,
807                                           struct lu_device *d)
808 {
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;
813
814         CDEBUG(D_INFO, "echo device:%p is going to be freed, next = %p\n",
815                ed, next);
816
817         lu_site_purge(env, ed->ed_site, -1);
818
819         /*
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.
824          */
825         spin_lock(&ec->ec_lock);
826         list_for_each_entry(eco, &ec->ec_objects, eo_obj_chain)
827                 eco->eo_deleted = 1;
828         spin_unlock(&ec->ec_lock);
829
830         /* purge again */
831         lu_site_purge(env, ed->ed_site, -1);
832
833         CDEBUG(D_INFO,
834                "Waiting for the reference of echo object to be dropped\n");
835
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);
840                 CERROR(
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);
845         }
846         spin_unlock(&ec->ec_lock);
847
848         LASSERT(list_empty(&ec->ec_locks));
849
850         CDEBUG(D_INFO, "No object exists, exiting...\n");
851
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);
856 #endif
857         while (next && !ed->ed_next_ismd)
858                 next = next->ld_type->ldt_ops->ldto_device_free(env, next);
859
860         LASSERT(ed->ed_site == d->ld_site);
861         echo_site_fini(env, ed);
862         cl_device_fini(&ed->ed_cl);
863         OBD_FREE_PTR(ed);
864
865         cl_env_cache_purge(~0);
866
867         return NULL;
868 }
869
870 static const struct lu_device_type_operations echo_device_type_ops = {
871         .ldto_init = echo_type_init,
872         .ldto_fini = echo_type_fini,
873
874         .ldto_start = echo_type_start,
875         .ldto_stop  = echo_type_stop,
876
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
881 };
882
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,
888 };
889 /** @} echo_init */
890
891 /** \defgroup echo_exports Exported operations
892  *
893  * exporting functions to echo client
894  *
895  * @{
896  */
897
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)
901 {
902         struct lu_env *env;
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;
908         struct lu_fid *fid;
909         __u16  refcheck;
910         int rc;
911
912         ENTRY;
913         LASSERTF(ostid_id(oi) != 0, DOSTID"\n", POSTID(oi));
914         LASSERTF(ostid_seq(oi) == FID_SEQ_ECHO, DOSTID"\n", POSTID(oi));
915
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));
919
920         env = cl_env_get(&refcheck);
921         if (IS_ERR(env))
922                 RETURN((void *)env);
923
924         info = echo_env_info(env);
925         conf = &info->eti_conf;
926         if (d->ed_next) {
927                 OBD_ALLOC_PTR(oinfo);
928                 if (!oinfo)
929                         GOTO(out, eco = ERR_PTR(-ENOMEM));
930
931                 oinfo->loi_oi = *oi;
932                 conf->eoc_cl.u.coc_oinfo = oinfo;
933         }
934
935         /*
936          * If echo_object_init() is successful then ownership of oinfo
937          * is transferred to the object.
938          */
939         conf->eoc_oinfo = &oinfo;
940
941         fid = &info->eti_fid;
942         rc = ostid_to_fid(fid, oi, 0);
943         if (rc != 0)
944                 GOTO(out, eco = ERR_PTR(rc));
945
946         /*
947          * In the function below, .hs_keycmp resolves to
948          * lu_obj_hop_keycmp()
949          */
950         /* coverity[overrun-buffer-val] */
951         obj = cl_object_find(env, echo_dev2cl(d), fid, &conf->eoc_cl);
952         if (IS_ERR(obj))
953                 GOTO(out, eco = (void *)obj);
954
955         eco = cl2echo_obj(obj);
956         if (eco->eo_deleted) {
957                 cl_object_put(env, obj);
958                 eco = ERR_PTR(-EAGAIN);
959         }
960
961 out:
962         if (oinfo)
963                 OBD_FREE_PTR(oinfo);
964
965         cl_env_put(env, &refcheck);
966         RETURN(eco);
967 }
968
969 static int cl_echo_object_put(struct echo_object *eco)
970 {
971         struct lu_env *env;
972         struct cl_object *obj = echo_obj2cl(eco);
973         __u16  refcheck;
974
975         ENTRY;
976         env = cl_env_get(&refcheck);
977         if (IS_ERR(env))
978                 RETURN(PTR_ERR(env));
979
980         /* an external function to kill an object? */
981         if (eco->eo_deleted) {
982                 struct lu_object_header *loh = obj->co_lu.lo_header;
983
984                 LASSERT(&eco->eo_hdr == luh2coh(loh));
985                 set_bit(LU_OBJECT_HEARD_BANSHEE, &loh->loh_flags);
986         }
987
988         cl_object_put(env, obj);
989         cl_env_put(env, &refcheck);
990         RETURN(0);
991 }
992
993 /** @} echo_exports */
994
995 static u64 last_object_id;
996
997 #ifdef HAVE_SERVER_SUPPORT
998 static void echo_md_build_name(struct lu_name *lname, char *name,
999                                       __u64 id)
1000 {
1001         snprintf(name, ETI_NAME_LEN, "%llu", id);
1002         lname->ln_name = name;
1003         lname->ln_namelen = strlen(name);
1004 }
1005
1006 /* similar to mdt_attr_get_complex */
1007 static int echo_big_lmm_get(const struct lu_env *env, struct md_object *o,
1008                             struct md_attr *ma)
1009 {
1010         struct echo_thread_info *info = echo_env_info(env);
1011         int rc;
1012
1013         ENTRY;
1014
1015         LASSERT(ma->ma_lmm_size > 0);
1016
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);
1020         else
1021                 rc = mo_xattr_get(env, o, &LU_BUF_NULL, XATTR_NAME_LMV);
1022
1023         if (rc < 0)
1024                 RETURN(rc);
1025
1026         /* big_lmm may need to be grown */
1027         if (info->eti_big_lmmsize < rc) {
1028                 int size = size_roundup_power2(rc);
1029
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;
1037                 }
1038
1039                 OBD_ALLOC_LARGE(info->eti_big_lmm, size);
1040                 if (!info->eti_big_lmm)
1041                         RETURN(-ENOMEM);
1042                 info->eti_big_lmmsize = size;
1043         }
1044         LASSERT(info->eti_big_lmmsize >= rc);
1045
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);
1050         else
1051                 rc = mo_xattr_get(env, o, &info->eti_buf, XATTR_NAME_LMV);
1052         if (rc < 0)
1053                 RETURN(rc);
1054
1055         if (ma->ma_need & MA_LOV)
1056                 ma->ma_valid |= MA_LOV;
1057         else
1058                 ma->ma_valid |= MA_LMV;
1059
1060         ma->ma_lmm = info->eti_big_lmm;
1061         ma->ma_lmm_size = rc;
1062
1063         RETURN(0);
1064 }
1065
1066 static int echo_attr_get_complex(const struct lu_env *env,
1067                                  struct md_object *next,
1068                                  struct md_attr *ma)
1069 {
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);
1073         int                      rc = 0, rc2;
1074
1075         ENTRY;
1076
1077         ma->ma_valid = 0;
1078
1079         if (ma->ma_need & MA_INODE) {
1080                 rc = mo_attr_get(env, next, ma);
1081                 if (rc)
1082                         GOTO(out, rc);
1083                 ma->ma_valid |= MA_INODE;
1084         }
1085
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);
1091                 if (rc2 > 0) {
1092                         ma->ma_lmm_size = rc2;
1093                         ma->ma_valid |= MA_LOV;
1094                 } else if (rc2 == -ENODATA) {
1095                         /* no LOV EA */
1096                         ma->ma_lmm_size = 0;
1097                 } else if (rc2 == -ERANGE) {
1098                         rc2 = echo_big_lmm_get(env, next, ma);
1099                         if (rc2 < 0)
1100                                 GOTO(out, rc = rc2);
1101                 } else {
1102                         GOTO(out, rc = rc2);
1103                 }
1104         }
1105
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);
1111                 if (rc2 > 0) {
1112                         ma->ma_lmm_size = rc2;
1113                         ma->ma_valid |= MA_LMV;
1114                 } else if (rc2 == -ENODATA) {
1115                         /* no LMV EA */
1116                         ma->ma_lmm_size = 0;
1117                 } else if (rc2 == -ERANGE) {
1118                         rc2 = echo_big_lmm_get(env, next, ma);
1119                         if (rc2 < 0)
1120                                 GOTO(out, rc = rc2);
1121                 } else {
1122                         GOTO(out, rc = rc2);
1123                 }
1124         }
1125
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);
1131                 if (rc2 > 0) {
1132                         ma->ma_acl_size = rc2;
1133                         ma->ma_valid |= MA_ACL_DEF;
1134                 } else if (rc2 == -ENODATA) {
1135                         /* no ACLs */
1136                         ma->ma_acl_size = 0;
1137                 } else {
1138                         GOTO(out, rc = rc2);
1139                 }
1140         }
1141 #endif
1142 out:
1143         CDEBUG(D_INODE, "after getattr rc = %d, ma_valid = %#llx ma_lmm=%p\n",
1144                rc, ma->ma_valid, ma->ma_lmm);
1145         RETURN(rc);
1146 }
1147
1148 static int
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,
1152                         struct md_attr *ma)
1153 {
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 };
1159         int                      rc;
1160
1161         ENTRY;
1162
1163         rc = mdo_lookup(env, parent, lname, fid2, spec);
1164         if (rc == 0)
1165                 return -EEXIST;
1166         else if (rc != -ENOENT)
1167                 return rc;
1168
1169         ec_child = lu_object_find_at(env, &ed->ed_cl.cd_lu_dev,
1170                                      fid, &conf);
1171         if (IS_ERR(ec_child)) {
1172                 CERROR("Can not find the child "DFID": rc = %ld\n", PFID(fid),
1173                         PTR_ERR(ec_child));
1174                 RETURN(PTR_ERR(ec_child));
1175         }
1176
1177         child = lu_object_locate(ec_child->lo_header, ld->ld_type);
1178         if (!child) {
1179                 CERROR("Can not locate the child "DFID"\n", PFID(fid));
1180                 GOTO(out_put, rc = -EINVAL);
1181         }
1182
1183         CDEBUG(D_RPCTRACE, "Start creating object "DFID" %s %p\n",
1184                PFID(lu_object_fid(&parent->mo_lu)), lname->ln_name, parent);
1185
1186         /*
1187          * Do not perform lookup sanity check. We know that name does not exist.
1188          */
1189         spec->sp_cr_lookup = 0;
1190         rc = mdo_create(env, parent, lname, lu2md(child), spec, ma);
1191         if (rc) {
1192                 CERROR("Can not create child "DFID": rc = %d\n", PFID(fid), rc);
1193                 GOTO(out_put, rc);
1194         }
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);
1197         EXIT;
1198 out_put:
1199         lu_object_put(env, ec_child);
1200         return rc;
1201 }
1202
1203 static int echo_set_lmm_size(const struct lu_env *env, struct lu_device *ld,
1204                              struct md_attr *ma)
1205 {
1206         struct echo_thread_info *info = echo_env_info(env);
1207
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);
1211         } else {
1212                 LASSERT(info->eti_big_lmmsize);
1213                 ma->ma_lmm = info->eti_big_lmm;
1214                 ma->ma_lmm_size = info->eti_big_lmmsize;
1215         }
1216
1217         return 0;
1218 }
1219
1220 static int
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)
1225 {
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;
1230         unsigned int            idx;
1231         struct lu_name          tmp_ln_name;
1232         struct lu_fid           stripe_fid;
1233         struct lu_object        *stripe_obj;
1234         int                     rc;
1235
1236         LASSERT(obj != NULL);
1237         LASSERT(S_ISDIR(obj->lo_header->loh_attr));
1238
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);
1243         if (rc) {
1244                 CERROR("Can not getattr child "DFID": rc = %d\n",
1245                         PFID(lu_object_fid(obj)), rc);
1246                 return rc;
1247         }
1248
1249         if (!(ma->ma_valid & MA_LMV)) {
1250                 *new_parent = obj;
1251                 return 0;
1252         }
1253
1254         lmv = (struct lmv_mds_md_v1 *)ma->ma_lmm;
1255         if (!lmv_is_sane(lmv)) {
1256                 rc = -EINVAL;
1257                 CERROR("Invalid mds md magic %x "DFID": rc = %d\n",
1258                        le32_to_cpu(lmv->lmv_magic), PFID(lu_object_fid(obj)),
1259                        rc);
1260                 return rc;
1261         }
1262
1263         if (name) {
1264                 tmp_ln_name.ln_name = name;
1265                 tmp_ln_name.ln_namelen = namelen;
1266         } else {
1267                 LASSERT(id != -1);
1268                 echo_md_build_name(&tmp_ln_name, info->eti_name, id);
1269         }
1270
1271         idx = lmv_name_to_stripe_index(lmv, tmp_ln_name.ln_name,
1272                                        tmp_ln_name.ln_namelen);
1273
1274         LASSERT(idx < le32_to_cpu(lmv->lmv_stripe_count));
1275         fid_le_to_cpu(&stripe_fid, &lmv->lmv_stripe_fids[idx]);
1276
1277         stripe_obj = lu_object_find_at(env, &ed->ed_cl.cd_lu_dev, &stripe_fid,
1278                                        NULL);
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);
1283                 return rc;
1284         }
1285
1286         *new_parent = lu_object_locate(stripe_obj->lo_header, ld->ld_type);
1287         if (!*new_parent) {
1288                 lu_object_put(env, stripe_obj);
1289                 RETURN(-ENXIO);
1290         }
1291
1292         return rc;
1293 }
1294
1295 static int echo_create_md_object(const struct lu_env *env,
1296                                  struct echo_device *ed,
1297                                  struct lu_object *ec_parent,
1298                                  struct lu_fid *fid,
1299                                  char *name, int namelen,
1300                                   __u64 id, __u32 mode, int count,
1301                                  int stripe_count, int stripe_offset)
1302 {
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;
1310         int rc = 0;
1311         int i;
1312
1313         ENTRY;
1314
1315         if (!ec_parent)
1316                 return -1;
1317         parent = lu_object_locate(ec_parent->lo_header, ld->ld_type);
1318         if (!parent)
1319                 RETURN(-ENXIO);
1320
1321         rc = echo_md_dir_stripe_choose(env, ed, parent, name, namelen,
1322                                        id, &new_parent);
1323         if (rc != 0)
1324                 RETURN(rc);
1325
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;
1335
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);
1343                         } else {
1344                                 struct lov_user_md_v3 *lum = &info->eti_lum;
1345
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);
1352                         }
1353                         spec->sp_cr_flags |= MDS_OPEN_HAS_EA;
1354                 }
1355         }
1356
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();
1360
1361         if (name) {
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,
1366                                              lname, spec, ma);
1367                 GOTO(out_put, rc);
1368         }
1369
1370         /* Create multiple object sequenced by id */
1371         for (i = 0; i < count; i++) {
1372                 char *tmp_name = info->eti_name;
1373
1374                 echo_md_build_name(lname, tmp_name, id);
1375
1376                 rc = echo_md_create_internal(env, ed, lu2md(new_parent),
1377                                              fid, lname, spec, ma);
1378                 if (rc) {
1379                         CERROR("Can not create child %s: rc = %d\n", tmp_name,
1380                                 rc);
1381                         break;
1382                 }
1383                 id++;
1384                 fid->f_oid++;
1385         }
1386
1387 out_put:
1388         if (new_parent != parent)
1389                 lu_object_put(env, new_parent);
1390
1391         RETURN(rc);
1392 }
1393
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)
1398 {
1399         struct echo_thread_info *info = echo_env_info(env);
1400         struct lu_fid *fid = &info->eti_fid;
1401         struct lu_object *child;
1402         int rc;
1403
1404         ENTRY;
1405         CDEBUG(D_INFO, "lookup %s in parent "DFID" %p\n", lname->ln_name,
1406                PFID(fid), parent);
1407
1408         rc = mdo_lookup(env, parent, lname, fid, NULL);
1409         if (rc) {
1410                 CERROR("lookup %s: rc = %d\n", lname->ln_name, rc);
1411                 RETURN(ERR_PTR(rc));
1412         }
1413
1414         /*
1415          * In the function below, .hs_keycmp resolves to
1416          * lu_obj_hop_keycmp()
1417          */
1418         /* coverity[overrun-buffer-val] */
1419         child = lu_object_find_at(env, &ed->ed_cl.cd_lu_dev, fid, NULL);
1420
1421         RETURN(child);
1422 }
1423
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)
1428 {
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;
1436         int rc = 0;
1437         int i;
1438
1439         ENTRY;
1440
1441         if (!ec_parent)
1442                 return -1;
1443         parent = lu_object_locate(ec_parent->lo_header, ld->ld_type);
1444         if (!parent)
1445                 RETURN(-ENXIO);
1446
1447         rc = echo_md_dir_stripe_choose(env, ed, parent, NULL, 0, id,
1448                                        &new_parent);
1449         if (rc != 0)
1450                 RETURN(rc);
1451
1452         for (i = 0; i < count; i++) {
1453                 struct lu_object *ec_child, *child;
1454
1455                 echo_md_build_name(lname, name, id);
1456
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);
1462                         break;
1463                 }
1464
1465                 child = lu_object_locate(ec_child->lo_header, ld->ld_type);
1466                 if (!child) {
1467                         CERROR("Can not locate the child %s\n", lname->ln_name);
1468                         lu_object_put(env, ec_child);
1469                         rc = -EINVAL;
1470                         break;
1471                 }
1472
1473                 CDEBUG(D_RPCTRACE, "Start setattr object "DFID"\n",
1474                        PFID(lu_object_fid(child)));
1475
1476                 buf->lb_buf = info->eti_xattr_buf;
1477                 buf->lb_len = sizeof(info->eti_xattr_buf);
1478
1479                 sprintf(name, "%s.test1", XATTR_USER_PREFIX);
1480                 rc = mo_xattr_set(env, lu2md(child), buf, name,
1481                                   LU_XATTR_CREATE);
1482                 if (rc < 0) {
1483                         CERROR("Can not setattr child "DFID": rc = %d\n",
1484                                 PFID(lu_object_fid(child)), rc);
1485                         lu_object_put(env, ec_child);
1486                         break;
1487                 }
1488                 CDEBUG(D_RPCTRACE, "End setattr object "DFID"\n",
1489                        PFID(lu_object_fid(child)));
1490                 id++;
1491                 lu_object_put(env, ec_child);
1492         }
1493
1494         if (new_parent != parent)
1495                 lu_object_put(env, new_parent);
1496
1497         RETURN(rc);
1498 }
1499
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)
1504 {
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;
1512         int rc = 0;
1513         int i;
1514
1515         ENTRY;
1516
1517         if (!ec_parent)
1518                 return -1;
1519         parent = lu_object_locate(ec_parent->lo_header, ld->ld_type);
1520         if (!parent)
1521                 RETURN(-ENXIO);
1522
1523         rc = echo_md_dir_stripe_choose(env, ed, parent, NULL, 0, id,
1524                                        &new_parent);
1525         if (rc != 0)
1526                 RETURN(rc);
1527
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);
1532
1533         for (i = 0; i < count; i++) {
1534                 struct lu_object *ec_child, *child;
1535
1536                 ma->ma_valid = 0;
1537                 echo_md_build_name(lname, name, id);
1538                 echo_set_lmm_size(env, ld, ma);
1539
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));
1545                 }
1546
1547                 child = lu_object_locate(ec_child->lo_header, ld->ld_type);
1548                 if (!child) {
1549                         CERROR("Can not locate the child %s\n", lname->ln_name);
1550                         lu_object_put(env, ec_child);
1551                         RETURN(-EINVAL);
1552                 }
1553
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);
1557                 if (rc) {
1558                         CERROR("Can not getattr child "DFID": rc = %d\n",
1559                                 PFID(lu_object_fid(child)), rc);
1560                         lu_object_put(env, ec_child);
1561                         break;
1562                 }
1563                 CDEBUG(D_RPCTRACE, "End getattr object "DFID"\n",
1564                        PFID(lu_object_fid(child)));
1565                 id++;
1566                 lu_object_put(env, ec_child);
1567         }
1568
1569         if (new_parent != parent)
1570                 lu_object_put(env, new_parent);
1571
1572         RETURN(rc);
1573 }
1574
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)
1579 {
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;
1587         int rc = 0;
1588         int i;
1589
1590         if (!ec_parent)
1591                 return -1;
1592         parent = lu_object_locate(ec_parent->lo_header, ld->ld_type);
1593         if (!parent)
1594                 return -ENXIO;
1595
1596         rc = echo_md_dir_stripe_choose(env, ed, parent, NULL, 0, id,
1597                                        &new_parent);
1598         if (rc != 0)
1599                 RETURN(rc);
1600
1601         /*prepare the requests*/
1602         for (i = 0; i < count; i++) {
1603                 echo_md_build_name(lname, name, id);
1604
1605                 CDEBUG(D_RPCTRACE, "Start lookup object "DFID" %s %p\n",
1606                        PFID(lu_object_fid(new_parent)), lname->ln_name,
1607                        new_parent);
1608
1609                 rc = mdo_lookup(env, lu2md(new_parent), lname, fid, NULL);
1610                 if (rc) {
1611                         CERROR("Can not lookup child %s: rc = %d\n", name, rc);
1612                         break;
1613                 }
1614
1615                 CDEBUG(D_RPCTRACE, "End lookup object "DFID" %s %p\n",
1616                        PFID(lu_object_fid(new_parent)), lname->ln_name,
1617                        new_parent);
1618
1619                 id++;
1620         }
1621
1622         if (new_parent != parent)
1623                 lu_object_put(env, new_parent);
1624
1625         return rc;
1626 }
1627
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,
1632                                     struct md_attr *ma)
1633 {
1634         struct lu_device   *ld = ed->ed_next;
1635         struct lu_object   *ec_child;
1636         struct lu_object   *child;
1637         int                 rc;
1638
1639         ENTRY;
1640
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,
1644                         PTR_ERR(ec_child));
1645                 RETURN(PTR_ERR(ec_child));
1646         }
1647
1648         child = lu_object_locate(ec_child->lo_header, ld->ld_type);
1649         if (!child) {
1650                 CERROR("Can not locate the child %s\n", lname->ln_name);
1651                 GOTO(out_put, rc = -EINVAL);
1652         }
1653
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);
1658         }
1659         CDEBUG(D_RPCTRACE, "Start destroy object "DFID" %s %p\n",
1660                PFID(lu_object_fid(&parent->mo_lu)), lname->ln_name, parent);
1661
1662         rc = mdo_unlink(env, parent, lu2md(child), lname, ma, 0);
1663         if (rc) {
1664                 CERROR("Can not unlink child %s: rc = %d\n",
1665                         lname->ln_name, rc);
1666                 GOTO(out_put, rc);
1667         }
1668         CDEBUG(D_RPCTRACE, "End destroy object "DFID" %s %p\n",
1669                PFID(lu_object_fid(&parent->mo_lu)), lname->ln_name, parent);
1670 out_put:
1671         lu_object_put(env, ec_child);
1672         return rc;
1673 }
1674
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,
1680                                int count)
1681 {
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;
1688         int                      rc = 0;
1689         int                      i;
1690
1691         ENTRY;
1692         parent = lu_object_locate(ec_parent->lo_header, ld->ld_type);
1693         if (!parent)
1694                 RETURN(-EINVAL);
1695
1696         rc = echo_md_dir_stripe_choose(env, ed, parent, name, namelen,
1697                                        id, &new_parent);
1698         if (rc != 0)
1699                 RETURN(rc);
1700
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;
1706         ma->ma_valid = 0;
1707
1708         if (name) {
1709                 lname->ln_name = name;
1710                 lname->ln_namelen = namelen;
1711                 rc = echo_md_destroy_internal(env, ed, lu2md(new_parent), lname,
1712                                               ma);
1713                 GOTO(out_put, rc);
1714         }
1715
1716         /*prepare the requests*/
1717         for (i = 0; i < count; i++) {
1718                 char *tmp_name = info->eti_name;
1719
1720                 ma->ma_valid = 0;
1721                 echo_md_build_name(lname, tmp_name, id);
1722
1723                 rc = echo_md_destroy_internal(env, ed, lu2md(new_parent), lname,
1724                                               ma);
1725                 if (rc) {
1726                         CERROR("Can not unlink child %s: rc = %d\n", name, rc);
1727                         break;
1728                 }
1729                 id++;
1730         }
1731
1732 out_put:
1733         if (new_parent != parent)
1734                 lu_object_put(env, new_parent);
1735
1736         RETURN(rc);
1737 }
1738
1739 static struct lu_object *echo_resolve_path(const struct lu_env *env,
1740                                            struct echo_device *ed, char *path,
1741                                            int path_len)
1742 {
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;
1749         int                      rc = 0;
1750
1751         ENTRY;
1752         *fid = ed->ed_root_fid;
1753
1754         /*
1755          * In the function below, .hs_keycmp resolves to
1756          * lu_obj_hop_keycmp()
1757          */
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));
1763                 RETURN(parent);
1764         }
1765
1766         while (1) {
1767                 struct lu_object *ld_parent;
1768                 char *e;
1769
1770                 e = strsep(&path, "/");
1771                 if (!e)
1772                         break;
1773
1774                 if (e[0] == 0) {
1775                         if (!path || path[0] == '\0')
1776                                 break;
1777                         continue;
1778                 }
1779
1780                 lname->ln_name = e;
1781                 lname->ln_namelen = strlen(e);
1782
1783                 ld_parent = lu_object_locate(parent->lo_header, ld->ld_type);
1784                 if (!ld_parent) {
1785                         lu_object_put(env, parent);
1786                         rc = -EINVAL;
1787                         break;
1788                 }
1789
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)),
1796                                 rc);
1797                         break;
1798                 }
1799                 parent = child;
1800         }
1801         if (rc)
1802                 RETURN(ERR_PTR(rc));
1803
1804         RETURN(parent);
1805 }
1806
1807 static void echo_ucred_init(struct lu_env *env)
1808 {
1809         struct lu_ucred *ucred = lu_ucred(env);
1810         kernel_cap_t kcap = current_cap();
1811
1812         ucred->uc_valid = UCRED_INVALID;
1813
1814         ucred->uc_suppgids[0] = -1;
1815         ucred->uc_suppgids[1] = -1;
1816
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();
1826
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);
1831         }
1832         ucred->uc_cap = kcap;
1833         ucred->uc_valid = UCRED_NEW;
1834 }
1835
1836 static void echo_ucred_fini(struct lu_env *env)
1837 {
1838         struct lu_ucred *ucred = lu_ucred(env);
1839
1840         ucred->uc_valid = UCRED_INIT;
1841 }
1842
1843 static int echo_md_handler(struct echo_device *ed, int command,
1844                            char *path, int path_len, __u64 id, int count,
1845                            struct obd_ioctl_data *data)
1846 {
1847         struct echo_thread_info *info;
1848         struct lu_device *ld = ed->ed_next;
1849         struct lu_env *env;
1850         __u16 refcheck;
1851         struct lu_object *parent;
1852         char *name = NULL;
1853         int namelen = data->ioc_plen2;
1854         int rc = 0;
1855
1856         ENTRY;
1857         if (!ld) {
1858                 CERROR("MD echo client is not being initialized properly\n");
1859                 RETURN(-EINVAL);
1860         }
1861
1862         if (strcmp(ld->ld_type->ldt_name, LUSTRE_MDD_NAME)) {
1863                 CERROR("Only support MDD layer right now!\n");
1864                 RETURN(-EINVAL);
1865         }
1866
1867         env = cl_env_get(&refcheck);
1868         if (IS_ERR(env))
1869                 RETURN(PTR_ERR(env));
1870
1871         rc = lu_env_refill_by_tags(env, ECHO_MD_CTX_TAG, ECHO_SES_TAG);
1872         if (rc != 0)
1873                 GOTO(out_env, rc);
1874
1875         /* init big_lmm buffer */
1876         info = echo_env_info(env);
1877         LASSERT(info->eti_big_lmm == NULL);
1878         OBD_ALLOC_LARGE(info->eti_big_lmm, MIN_MD_SIZE);
1879         if (!info->eti_big_lmm)
1880                 GOTO(out_env, rc = -ENOMEM);
1881         info->eti_big_lmmsize = MIN_MD_SIZE;
1882
1883         parent = echo_resolve_path(env, ed, path, path_len);
1884         if (IS_ERR(parent)) {
1885                 CERROR("Can not resolve the path %s: rc = %ld\n", path,
1886                         PTR_ERR(parent));
1887                 GOTO(out_free, rc = PTR_ERR(parent));
1888         }
1889
1890         if (namelen > 0) {
1891                 OBD_ALLOC(name, namelen + 1);
1892                 if (!name)
1893                         GOTO(out_put, rc = -ENOMEM);
1894                 if (copy_from_user(name, data->ioc_pbuf2, namelen))
1895                         GOTO(out_name, rc = -EFAULT);
1896         }
1897
1898         echo_ucred_init(env);
1899
1900         switch (command) {
1901         case ECHO_MD_CREATE:
1902         case ECHO_MD_MKDIR: {
1903                 struct echo_thread_info *info = echo_env_info(env);
1904                 __u32 mode = data->ioc_obdo2.o_mode;
1905                 struct lu_fid *fid = &info->eti_fid;
1906                 int stripe_count = (int)data->ioc_obdo2.o_misc;
1907                 int stripe_index = (int)data->ioc_obdo2.o_stripe_idx;
1908
1909                 rc = ostid_to_fid(fid, &data->ioc_obdo1.o_oi, 0);
1910                 if (rc != 0)
1911                         break;
1912
1913                 /*
1914                  * In the function below, .hs_keycmp resolves to
1915                  * lu_obj_hop_keycmp()
1916                  */
1917                 /* coverity[overrun-buffer-val] */
1918                 rc = echo_create_md_object(env, ed, parent, fid, name, namelen,
1919                                            id, mode, count, stripe_count,
1920                                            stripe_index);
1921                 break;
1922         }
1923         case ECHO_MD_DESTROY:
1924         case ECHO_MD_RMDIR: {
1925                 __u32 mode = data->ioc_obdo2.o_mode;
1926
1927                 rc = echo_destroy_object(env, ed, parent, name, namelen,
1928                                          id, mode, count);
1929                 break;
1930         }
1931         case ECHO_MD_LOOKUP:
1932                 rc = echo_lookup_object(env, ed, parent, id, count);
1933                 break;
1934         case ECHO_MD_GETATTR:
1935                 rc = echo_getattr_object(env, ed, parent, id, count);
1936                 break;
1937         case ECHO_MD_SETATTR:
1938                 rc = echo_setattr_object(env, ed, parent, id, count);
1939                 break;
1940         default:
1941                 CERROR("unknown command %d\n", command);
1942                 rc = -EINVAL;
1943                 break;
1944         }
1945         echo_ucred_fini(env);
1946
1947 out_name:
1948         if (name)
1949                 OBD_FREE(name, namelen + 1);
1950 out_put:
1951         lu_object_put(env, parent);
1952 out_free:
1953         LASSERT(info->eti_big_lmm);
1954         OBD_FREE_LARGE(info->eti_big_lmm, info->eti_big_lmmsize);
1955         info->eti_big_lmm = NULL;
1956         info->eti_big_lmmsize = 0;
1957 out_env:
1958         cl_env_put(env, &refcheck);
1959         return rc;
1960 }
1961 #endif /* HAVE_SERVER_SUPPORT */
1962
1963 static int echo_create_object(const struct lu_env *env, struct echo_device *ed,
1964                               struct obdo *oa)
1965 {
1966         struct echo_object      *eco;
1967         struct echo_client_obd  *ec = ed->ed_ec;
1968         int created = 0;
1969         int rc;
1970
1971         ENTRY;
1972         if (!(oa->o_valid & OBD_MD_FLID) ||
1973             !(oa->o_valid & OBD_MD_FLGROUP) ||
1974             !fid_seq_is_echo(ostid_seq(&oa->o_oi))) {
1975                 CERROR("invalid oid "DOSTID"\n", POSTID(&oa->o_oi));
1976                 RETURN(-EINVAL);
1977         }
1978
1979         if (ostid_id(&oa->o_oi) == 0) {
1980                 rc = ostid_set_id(&oa->o_oi, ++last_object_id);
1981                 if (rc)
1982                         GOTO(failed, rc);
1983         }
1984
1985         rc = obd_create(env, ec->ec_exp, oa);
1986         if (rc != 0) {
1987                 CERROR("Cannot create objects: rc = %d\n", rc);
1988                 GOTO(failed, rc);
1989         }
1990
1991         created = 1;
1992
1993         oa->o_valid |= OBD_MD_FLID;
1994
1995         eco = cl_echo_object_find(ed, &oa->o_oi);
1996         if (IS_ERR(eco))
1997                 GOTO(failed, rc = PTR_ERR(eco));
1998         cl_echo_object_put(eco);
1999
2000         CDEBUG(D_INFO, "oa oid "DOSTID"\n", POSTID(&oa->o_oi));
2001         EXIT;
2002
2003 failed:
2004         if (created && rc != 0)
2005                 obd_destroy(env, ec->ec_exp, oa);
2006
2007         if (rc != 0)
2008                 CERROR("create object failed with: rc = %d\n", rc);
2009
2010         return rc;
2011 }
2012
2013 static int echo_get_object(struct echo_object **ecop, struct echo_device *ed,
2014                            struct obdo *oa)
2015 {
2016         struct echo_object *eco;
2017         int rc;
2018
2019         ENTRY;
2020         if (!(oa->o_valid & OBD_MD_FLID) ||
2021             !(oa->o_valid & OBD_MD_FLGROUP) ||
2022             ostid_id(&oa->o_oi) == 0) {
2023                 CERROR("invalid oid "DOSTID"\n", POSTID(&oa->o_oi));
2024                 RETURN(-EINVAL);
2025         }
2026
2027         rc = 0;
2028         eco = cl_echo_object_find(ed, &oa->o_oi);
2029         if (!IS_ERR(eco))
2030                 *ecop = eco;
2031         else
2032                 rc = PTR_ERR(eco);
2033
2034         RETURN(rc);
2035 }
2036
2037 static void echo_put_object(struct echo_object *eco)
2038 {
2039         int rc;
2040
2041         rc = cl_echo_object_put(eco);
2042         if (rc)
2043                 CERROR("%s: echo client drop an object failed: rc = %d\n",
2044                        eco->eo_dev->ed_ec->ec_exp->exp_obd->obd_name, rc);
2045 }
2046
2047 static void echo_client_page_debug_setup(struct page *page, int rw, u64 id,
2048                                          u64 offset, u64 count)
2049 {
2050         char *addr;
2051         u64 stripe_off;
2052         u64 stripe_id;
2053         int delta;
2054
2055         /* no partial pages on the client */
2056         LASSERT(count == PAGE_SIZE);
2057
2058         addr = kmap(page);
2059
2060         for (delta = 0; delta < PAGE_SIZE; delta += OBD_ECHO_BLOCK_SIZE) {
2061                 if (rw == OBD_BRW_WRITE) {
2062                         stripe_off = offset + delta;
2063                         stripe_id = id;
2064                 } else {
2065                         stripe_off = 0xdeadbeef00c0ffeeULL;
2066                         stripe_id = 0xdeadbeef00c0ffeeULL;
2067                 }
2068                 block_debug_setup(addr + delta, OBD_ECHO_BLOCK_SIZE,
2069                                   stripe_off, stripe_id);
2070         }
2071
2072         kunmap(page);
2073 }
2074
2075 static int
2076 echo_client_page_debug_check(struct page *page, u64 id, u64 offset, u64 count)
2077 {
2078         u64 stripe_off;
2079         u64 stripe_id;
2080         char *addr;
2081         int delta;
2082         int rc;
2083         int rc2;
2084
2085         /* no partial pages on the client */
2086         LASSERT(count == PAGE_SIZE);
2087
2088         addr = kmap(page);
2089
2090         for (rc = delta = 0; delta < PAGE_SIZE; delta += OBD_ECHO_BLOCK_SIZE) {
2091                 stripe_off = offset + delta;
2092                 stripe_id = id;
2093
2094                 rc2 = block_debug_check("test_brw",
2095                                         addr + delta, OBD_ECHO_BLOCK_SIZE,
2096                                         stripe_off, stripe_id);
2097                 if (rc2 != 0) {
2098                         CERROR("Error in echo object %#llx\n", id);
2099                         rc = rc2;
2100                 }
2101         }
2102
2103         kunmap(page);
2104         return rc;
2105 }
2106
2107 static int echo_client_prep_commit(const struct lu_env *env,
2108                                    struct obd_export *exp, int rw,
2109                                    struct obdo *oa, struct echo_object *eco,
2110                                    u64 offset, u64 count,
2111                                    u64 batch, int async)
2112 {
2113         struct obd_ioobj ioo;
2114         struct niobuf_local *lnb;
2115         struct niobuf_remote rnb;
2116         u64 off;
2117         u64 npages, tot_pages, apc;
2118         int i, ret = 0, brw_flags = 0;
2119
2120         ENTRY;
2121         if (count <= 0 || (count & ~PAGE_MASK) != 0)
2122                 RETURN(-EINVAL);
2123
2124         apc = npages = batch >> PAGE_SHIFT;
2125         tot_pages = count >> PAGE_SHIFT;
2126
2127         OBD_ALLOC_PTR_ARRAY_LARGE(lnb, apc);
2128         if (!lnb)
2129                 RETURN(-ENOMEM);
2130
2131         if (rw == OBD_BRW_WRITE && async)
2132                 brw_flags |= OBD_BRW_ASYNC;
2133
2134         obdo_to_ioobj(oa, &ioo);
2135
2136         off = offset;
2137
2138         for (; tot_pages > 0; tot_pages -= npages) {
2139                 int lpages;
2140
2141                 if (tot_pages < npages)
2142                         npages = tot_pages;
2143
2144                 rnb.rnb_offset = off;
2145                 rnb.rnb_len = npages * PAGE_SIZE;
2146                 rnb.rnb_flags = brw_flags;
2147                 ioo.ioo_bufcnt = 1;
2148                 off += npages * PAGE_SIZE;
2149
2150                 lpages = npages;
2151                 ret = obd_preprw(env, rw, exp, oa, 1, &ioo, &rnb, &lpages, lnb);
2152                 if (ret != 0)
2153                         GOTO(out, ret);
2154
2155                 for (i = 0; i < lpages; i++) {
2156                         struct page *page = lnb[i].lnb_page;
2157
2158                         /* read past eof? */
2159                         if (!page && lnb[i].lnb_rc == 0)
2160                                 continue;
2161
2162                         if (async)
2163                                 lnb[i].lnb_flags |= OBD_BRW_ASYNC;
2164
2165                         if (ostid_id(&oa->o_oi) == ECHO_PERSISTENT_OBJID ||
2166                             (oa->o_valid & OBD_MD_FLFLAGS) == 0 ||
2167                             (oa->o_flags & OBD_FL_DEBUG_CHECK) == 0)
2168                                 continue;
2169
2170                         if (rw == OBD_BRW_WRITE)
2171                                 echo_client_page_debug_setup(page, rw,
2172                                                         ostid_id(&oa->o_oi),
2173                                                         lnb[i].lnb_file_offset,
2174                                                         lnb[i].lnb_len);
2175                         else
2176                                 echo_client_page_debug_check(page,
2177                                                         ostid_id(&oa->o_oi),
2178                                                         lnb[i].lnb_file_offset,
2179                                                         lnb[i].lnb_len);
2180                 }
2181
2182                 ret = obd_commitrw(env, rw, exp, oa, 1, &ioo, &rnb, npages, lnb,
2183                                    ret, rnb.rnb_len, ktime_set(0, 0));
2184                 if (ret != 0)
2185                         break;
2186
2187                 /* Reuse env context. */
2188                 lu_context_exit((struct lu_context *)&env->le_ctx);
2189                 lu_context_enter((struct lu_context *)&env->le_ctx);
2190         }
2191
2192 out:
2193         OBD_FREE_PTR_ARRAY_LARGE(lnb, apc);
2194
2195         RETURN(ret);
2196 }
2197
2198 static int echo_client_brw_ioctl(const struct lu_env *env, int rw,
2199                                  struct obd_export *exp,
2200                                  struct obd_ioctl_data *data)
2201 {
2202         struct obd_device *obd = class_exp2obd(exp);
2203         struct echo_device *ed = obd2echo_dev(obd);
2204         struct echo_client_obd *ec = ed->ed_ec;
2205         struct obdo *oa = &data->ioc_obdo1;
2206         struct echo_object *eco;
2207         int rc;
2208         int async = 0;
2209         long test_mode;
2210
2211         ENTRY;
2212         LASSERT(oa->o_valid & OBD_MD_FLGROUP);
2213
2214         rc = echo_get_object(&eco, ed, oa);
2215         if (rc)
2216                 RETURN(rc);
2217
2218         oa->o_valid &= ~OBD_MD_FLHANDLE;
2219
2220         /* OFD/obdfilter works only via prep/commit */
2221         test_mode = (long)data->ioc_pbuf1;
2222         if (!ed->ed_next && test_mode != 3) {
2223                 test_mode = 3;
2224                 data->ioc_plen1 = data->ioc_count;
2225         }
2226
2227         if (test_mode == 3)
2228                 async = 1;
2229
2230         /* Truncate batch size to maximum */
2231         if (data->ioc_plen1 > PTLRPC_MAX_BRW_SIZE)
2232                 data->ioc_plen1 = PTLRPC_MAX_BRW_SIZE;
2233
2234         switch (test_mode) {
2235         case 3:
2236                 rc = echo_client_prep_commit(env, ec->ec_exp, rw, oa, eco,
2237                                              data->ioc_offset, data->ioc_count,
2238                                              data->ioc_plen1, async);
2239                 break;
2240         default:
2241                 rc = -EINVAL;
2242         }
2243
2244         echo_put_object(eco);
2245
2246         RETURN(rc);
2247 }
2248
2249 static int
2250 echo_client_iocontrol(unsigned int cmd, struct obd_export *exp, int len,
2251                       void *karg, void __user *uarg)
2252 {
2253 #ifdef HAVE_SERVER_SUPPORT
2254         struct tgt_session_info *tsi;
2255 #endif
2256         struct obd_device      *obd = exp->exp_obd;
2257         struct echo_device     *ed = obd2echo_dev(obd);
2258         struct echo_client_obd *ec = ed->ed_ec;
2259         struct echo_object     *eco;
2260         struct obd_ioctl_data  *data = karg;
2261         struct lu_env          *env;
2262         unsigned long           env_tags = 0;
2263         __u16                   refcheck;
2264         struct obdo            *oa;
2265         struct lu_fid           fid;
2266         int                     rw = OBD_BRW_READ;
2267         int                     rc = 0;
2268
2269         ENTRY;
2270         oa = &data->ioc_obdo1;
2271         if (!(oa->o_valid & OBD_MD_FLGROUP)) {
2272                 oa->o_valid |= OBD_MD_FLGROUP;
2273                 ostid_set_seq_echo(&oa->o_oi);
2274         }
2275
2276         /* This FID is unpacked just for validation at this point */
2277         rc = ostid_to_fid(&fid, &oa->o_oi, 0);
2278         if (rc < 0)
2279                 RETURN(rc);
2280
2281         env = cl_env_get(&refcheck);
2282         if (IS_ERR(env))
2283                 RETURN(PTR_ERR(env));
2284
2285         lu_env_add(env);
2286
2287 #ifdef HAVE_SERVER_SUPPORT
2288         if (cmd == OBD_IOC_ECHO_MD || cmd == OBD_IOC_ECHO_ALLOC_SEQ)
2289                 env_tags = ECHO_MD_CTX_TAG;
2290         else
2291 #endif
2292                 env_tags = ECHO_DT_CTX_TAG;
2293
2294         rc = lu_env_refill_by_tags(env, env_tags, ECHO_SES_TAG);
2295         if (rc != 0)
2296                 GOTO(out, rc);
2297
2298 #ifdef HAVE_SERVER_SUPPORT
2299         tsi = tgt_ses_info(env);
2300         /* treat as local operation */
2301         tsi->tsi_exp = NULL;
2302         tsi->tsi_jobid = NULL;
2303 #endif
2304
2305         switch (cmd) {
2306         case OBD_IOC_CREATE:                    /* may create echo object */
2307                 if (!capable(CAP_SYS_ADMIN))
2308                         GOTO(out, rc = -EPERM);
2309
2310                 rc = echo_create_object(env, ed, oa);
2311                 GOTO(out, rc);
2312
2313 #ifdef HAVE_SERVER_SUPPORT
2314         case OBD_IOC_ECHO_MD: {
2315                 int count;
2316                 int cmd;
2317                 char *dir = NULL;
2318                 int dirlen;
2319                 __u64 id;
2320
2321                 if (!capable(CAP_SYS_ADMIN))
2322                         GOTO(out, rc = -EPERM);
2323
2324                 count = data->ioc_count;
2325                 cmd = data->ioc_command;
2326
2327                 id = data->ioc_obdo2.o_oi.oi.oi_id;
2328                 dirlen = data->ioc_plen1;
2329                 OBD_ALLOC(dir, dirlen + 1);
2330                 if (!dir)
2331                         GOTO(out, rc = -ENOMEM);
2332
2333                 if (copy_from_user(dir, data->ioc_pbuf1, dirlen)) {
2334                         OBD_FREE(dir, data->ioc_plen1 + 1);
2335                         GOTO(out, rc = -EFAULT);
2336                 }
2337
2338                 rc = echo_md_handler(ed, cmd, dir, dirlen, id, count, data);
2339                 OBD_FREE(dir, dirlen + 1);
2340                 GOTO(out, rc);
2341         }
2342         case OBD_IOC_ECHO_ALLOC_SEQ: {
2343                 __u64            seq;
2344                 int              max_count;
2345
2346                 if (!capable(CAP_SYS_ADMIN))
2347                         GOTO(out, rc = -EPERM);
2348
2349                 rc = seq_client_get_seq(env, ed->ed_cl_seq, &seq);
2350                 if (rc < 0) {
2351                         CERROR("%s: Can not alloc seq: rc = %d\n",
2352                                obd->obd_name, rc);
2353                         GOTO(out, rc);
2354                 }
2355
2356                 if (copy_to_user(data->ioc_pbuf1, &seq, data->ioc_plen1))
2357                         return -EFAULT;
2358
2359                 max_count = LUSTRE_METADATA_SEQ_MAX_WIDTH;
2360                 if (copy_to_user(data->ioc_pbuf2, &max_count,
2361                                      data->ioc_plen2))
2362                         return -EFAULT;
2363                 GOTO(out, rc);
2364         }
2365 #endif /* HAVE_SERVER_SUPPORT */
2366         case OBD_IOC_DESTROY:
2367                 if (!capable(CAP_SYS_ADMIN))
2368                         GOTO(out, rc = -EPERM);
2369
2370                 rc = echo_get_object(&eco, ed, oa);
2371                 if (rc == 0) {
2372                         rc = obd_destroy(env, ec->ec_exp, oa);
2373                         if (rc == 0)
2374                                 eco->eo_deleted = 1;
2375                         echo_put_object(eco);
2376                 }
2377                 GOTO(out, rc);
2378
2379         case OBD_IOC_GETATTR:
2380                 rc = echo_get_object(&eco, ed, oa);
2381                 if (rc == 0) {
2382                         rc = obd_getattr(env, ec->ec_exp, oa);
2383                         echo_put_object(eco);
2384                 }
2385                 GOTO(out, rc);
2386
2387         case OBD_IOC_SETATTR:
2388                 if (!capable(CAP_SYS_ADMIN))
2389                         GOTO(out, rc = -EPERM);
2390
2391                 rc = echo_get_object(&eco, ed, oa);
2392                 if (rc == 0) {
2393                         rc = obd_setattr(env, ec->ec_exp, oa);
2394                         echo_put_object(eco);
2395                 }
2396                 GOTO(out, rc);
2397
2398         case OBD_IOC_BRW_WRITE:
2399                 if (!capable(CAP_SYS_ADMIN))
2400                         GOTO(out, rc = -EPERM);
2401
2402                 rw = OBD_BRW_WRITE;
2403                 fallthrough;
2404         case OBD_IOC_BRW_READ:
2405                 rc = echo_client_brw_ioctl(env, rw, exp, data);
2406                 GOTO(out, rc);
2407
2408         default:
2409                 CERROR("echo_ioctl(): unrecognised ioctl %#x\n", cmd);
2410                 GOTO(out, rc = -ENOTTY);
2411         }
2412
2413         EXIT;
2414 out:
2415         lu_env_remove(env);
2416         cl_env_put(env, &refcheck);
2417
2418         return rc;
2419 }
2420
2421 static int echo_client_setup(const struct lu_env *env,
2422                              struct obd_device *obd, struct lustre_cfg *lcfg)
2423 {
2424         struct echo_client_obd *ec = &obd->u.echo_client;
2425         struct obd_device *tgt;
2426         struct obd_uuid echo_uuid = { "ECHO_UUID" };
2427         struct obd_connect_data *ocd = NULL;
2428         int rc;
2429
2430         ENTRY;
2431         if (lcfg->lcfg_bufcount < 2 || LUSTRE_CFG_BUFLEN(lcfg, 1) < 1) {
2432                 CERROR("requires a TARGET OBD name\n");
2433                 RETURN(-EINVAL);
2434         }
2435
2436         tgt = class_name2obd(lustre_cfg_string(lcfg, 1));
2437         if (!tgt || !tgt->obd_attached || !tgt->obd_set_up) {
2438                 CERROR("device not attached or not set up (%s)\n",
2439                        lustre_cfg_string(lcfg, 1));
2440                 RETURN(-EINVAL);
2441         }
2442
2443         spin_lock_init(&ec->ec_lock);
2444         INIT_LIST_HEAD(&ec->ec_objects);
2445         INIT_LIST_HEAD(&ec->ec_locks);
2446         ec->ec_unique = 0;
2447
2448         lu_context_tags_update(ECHO_DT_CTX_TAG);
2449         lu_session_tags_update(ECHO_SES_TAG);
2450
2451         if (!strcmp(tgt->obd_type->typ_name, LUSTRE_MDT_NAME)) {
2452 #ifdef HAVE_SERVER_SUPPORT
2453                 lu_context_tags_update(ECHO_MD_CTX_TAG);
2454 #else
2455                 CERROR(
2456                        "Local operations are NOT supported on client side. Only remote operations are supported. Metadata client must be run on server side.\n");
2457 #endif
2458                 RETURN(0);
2459         }
2460
2461         OBD_ALLOC(ocd, sizeof(*ocd));
2462         if (!ocd) {
2463                 CERROR("Can't alloc ocd connecting to %s\n",
2464                        lustre_cfg_string(lcfg, 1));
2465                 return -ENOMEM;
2466         }
2467
2468         ocd->ocd_connect_flags = OBD_CONNECT_VERSION | OBD_CONNECT_REQPORTAL |
2469                                  OBD_CONNECT_BRW_SIZE |
2470                                  OBD_CONNECT_GRANT | OBD_CONNECT_FULL20 |
2471                                  OBD_CONNECT_64BITHASH | OBD_CONNECT_LVB_TYPE |
2472                                  OBD_CONNECT_FID | OBD_CONNECT_FLAGS2;
2473         ocd->ocd_connect_flags2 = OBD_CONNECT2_REP_MBITS;
2474
2475         ocd->ocd_brw_size = DT_MAX_BRW_SIZE;
2476         ocd->ocd_version = LUSTRE_VERSION_CODE;
2477         ocd->ocd_group = FID_SEQ_ECHO;
2478
2479         rc = obd_connect(env, &ec->ec_exp, tgt, &echo_uuid, ocd, NULL);
2480         if (rc == 0) {
2481                 /* Turn off pinger because it connects to tgt obd directly. */
2482                 spin_lock(&tgt->obd_dev_lock);
2483                 list_del_init(&ec->ec_exp->exp_obd_chain_timed);
2484                 spin_unlock(&tgt->obd_dev_lock);
2485         }
2486
2487         OBD_FREE(ocd, sizeof(*ocd));
2488
2489         if (rc != 0) {
2490                 CERROR("fail to connect to device %s\n",
2491                        lustre_cfg_string(lcfg, 1));
2492                 return rc;
2493         }
2494
2495         RETURN(rc);
2496 }
2497
2498 static int echo_client_cleanup(struct obd_device *obd)
2499 {
2500         struct echo_device *ed = obd2echo_dev(obd);
2501         struct echo_client_obd *ec = &obd->u.echo_client;
2502         int rc;
2503
2504         ENTRY;
2505         /*Do nothing for Metadata echo client*/
2506         if (!ed)
2507                 RETURN(0);
2508
2509         lu_session_tags_clear(ECHO_SES_TAG & ~LCT_SESSION);
2510         lu_context_tags_clear(ECHO_DT_CTX_TAG);
2511         if (ed->ed_next_ismd) {
2512 #ifdef HAVE_SERVER_SUPPORT
2513                 lu_context_tags_clear(ECHO_MD_CTX_TAG);
2514 #else
2515                 CERROR(
2516                        "This is client-side only module, does not support metadata echo client.\n");
2517 #endif
2518                 RETURN(0);
2519         }
2520
2521         if (!list_empty(&obd->obd_exports)) {
2522                 CERROR("still has clients!\n");
2523                 RETURN(-EBUSY);
2524         }
2525
2526         LASSERT(refcount_read(&ec->ec_exp->exp_handle.h_ref) > 0);
2527         rc = obd_disconnect(ec->ec_exp);
2528         if (rc != 0)
2529                 CERROR("fail to disconnect device: %d\n", rc);
2530
2531         RETURN(rc);
2532 }
2533
2534 static int echo_client_connect(const struct lu_env *env,
2535                                struct obd_export **exp,
2536                                struct obd_device *src, struct obd_uuid *cluuid,
2537                                struct obd_connect_data *data, void *localdata)
2538 {
2539         int rc;
2540         struct lustre_handle conn = { 0 };
2541
2542         ENTRY;
2543         rc = class_connect(&conn, src, cluuid);
2544         if (rc == 0)
2545                 *exp = class_conn2export(&conn);
2546
2547         RETURN(rc);
2548 }
2549
2550 static int echo_client_disconnect(struct obd_export *exp)
2551 {
2552         int rc;
2553
2554         ENTRY;
2555         if (!exp)
2556                 GOTO(out, rc = -EINVAL);
2557
2558         rc = class_disconnect(exp);
2559         GOTO(out, rc);
2560 out:
2561         return rc;
2562 }
2563
2564 static const struct obd_ops echo_client_obd_ops = {
2565         .o_owner       = THIS_MODULE,
2566         .o_iocontrol   = echo_client_iocontrol,
2567         .o_connect     = echo_client_connect,
2568         .o_disconnect  = echo_client_disconnect
2569 };
2570
2571 static int __init obdecho_init(void)
2572 {
2573         int rc;
2574
2575         ENTRY;
2576         LCONSOLE_INFO("Echo OBD driver; http://www.lustre.org/\n");
2577
2578         LASSERT(PAGE_SIZE % OBD_ECHO_BLOCK_SIZE == 0);
2579
2580 # ifdef HAVE_SERVER_SUPPORT
2581         rc = echo_persistent_pages_init();
2582         if (rc != 0)
2583                 goto failed_0;
2584
2585         rc = class_register_type(&echo_obd_ops, NULL, true,
2586                                  LUSTRE_ECHO_NAME, &echo_srv_type);
2587         if (rc != 0)
2588                 goto failed_1;
2589 # endif
2590
2591         rc = lu_kmem_init(echo_caches);
2592         if (rc == 0) {
2593                 rc = class_register_type(&echo_client_obd_ops, NULL, false,
2594                                          LUSTRE_ECHO_CLIENT_NAME,
2595                                          &echo_device_type);
2596                 if (rc)
2597                         lu_kmem_fini(echo_caches);
2598         }
2599
2600 # ifdef HAVE_SERVER_SUPPORT
2601         if (rc == 0)
2602                 RETURN(0);
2603
2604         class_unregister_type(LUSTRE_ECHO_NAME);
2605 failed_1:
2606         echo_persistent_pages_fini();
2607 failed_0:
2608 # endif
2609         RETURN(rc);
2610 }
2611
2612 static void __exit obdecho_exit(void)
2613 {
2614         class_unregister_type(LUSTRE_ECHO_CLIENT_NAME);
2615         lu_kmem_fini(echo_caches);
2616
2617 #ifdef HAVE_SERVER_SUPPORT
2618         class_unregister_type(LUSTRE_ECHO_NAME);
2619         echo_persistent_pages_fini();
2620 #endif
2621 }
2622
2623 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
2624 MODULE_DESCRIPTION("Lustre Echo Client test driver");
2625 MODULE_VERSION(LUSTRE_VERSION_STRING);
2626 MODULE_LICENSE("GPL");
2627
2628 module_init(obdecho_init);
2629 module_exit(obdecho_exit);
2630
2631 /** @} echo_client */