4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_ECHO
38 #include <linux/libcfs/libcfs.h>
41 #include <obd_support.h>
42 #include <obd_class.h>
43 #include <lustre_debug.h>
44 #include <lprocfs_status.h>
45 #include <cl_object.h>
46 #include <md_object.h>
47 #include <lustre_fid.h>
48 #include <lustre_acl.h>
49 #include <lustre_net.h>
52 #include "echo_internal.h"
54 /** \defgroup echo_client Echo Client
59 struct cl_device ed_cl
;
60 struct echo_client_obd
*ed_ec
;
62 struct cl_site ed_site_myself
;
63 struct cl_site
*ed_site
;
64 struct lu_device
*ed_next
;
67 struct lu_client_seq
*ed_cl_seq
;
71 struct cl_object eo_cl
;
72 struct cl_object_header eo_hdr
;
74 struct echo_device
*eo_dev
;
75 struct list_head eo_obj_chain
;
76 struct lov_stripe_md
*eo_lsm
;
81 struct echo_object_conf
{
82 struct cl_object_conf eoc_cl
;
83 struct lov_stripe_md
**eoc_md
;
87 struct cl_page_slice ep_cl
;
89 struct page
*ep_vmpage
;
93 struct cl_lock_slice el_cl
;
94 struct list_head el_chain
;
95 struct echo_object
*el_object
;
101 struct cl_io_slice ei_cl
;
106 struct cl_req_slice er_cl
;
110 static int echo_client_setup(const struct lu_env
*env
,
111 struct obd_device
*obddev
,
112 struct lustre_cfg
*lcfg
);
113 static int echo_client_cleanup(struct obd_device
*obddev
);
116 /** \defgroup echo_helpers Helper functions
119 static inline struct echo_device
*cl2echo_dev(const struct cl_device
*dev
)
121 return container_of0(dev
, struct echo_device
, ed_cl
);
124 static inline struct cl_device
*echo_dev2cl(struct echo_device
*d
)
129 static inline struct echo_device
*obd2echo_dev(const struct obd_device
*obd
)
131 return cl2echo_dev(lu2cl_dev(obd
->obd_lu_dev
));
134 static inline struct cl_object
*echo_obj2cl(struct echo_object
*eco
)
139 static inline struct echo_object
*cl2echo_obj(const struct cl_object
*o
)
141 return container_of(o
, struct echo_object
, eo_cl
);
144 static inline struct echo_page
*cl2echo_page(const struct cl_page_slice
*s
)
146 return container_of(s
, struct echo_page
, ep_cl
);
149 static inline struct echo_lock
*cl2echo_lock(const struct cl_lock_slice
*s
)
151 return container_of(s
, struct echo_lock
, el_cl
);
154 static inline struct cl_lock
*echo_lock2cl(const struct echo_lock
*ecl
)
156 return ecl
->el_cl
.cls_lock
;
159 static struct lu_context_key echo_thread_key
;
160 static inline struct echo_thread_info
*echo_env_info(const struct lu_env
*env
)
162 struct echo_thread_info
*info
;
163 info
= lu_context_key_get(&env
->le_ctx
, &echo_thread_key
);
164 LASSERT(info
!= NULL
);
169 struct echo_object_conf
*cl2echo_conf(const struct cl_object_conf
*c
)
171 return container_of(c
, struct echo_object_conf
, eoc_cl
);
174 /** @} echo_helpers */
176 static struct echo_object
*cl_echo_object_find(struct echo_device
*d
,
177 struct lov_stripe_md
**lsm
);
178 static int cl_echo_object_put(struct echo_object
*eco
);
179 static int cl_echo_enqueue (struct echo_object
*eco
, obd_off start
,
180 obd_off end
, int mode
, __u64
*cookie
);
181 static int cl_echo_cancel (struct echo_device
*d
, __u64 cookie
);
182 static int cl_echo_object_brw(struct echo_object
*eco
, int rw
, obd_off offset
,
183 struct page
**pages
, int npages
, int async
);
185 static struct echo_thread_info
*echo_env_info(const struct lu_env
*env
);
187 struct echo_thread_info
{
188 struct echo_object_conf eti_conf
;
189 struct lustre_md eti_md
;
191 struct cl_2queue eti_queue
;
193 struct cl_lock_descr eti_descr
;
194 struct lu_fid eti_fid
;
195 struct lu_fid eti_fid2
;
196 struct md_op_spec eti_spec
;
197 struct lov_mds_md_v3 eti_lmm
;
198 struct lov_user_md_v3 eti_lum
;
199 struct md_attr eti_ma
;
200 struct lu_name eti_lname
;
201 /* per-thread values, can be re-used */
205 struct lu_buf eti_buf
;
206 char eti_xattr_buf
[LUSTRE_POSIX_ACL_MAX_SIZE
];
209 /* No session used right now */
210 struct echo_session_info
{
214 static struct kmem_cache
*echo_lock_kmem
;
215 static struct kmem_cache
*echo_object_kmem
;
216 static struct kmem_cache
*echo_thread_kmem
;
217 static struct kmem_cache
*echo_session_kmem
;
218 //static struct kmem_cache *echo_req_kmem;
220 static struct lu_kmem_descr echo_caches
[] = {
222 .ckd_cache
= &echo_lock_kmem
,
223 .ckd_name
= "echo_lock_kmem",
224 .ckd_size
= sizeof (struct echo_lock
)
227 .ckd_cache
= &echo_object_kmem
,
228 .ckd_name
= "echo_object_kmem",
229 .ckd_size
= sizeof (struct echo_object
)
232 .ckd_cache
= &echo_thread_kmem
,
233 .ckd_name
= "echo_thread_kmem",
234 .ckd_size
= sizeof (struct echo_thread_info
)
237 .ckd_cache
= &echo_session_kmem
,
238 .ckd_name
= "echo_session_kmem",
239 .ckd_size
= sizeof (struct echo_session_info
)
243 .ckd_cache
= &echo_req_kmem
,
244 .ckd_name
= "echo_req_kmem",
245 .ckd_size
= sizeof (struct echo_req
)
253 /** \defgroup echo_page Page operations
255 * Echo page operations.
259 static struct page
*echo_page_vmpage(const struct lu_env
*env
,
260 const struct cl_page_slice
*slice
)
262 return cl2echo_page(slice
)->ep_vmpage
;
265 static int echo_page_own(const struct lu_env
*env
,
266 const struct cl_page_slice
*slice
,
267 struct cl_io
*io
, int nonblock
)
269 struct echo_page
*ep
= cl2echo_page(slice
);
272 mutex_lock(&ep
->ep_lock
);
273 else if (!mutex_trylock(&ep
->ep_lock
))
278 static void echo_page_disown(const struct lu_env
*env
,
279 const struct cl_page_slice
*slice
,
282 struct echo_page
*ep
= cl2echo_page(slice
);
284 LASSERT(mutex_is_locked(&ep
->ep_lock
));
285 mutex_unlock(&ep
->ep_lock
);
288 static void echo_page_discard(const struct lu_env
*env
,
289 const struct cl_page_slice
*slice
,
290 struct cl_io
*unused
)
292 cl_page_delete(env
, slice
->cpl_page
);
295 static int echo_page_is_vmlocked(const struct lu_env
*env
,
296 const struct cl_page_slice
*slice
)
298 if (mutex_is_locked(&cl2echo_page(slice
)->ep_lock
))
303 static void echo_page_completion(const struct lu_env
*env
,
304 const struct cl_page_slice
*slice
,
307 LASSERT(slice
->cpl_page
->cp_sync_io
!= NULL
);
310 static void echo_page_fini(const struct lu_env
*env
,
311 struct cl_page_slice
*slice
)
313 struct echo_page
*ep
= cl2echo_page(slice
);
314 struct echo_object
*eco
= cl2echo_obj(slice
->cpl_obj
);
315 struct page
*vmpage
= ep
->ep_vmpage
;
317 atomic_dec(&eco
->eo_npages
);
318 page_cache_release(vmpage
);
321 static int echo_page_prep(const struct lu_env
*env
,
322 const struct cl_page_slice
*slice
,
323 struct cl_io
*unused
)
328 static int echo_page_print(const struct lu_env
*env
,
329 const struct cl_page_slice
*slice
,
330 void *cookie
, lu_printer_t printer
)
332 struct echo_page
*ep
= cl2echo_page(slice
);
334 (*printer
)(env
, cookie
, LUSTRE_ECHO_CLIENT_NAME
"-page@%p %d vm@%p\n",
335 ep
, mutex_is_locked(&ep
->ep_lock
), ep
->ep_vmpage
);
339 static const struct cl_page_operations echo_page_ops
= {
340 .cpo_own
= echo_page_own
,
341 .cpo_disown
= echo_page_disown
,
342 .cpo_discard
= echo_page_discard
,
343 .cpo_vmpage
= echo_page_vmpage
,
344 .cpo_fini
= echo_page_fini
,
345 .cpo_print
= echo_page_print
,
346 .cpo_is_vmlocked
= echo_page_is_vmlocked
,
349 .cpo_prep
= echo_page_prep
,
350 .cpo_completion
= echo_page_completion
,
353 .cpo_prep
= echo_page_prep
,
354 .cpo_completion
= echo_page_completion
,
360 /** \defgroup echo_lock Locking
362 * echo lock operations
366 static void echo_lock_fini(const struct lu_env
*env
,
367 struct cl_lock_slice
*slice
)
369 struct echo_lock
*ecl
= cl2echo_lock(slice
);
371 LASSERT(list_empty(&ecl
->el_chain
));
372 OBD_SLAB_FREE_PTR(ecl
, echo_lock_kmem
);
375 static void echo_lock_delete(const struct lu_env
*env
,
376 const struct cl_lock_slice
*slice
)
378 struct echo_lock
*ecl
= cl2echo_lock(slice
);
380 LASSERT(list_empty(&ecl
->el_chain
));
383 static int echo_lock_fits_into(const struct lu_env
*env
,
384 const struct cl_lock_slice
*slice
,
385 const struct cl_lock_descr
*need
,
386 const struct cl_io
*unused
)
391 static struct cl_lock_operations echo_lock_ops
= {
392 .clo_fini
= echo_lock_fini
,
393 .clo_delete
= echo_lock_delete
,
394 .clo_fits_into
= echo_lock_fits_into
399 /** \defgroup echo_cl_ops cl_object operations
401 * operations for cl_object
405 static int echo_page_init(const struct lu_env
*env
, struct cl_object
*obj
,
406 struct cl_page
*page
, struct page
*vmpage
)
408 struct echo_page
*ep
= cl_object_page_slice(obj
, page
);
409 struct echo_object
*eco
= cl2echo_obj(obj
);
411 ep
->ep_vmpage
= vmpage
;
412 page_cache_get(vmpage
);
413 mutex_init(&ep
->ep_lock
);
414 cl_page_slice_add(page
, &ep
->ep_cl
, obj
, &echo_page_ops
);
415 atomic_inc(&eco
->eo_npages
);
419 static int echo_io_init(const struct lu_env
*env
, struct cl_object
*obj
,
425 static int echo_lock_init(const struct lu_env
*env
,
426 struct cl_object
*obj
, struct cl_lock
*lock
,
427 const struct cl_io
*unused
)
429 struct echo_lock
*el
;
431 OBD_SLAB_ALLOC_PTR_GFP(el
, echo_lock_kmem
, __GFP_IO
);
433 cl_lock_slice_add(lock
, &el
->el_cl
, obj
, &echo_lock_ops
);
434 el
->el_object
= cl2echo_obj(obj
);
435 INIT_LIST_HEAD(&el
->el_chain
);
436 atomic_set(&el
->el_refcount
, 0);
438 return el
== NULL
? -ENOMEM
: 0;
441 static int echo_conf_set(const struct lu_env
*env
, struct cl_object
*obj
,
442 const struct cl_object_conf
*conf
)
447 static const struct cl_object_operations echo_cl_obj_ops
= {
448 .coo_page_init
= echo_page_init
,
449 .coo_lock_init
= echo_lock_init
,
450 .coo_io_init
= echo_io_init
,
451 .coo_conf_set
= echo_conf_set
453 /** @} echo_cl_ops */
455 /** \defgroup echo_lu_ops lu_object operations
457 * operations for echo lu object.
461 static int echo_object_init(const struct lu_env
*env
, struct lu_object
*obj
,
462 const struct lu_object_conf
*conf
)
464 struct echo_device
*ed
= cl2echo_dev(lu2cl_dev(obj
->lo_dev
));
465 struct echo_client_obd
*ec
= ed
->ed_ec
;
466 struct echo_object
*eco
= cl2echo_obj(lu2cl(obj
));
469 struct lu_object
*below
;
470 struct lu_device
*under
;
473 below
= under
->ld_ops
->ldo_object_alloc(env
, obj
->lo_header
,
477 lu_object_add(obj
, below
);
480 if (!ed
->ed_next_ismd
) {
481 const struct cl_object_conf
*cconf
= lu2cl_conf(conf
);
482 struct echo_object_conf
*econf
= cl2echo_conf(cconf
);
484 LASSERT(econf
->eoc_md
);
485 eco
->eo_lsm
= *econf
->eoc_md
;
486 /* clear the lsm pointer so that it won't get freed. */
487 *econf
->eoc_md
= NULL
;
493 atomic_set(&eco
->eo_npages
, 0);
494 cl_object_page_init(lu2cl(obj
), sizeof(struct echo_page
));
496 spin_lock(&ec
->ec_lock
);
497 list_add_tail(&eco
->eo_obj_chain
, &ec
->ec_objects
);
498 spin_unlock(&ec
->ec_lock
);
503 /* taken from osc_unpackmd() */
504 static int echo_alloc_memmd(struct echo_device
*ed
,
505 struct lov_stripe_md
**lsmp
)
509 /* If export is lov/osc then use their obd method */
510 if (ed
->ed_next
!= NULL
)
511 return obd_alloc_memmd(ed
->ed_ec
->ec_exp
, lsmp
);
512 /* OFD has no unpackmd method, do everything here */
513 lsm_size
= lov_stripe_md_size(1);
515 LASSERT(*lsmp
== NULL
);
516 OBD_ALLOC(*lsmp
, lsm_size
);
520 OBD_ALLOC((*lsmp
)->lsm_oinfo
[0], sizeof(struct lov_oinfo
));
521 if ((*lsmp
)->lsm_oinfo
[0] == NULL
) {
522 OBD_FREE(*lsmp
, lsm_size
);
526 loi_init((*lsmp
)->lsm_oinfo
[0]);
527 (*lsmp
)->lsm_maxbytes
= LUSTRE_STRIPE_MAXBYTES
;
528 ostid_set_seq_echo(&(*lsmp
)->lsm_oi
);
533 static int echo_free_memmd(struct echo_device
*ed
, struct lov_stripe_md
**lsmp
)
537 /* If export is lov/osc then use their obd method */
538 if (ed
->ed_next
!= NULL
)
539 return obd_free_memmd(ed
->ed_ec
->ec_exp
, lsmp
);
540 /* OFD has no unpackmd method, do everything here */
541 lsm_size
= lov_stripe_md_size(1);
543 LASSERT(*lsmp
!= NULL
);
544 OBD_FREE((*lsmp
)->lsm_oinfo
[0], sizeof(struct lov_oinfo
));
545 OBD_FREE(*lsmp
, lsm_size
);
550 static void echo_object_free(const struct lu_env
*env
, struct lu_object
*obj
)
552 struct echo_object
*eco
= cl2echo_obj(lu2cl(obj
));
553 struct echo_client_obd
*ec
= eco
->eo_dev
->ed_ec
;
555 LASSERT(atomic_read(&eco
->eo_npages
) == 0);
557 spin_lock(&ec
->ec_lock
);
558 list_del_init(&eco
->eo_obj_chain
);
559 spin_unlock(&ec
->ec_lock
);
562 lu_object_header_fini(obj
->lo_header
);
565 echo_free_memmd(eco
->eo_dev
, &eco
->eo_lsm
);
566 OBD_SLAB_FREE_PTR(eco
, echo_object_kmem
);
569 static int echo_object_print(const struct lu_env
*env
, void *cookie
,
570 lu_printer_t p
, const struct lu_object
*o
)
572 struct echo_object
*obj
= cl2echo_obj(lu2cl(o
));
574 return (*p
)(env
, cookie
, "echoclient-object@%p", obj
);
577 static const struct lu_object_operations echo_lu_obj_ops
= {
578 .loo_object_init
= echo_object_init
,
579 .loo_object_delete
= NULL
,
580 .loo_object_release
= NULL
,
581 .loo_object_free
= echo_object_free
,
582 .loo_object_print
= echo_object_print
,
583 .loo_object_invariant
= NULL
585 /** @} echo_lu_ops */
587 /** \defgroup echo_lu_dev_ops lu_device operations
589 * Operations for echo lu device.
593 static struct lu_object
*echo_object_alloc(const struct lu_env
*env
,
594 const struct lu_object_header
*hdr
,
595 struct lu_device
*dev
)
597 struct echo_object
*eco
;
598 struct lu_object
*obj
= NULL
;
600 /* we're the top dev. */
601 LASSERT(hdr
== NULL
);
602 OBD_SLAB_ALLOC_PTR_GFP(eco
, echo_object_kmem
, __GFP_IO
);
604 struct cl_object_header
*hdr
= &eco
->eo_hdr
;
606 obj
= &echo_obj2cl(eco
)->co_lu
;
607 cl_object_header_init(hdr
);
608 lu_object_init(obj
, &hdr
->coh_lu
, dev
);
609 lu_object_add_top(&hdr
->coh_lu
, obj
);
611 eco
->eo_cl
.co_ops
= &echo_cl_obj_ops
;
612 obj
->lo_ops
= &echo_lu_obj_ops
;
617 static struct lu_device_operations echo_device_lu_ops
= {
618 .ldo_object_alloc
= echo_object_alloc
,
621 /** @} echo_lu_dev_ops */
623 static struct cl_device_operations echo_device_cl_ops
= {
626 /** \defgroup echo_init Setup and teardown
628 * Init and fini functions for echo client.
632 static int echo_site_init(const struct lu_env
*env
, struct echo_device
*ed
)
634 struct cl_site
*site
= &ed
->ed_site_myself
;
637 /* initialize site */
638 rc
= cl_site_init(site
, &ed
->ed_cl
);
640 CERROR("Cannot initialize site for echo client(%d)\n", rc
);
644 rc
= lu_site_init_finish(&site
->cs_lu
);
652 static void echo_site_fini(const struct lu_env
*env
, struct echo_device
*ed
)
655 if (!ed
->ed_next_ismd
)
656 cl_site_fini(ed
->ed_site
);
661 static void *echo_thread_key_init(const struct lu_context
*ctx
,
662 struct lu_context_key
*key
)
664 struct echo_thread_info
*info
;
666 OBD_SLAB_ALLOC_PTR_GFP(info
, echo_thread_kmem
, __GFP_IO
);
668 info
= ERR_PTR(-ENOMEM
);
672 static void echo_thread_key_fini(const struct lu_context
*ctx
,
673 struct lu_context_key
*key
, void *data
)
675 struct echo_thread_info
*info
= data
;
676 OBD_SLAB_FREE_PTR(info
, echo_thread_kmem
);
679 static void echo_thread_key_exit(const struct lu_context
*ctx
,
680 struct lu_context_key
*key
, void *data
)
684 static struct lu_context_key echo_thread_key
= {
685 .lct_tags
= LCT_CL_THREAD
,
686 .lct_init
= echo_thread_key_init
,
687 .lct_fini
= echo_thread_key_fini
,
688 .lct_exit
= echo_thread_key_exit
691 static void *echo_session_key_init(const struct lu_context
*ctx
,
692 struct lu_context_key
*key
)
694 struct echo_session_info
*session
;
696 OBD_SLAB_ALLOC_PTR_GFP(session
, echo_session_kmem
, __GFP_IO
);
698 session
= ERR_PTR(-ENOMEM
);
702 static void echo_session_key_fini(const struct lu_context
*ctx
,
703 struct lu_context_key
*key
, void *data
)
705 struct echo_session_info
*session
= data
;
706 OBD_SLAB_FREE_PTR(session
, echo_session_kmem
);
709 static void echo_session_key_exit(const struct lu_context
*ctx
,
710 struct lu_context_key
*key
, void *data
)
714 static struct lu_context_key echo_session_key
= {
715 .lct_tags
= LCT_SESSION
,
716 .lct_init
= echo_session_key_init
,
717 .lct_fini
= echo_session_key_fini
,
718 .lct_exit
= echo_session_key_exit
721 LU_TYPE_INIT_FINI(echo
, &echo_thread_key
, &echo_session_key
);
723 #define ECHO_SEQ_WIDTH 0xffffffff
724 static int echo_fid_init(struct echo_device
*ed
, char *obd_name
,
725 struct seq_server_site
*ss
)
730 OBD_ALLOC_PTR(ed
->ed_cl_seq
);
731 if (ed
->ed_cl_seq
== NULL
)
734 OBD_ALLOC(prefix
, MAX_OBD_NAME
+ 5);
736 GOTO(out_free_seq
, rc
= -ENOMEM
);
738 snprintf(prefix
, MAX_OBD_NAME
+ 5, "srv-%s", obd_name
);
740 /* Init client side sequence-manager */
741 rc
= seq_client_init(ed
->ed_cl_seq
, NULL
,
743 prefix
, ss
->ss_server_seq
);
744 ed
->ed_cl_seq
->lcs_width
= ECHO_SEQ_WIDTH
;
745 OBD_FREE(prefix
, MAX_OBD_NAME
+ 5);
747 GOTO(out_free_seq
, rc
);
752 OBD_FREE_PTR(ed
->ed_cl_seq
);
753 ed
->ed_cl_seq
= NULL
;
757 static int echo_fid_fini(struct obd_device
*obddev
)
759 struct echo_device
*ed
= obd2echo_dev(obddev
);
761 if (ed
->ed_cl_seq
!= NULL
) {
762 seq_client_fini(ed
->ed_cl_seq
);
763 OBD_FREE_PTR(ed
->ed_cl_seq
);
764 ed
->ed_cl_seq
= NULL
;
770 static struct lu_device
*echo_device_alloc(const struct lu_env
*env
,
771 struct lu_device_type
*t
,
772 struct lustre_cfg
*cfg
)
774 struct lu_device
*next
;
775 struct echo_device
*ed
;
776 struct cl_device
*cd
;
777 struct obd_device
*obd
= NULL
; /* to keep compiler happy */
778 struct obd_device
*tgt
;
779 const char *tgt_type_name
;
785 GOTO(out
, rc
= -ENOMEM
);
789 rc
= cl_device_init(cd
, t
);
793 cd
->cd_lu_dev
.ld_ops
= &echo_device_lu_ops
;
794 cd
->cd_ops
= &echo_device_cl_ops
;
797 obd
= class_name2obd(lustre_cfg_string(cfg
, 0));
798 LASSERT(obd
!= NULL
);
799 LASSERT(env
!= NULL
);
801 tgt
= class_name2obd(lustre_cfg_string(cfg
, 1));
803 CERROR("Can not find tgt device %s\n",
804 lustre_cfg_string(cfg
, 1));
805 GOTO(out
, rc
= -ENODEV
);
808 next
= tgt
->obd_lu_dev
;
809 if (!strcmp(tgt
->obd_type
->typ_name
, LUSTRE_MDT_NAME
)) {
810 ed
->ed_next_ismd
= 1;
812 ed
->ed_next_ismd
= 0;
813 rc
= echo_site_init(env
, ed
);
819 rc
= echo_client_setup(env
, obd
, cfg
);
823 ed
->ed_ec
= &obd
->u
.echo_client
;
826 if (ed
->ed_next_ismd
) {
827 /* Suppose to connect to some Metadata layer */
829 struct lu_device
*ld
;
833 CERROR("%s is not lu device type!\n",
834 lustre_cfg_string(cfg
, 1));
835 GOTO(out
, rc
= -EINVAL
);
838 tgt_type_name
= lustre_cfg_string(cfg
, 2);
839 if (!tgt_type_name
) {
840 CERROR("%s no type name for echo %s setup\n",
841 lustre_cfg_string(cfg
, 1),
842 tgt
->obd_type
->typ_name
);
843 GOTO(out
, rc
= -EINVAL
);
848 spin_lock(&ls
->ls_ld_lock
);
849 list_for_each_entry(ld
, &ls
->ls_ld_linkage
, ld_linkage
) {
850 if (strcmp(ld
->ld_type
->ldt_name
, tgt_type_name
) == 0) {
855 spin_unlock(&ls
->ls_ld_lock
);
858 CERROR("%s is not lu device type!\n",
859 lustre_cfg_string(cfg
, 1));
860 GOTO(out
, rc
= -EINVAL
);
864 /* For MD echo client, it will use the site in MDS stack */
865 ed
->ed_site_myself
.cs_lu
= *ls
;
866 ed
->ed_site
= &ed
->ed_site_myself
;
867 ed
->ed_cl
.cd_lu_dev
.ld_site
= &ed
->ed_site_myself
.cs_lu
;
868 rc
= echo_fid_init(ed
, obd
->obd_name
, lu_site2seq(ls
));
870 CERROR("echo fid init error %d\n", rc
);
874 /* if echo client is to be stacked upon ost device, the next is
875 * NULL since ost is not a clio device so far */
876 if (next
!= NULL
&& !lu_device_is_cl(next
))
879 tgt_type_name
= tgt
->obd_type
->typ_name
;
881 LASSERT(next
!= NULL
);
882 if (next
->ld_site
!= NULL
)
883 GOTO(out
, rc
= -EBUSY
);
885 next
->ld_site
= &ed
->ed_site
->cs_lu
;
886 rc
= next
->ld_type
->ldt_ops
->ldto_device_init(env
, next
,
887 next
->ld_type
->ldt_name
,
892 /* Tricky case, I have to determine the obd type since
893 * CLIO uses the different parameters to initialize
894 * objects for lov & osc. */
895 if (strcmp(tgt_type_name
, LUSTRE_LOV_NAME
) == 0)
896 ed
->ed_next_islov
= 1;
898 LASSERT(strcmp(tgt_type_name
,
899 LUSTRE_OSC_NAME
) == 0);
901 LASSERT(strcmp(tgt_type_name
, LUSTRE_OST_NAME
) == 0);
905 return &cd
->cd_lu_dev
;
910 rc2
= echo_client_cleanup(obd
);
912 CERROR("Cleanup obd device %s error(%d)\n",
917 echo_site_fini(env
, ed
);
919 cl_device_fini(&ed
->ed_cl
);
929 static int echo_device_init(const struct lu_env
*env
, struct lu_device
*d
,
930 const char *name
, struct lu_device
*next
)
936 static struct lu_device
*echo_device_fini(const struct lu_env
*env
,
939 struct echo_device
*ed
= cl2echo_dev(lu2cl_dev(d
));
940 struct lu_device
*next
= ed
->ed_next
;
942 while (next
&& !ed
->ed_next_ismd
)
943 next
= next
->ld_type
->ldt_ops
->ldto_device_fini(env
, next
);
947 static void echo_lock_release(const struct lu_env
*env
,
948 struct echo_lock
*ecl
,
951 struct cl_lock
*clk
= echo_lock2cl(ecl
);
955 cl_lock_release(env
, clk
, "ec enqueue", ecl
->el_object
);
957 cl_lock_mutex_get(env
, clk
);
958 cl_lock_cancel(env
, clk
);
959 cl_lock_delete(env
, clk
);
960 cl_lock_mutex_put(env
, clk
);
962 cl_lock_put(env
, clk
);
965 static struct lu_device
*echo_device_free(const struct lu_env
*env
,
968 struct echo_device
*ed
= cl2echo_dev(lu2cl_dev(d
));
969 struct echo_client_obd
*ec
= ed
->ed_ec
;
970 struct echo_object
*eco
;
971 struct lu_device
*next
= ed
->ed_next
;
973 CDEBUG(D_INFO
, "echo device:%p is going to be freed, next = %p\n",
976 lu_site_purge(env
, &ed
->ed_site
->cs_lu
, -1);
978 /* check if there are objects still alive.
979 * It shouldn't have any object because lu_site_purge would cleanup
980 * all of cached objects. Anyway, probably the echo device is being
981 * parallelly accessed.
983 spin_lock(&ec
->ec_lock
);
984 list_for_each_entry(eco
, &ec
->ec_objects
, eo_obj_chain
)
986 spin_unlock(&ec
->ec_lock
);
989 lu_site_purge(env
, &ed
->ed_site
->cs_lu
, -1);
992 "Waiting for the reference of echo object to be dropped\n");
994 /* Wait for the last reference to be dropped. */
995 spin_lock(&ec
->ec_lock
);
996 while (!list_empty(&ec
->ec_objects
)) {
997 spin_unlock(&ec
->ec_lock
);
998 CERROR("echo_client still has objects at cleanup time, "
999 "wait for 1 second\n");
1000 schedule_timeout_and_set_state(TASK_UNINTERRUPTIBLE
,
1001 cfs_time_seconds(1));
1002 lu_site_purge(env
, &ed
->ed_site
->cs_lu
, -1);
1003 spin_lock(&ec
->ec_lock
);
1005 spin_unlock(&ec
->ec_lock
);
1007 LASSERT(list_empty(&ec
->ec_locks
));
1009 CDEBUG(D_INFO
, "No object exists, exiting...\n");
1011 echo_client_cleanup(d
->ld_obd
);
1012 echo_fid_fini(d
->ld_obd
);
1013 while (next
&& !ed
->ed_next_ismd
)
1014 next
= next
->ld_type
->ldt_ops
->ldto_device_free(env
, next
);
1016 LASSERT(ed
->ed_site
== lu2cl_site(d
->ld_site
));
1017 echo_site_fini(env
, ed
);
1018 cl_device_fini(&ed
->ed_cl
);
1024 static const struct lu_device_type_operations echo_device_type_ops
= {
1025 .ldto_init
= echo_type_init
,
1026 .ldto_fini
= echo_type_fini
,
1028 .ldto_start
= echo_type_start
,
1029 .ldto_stop
= echo_type_stop
,
1031 .ldto_device_alloc
= echo_device_alloc
,
1032 .ldto_device_free
= echo_device_free
,
1033 .ldto_device_init
= echo_device_init
,
1034 .ldto_device_fini
= echo_device_fini
1037 static struct lu_device_type echo_device_type
= {
1038 .ldt_tags
= LU_DEVICE_CL
,
1039 .ldt_name
= LUSTRE_ECHO_CLIENT_NAME
,
1040 .ldt_ops
= &echo_device_type_ops
,
1041 .ldt_ctx_tags
= LCT_CL_THREAD
| LCT_MD_THREAD
| LCT_DT_THREAD
,
1045 /** \defgroup echo_exports Exported operations
1047 * exporting functions to echo client
1052 /* Interfaces to echo client obd device */
1053 static struct echo_object
*cl_echo_object_find(struct echo_device
*d
,
1054 struct lov_stripe_md
**lsmp
)
1057 struct echo_thread_info
*info
;
1058 struct echo_object_conf
*conf
;
1059 struct lov_stripe_md
*lsm
;
1060 struct echo_object
*eco
;
1061 struct cl_object
*obj
;
1069 LASSERTF(ostid_id(&lsm
->lsm_oi
) != 0, DOSTID
"\n", POSTID(&lsm
->lsm_oi
));
1070 LASSERTF(ostid_seq(&lsm
->lsm_oi
) == FID_SEQ_ECHO
, DOSTID
"\n",
1071 POSTID(&lsm
->lsm_oi
));
1073 /* Never return an object if the obd is to be freed. */
1074 if (echo_dev2cl(d
)->cd_lu_dev
.ld_obd
->obd_stopping
)
1075 return ERR_PTR(-ENODEV
);
1077 env
= cl_env_get(&refcheck
);
1081 info
= echo_env_info(env
);
1082 conf
= &info
->eti_conf
;
1084 if (!d
->ed_next_islov
) {
1085 struct lov_oinfo
*oinfo
= lsm
->lsm_oinfo
[0];
1086 LASSERT(oinfo
!= NULL
);
1087 oinfo
->loi_oi
= lsm
->lsm_oi
;
1088 conf
->eoc_cl
.u
.coc_oinfo
= oinfo
;
1090 struct lustre_md
*md
;
1092 memset(md
, 0, sizeof(*md
));
1094 conf
->eoc_cl
.u
.coc_md
= md
;
1097 conf
->eoc_md
= lsmp
;
1099 fid
= &info
->eti_fid
;
1100 rc
= ostid_to_fid(fid
, &lsm
->lsm_oi
, 0);
1102 GOTO(out
, eco
= ERR_PTR(rc
));
1104 /* In the function below, .hs_keycmp resolves to
1105 * lu_obj_hop_keycmp() */
1106 /* coverity[overrun-buffer-val] */
1107 obj
= cl_object_find(env
, echo_dev2cl(d
), fid
, &conf
->eoc_cl
);
1109 GOTO(out
, eco
= (void *)obj
);
1111 eco
= cl2echo_obj(obj
);
1112 if (eco
->eo_deleted
) {
1113 cl_object_put(env
, obj
);
1114 eco
= ERR_PTR(-EAGAIN
);
1118 cl_env_put(env
, &refcheck
);
1122 static int cl_echo_object_put(struct echo_object
*eco
)
1125 struct cl_object
*obj
= echo_obj2cl(eco
);
1128 env
= cl_env_get(&refcheck
);
1130 return PTR_ERR(env
);
1132 /* an external function to kill an object? */
1133 if (eco
->eo_deleted
) {
1134 struct lu_object_header
*loh
= obj
->co_lu
.lo_header
;
1135 LASSERT(&eco
->eo_hdr
== luh2coh(loh
));
1136 set_bit(LU_OBJECT_HEARD_BANSHEE
, &loh
->loh_flags
);
1139 cl_object_put(env
, obj
);
1140 cl_env_put(env
, &refcheck
);
1144 static int cl_echo_enqueue0(struct lu_env
*env
, struct echo_object
*eco
,
1145 obd_off start
, obd_off end
, int mode
,
1146 __u64
*cookie
, __u32 enqflags
)
1149 struct cl_lock
*lck
;
1150 struct cl_object
*obj
;
1151 struct cl_lock_descr
*descr
;
1152 struct echo_thread_info
*info
;
1155 info
= echo_env_info(env
);
1157 descr
= &info
->eti_descr
;
1158 obj
= echo_obj2cl(eco
);
1160 descr
->cld_obj
= obj
;
1161 descr
->cld_start
= cl_index(obj
, start
);
1162 descr
->cld_end
= cl_index(obj
, end
);
1163 descr
->cld_mode
= mode
== LCK_PW
? CLM_WRITE
: CLM_READ
;
1164 descr
->cld_enq_flags
= enqflags
;
1167 lck
= cl_lock_request(env
, io
, descr
, "ec enqueue", eco
);
1169 struct echo_client_obd
*ec
= eco
->eo_dev
->ed_ec
;
1170 struct echo_lock
*el
;
1172 rc
= cl_wait(env
, lck
);
1174 el
= cl2echo_lock(cl_lock_at(lck
, &echo_device_type
));
1175 spin_lock(&ec
->ec_lock
);
1176 if (list_empty(&el
->el_chain
)) {
1177 list_add(&el
->el_chain
, &ec
->ec_locks
);
1178 el
->el_cookie
= ++ec
->ec_unique
;
1180 atomic_inc(&el
->el_refcount
);
1181 *cookie
= el
->el_cookie
;
1182 spin_unlock(&ec
->ec_lock
);
1184 cl_lock_release(env
, lck
, "ec enqueue", current
);
1190 static int cl_echo_enqueue(struct echo_object
*eco
, obd_off start
, obd_off end
,
1191 int mode
, __u64
*cookie
)
1193 struct echo_thread_info
*info
;
1199 env
= cl_env_get(&refcheck
);
1201 return PTR_ERR(env
);
1203 info
= echo_env_info(env
);
1206 io
->ci_ignore_layout
= 1;
1207 result
= cl_io_init(env
, io
, CIT_MISC
, echo_obj2cl(eco
));
1210 LASSERT(result
== 0);
1212 result
= cl_echo_enqueue0(env
, eco
, start
, end
, mode
, cookie
, 0);
1213 cl_io_fini(env
, io
);
1216 cl_env_put(env
, &refcheck
);
1220 static int cl_echo_cancel0(struct lu_env
*env
, struct echo_device
*ed
,
1223 struct echo_client_obd
*ec
= ed
->ed_ec
;
1224 struct echo_lock
*ecl
= NULL
;
1225 struct list_head
*el
;
1226 int found
= 0, still_used
= 0;
1228 LASSERT(ec
!= NULL
);
1229 spin_lock(&ec
->ec_lock
);
1230 list_for_each (el
, &ec
->ec_locks
) {
1231 ecl
= list_entry (el
, struct echo_lock
, el_chain
);
1232 CDEBUG(D_INFO
, "ecl: %p, cookie: "LPX64
"\n", ecl
, ecl
->el_cookie
);
1233 found
= (ecl
->el_cookie
== cookie
);
1235 if (atomic_dec_and_test(&ecl
->el_refcount
))
1236 list_del_init(&ecl
->el_chain
);
1242 spin_unlock(&ec
->ec_lock
);
1247 echo_lock_release(env
, ecl
, still_used
);
1251 static int cl_echo_cancel(struct echo_device
*ed
, __u64 cookie
)
1257 env
= cl_env_get(&refcheck
);
1259 return PTR_ERR(env
);
1261 rc
= cl_echo_cancel0(env
, ed
, cookie
);
1263 cl_env_put(env
, &refcheck
);
1267 static int cl_echo_async_brw(const struct lu_env
*env
, struct cl_io
*io
,
1268 enum cl_req_type unused
, struct cl_2queue
*queue
)
1270 struct cl_page
*clp
;
1271 struct cl_page
*temp
;
1274 cl_page_list_for_each_safe(clp
, temp
, &queue
->c2_qin
) {
1276 rc
= cl_page_cache_add(env
, io
, clp
, CRT_WRITE
);
1279 result
= result
?: rc
;
1284 static int cl_echo_object_brw(struct echo_object
*eco
, int rw
, obd_off offset
,
1285 struct page
**pages
, int npages
, int async
)
1288 struct echo_thread_info
*info
;
1289 struct cl_object
*obj
= echo_obj2cl(eco
);
1290 struct echo_device
*ed
= eco
->eo_dev
;
1291 struct cl_2queue
*queue
;
1293 struct cl_page
*clp
;
1294 struct lustre_handle lh
= { 0 };
1295 int page_size
= cl_page_size(obj
);
1300 LASSERT((offset
& ~CFS_PAGE_MASK
) == 0);
1301 LASSERT(ed
->ed_next
!= NULL
);
1302 env
= cl_env_get(&refcheck
);
1304 return PTR_ERR(env
);
1306 info
= echo_env_info(env
);
1308 queue
= &info
->eti_queue
;
1310 cl_2queue_init(queue
);
1312 io
->ci_ignore_layout
= 1;
1313 rc
= cl_io_init(env
, io
, CIT_MISC
, obj
);
1319 rc
= cl_echo_enqueue0(env
, eco
, offset
,
1320 offset
+ npages
* PAGE_CACHE_SIZE
- 1,
1321 rw
== READ
? LCK_PR
: LCK_PW
, &lh
.cookie
,
1324 GOTO(error_lock
, rc
);
1326 for (i
= 0; i
< npages
; i
++) {
1328 clp
= cl_page_find(env
, obj
, cl_index(obj
, offset
),
1329 pages
[i
], CPT_TRANSIENT
);
1334 LASSERT(clp
->cp_type
== CPT_TRANSIENT
);
1336 rc
= cl_page_own(env
, io
, clp
);
1338 LASSERT(clp
->cp_state
== CPS_FREEING
);
1339 cl_page_put(env
, clp
);
1343 cl_2queue_add(queue
, clp
);
1345 /* drop the reference count for cl_page_find, so that the page
1346 * will be freed in cl_2queue_fini. */
1347 cl_page_put(env
, clp
);
1348 cl_page_clip(env
, clp
, 0, page_size
);
1350 offset
+= page_size
;
1354 enum cl_req_type typ
= rw
== READ
? CRT_READ
: CRT_WRITE
;
1356 async
= async
&& (typ
== CRT_WRITE
);
1358 rc
= cl_echo_async_brw(env
, io
, typ
, queue
);
1360 rc
= cl_io_submit_sync(env
, io
, typ
, queue
, 0);
1361 CDEBUG(D_INFO
, "echo_client %s write returns %d\n",
1362 async
? "async" : "sync", rc
);
1365 cl_echo_cancel0(env
, ed
, lh
.cookie
);
1367 cl_2queue_discard(env
, io
, queue
);
1368 cl_2queue_disown(env
, io
, queue
);
1369 cl_2queue_fini(env
, queue
);
1370 cl_io_fini(env
, io
);
1372 cl_env_put(env
, &refcheck
);
1375 /** @} echo_exports */
1378 static obd_id last_object_id
;
1381 echo_copyout_lsm (struct lov_stripe_md
*lsm
, void *_ulsm
, int ulsm_nob
)
1383 struct lov_stripe_md
*ulsm
= _ulsm
;
1386 nob
= offsetof (struct lov_stripe_md
, lsm_oinfo
[lsm
->lsm_stripe_count
]);
1390 if (copy_to_user (ulsm
, lsm
, sizeof(*ulsm
)))
1393 for (i
= 0; i
< lsm
->lsm_stripe_count
; i
++) {
1394 if (copy_to_user (ulsm
->lsm_oinfo
[i
], lsm
->lsm_oinfo
[i
],
1395 sizeof(lsm
->lsm_oinfo
[0])))
1402 echo_copyin_lsm (struct echo_device
*ed
, struct lov_stripe_md
*lsm
,
1403 void *ulsm
, int ulsm_nob
)
1405 struct echo_client_obd
*ec
= ed
->ed_ec
;
1408 if (ulsm_nob
< sizeof (*lsm
))
1411 if (copy_from_user (lsm
, ulsm
, sizeof (*lsm
)))
1414 if (lsm
->lsm_stripe_count
> ec
->ec_nstripes
||
1415 lsm
->lsm_magic
!= LOV_MAGIC
||
1416 (lsm
->lsm_stripe_size
& (~CFS_PAGE_MASK
)) != 0 ||
1417 ((__u64
)lsm
->lsm_stripe_size
* lsm
->lsm_stripe_count
> ~0UL))
1421 for (i
= 0; i
< lsm
->lsm_stripe_count
; i
++) {
1422 if (copy_from_user(lsm
->lsm_oinfo
[i
],
1423 ((struct lov_stripe_md
*)ulsm
)-> \
1425 sizeof(lsm
->lsm_oinfo
[0])))
1431 static inline void echo_md_build_name(struct lu_name
*lname
, char *name
,
1434 sprintf(name
, LPU64
, id
);
1435 lname
->ln_name
= name
;
1436 lname
->ln_namelen
= strlen(name
);
1439 /* similar to mdt_attr_get_complex */
1440 static int echo_big_lmm_get(const struct lu_env
*env
, struct md_object
*o
,
1443 struct echo_thread_info
*info
= echo_env_info(env
);
1446 LASSERT(ma
->ma_lmm_size
> 0);
1448 rc
= mo_xattr_get(env
, o
, &LU_BUF_NULL
, XATTR_NAME_LOV
);
1452 /* big_lmm may need to be grown */
1453 if (info
->eti_big_lmmsize
< rc
) {
1454 int size
= size_roundup_power2(rc
);
1456 if (info
->eti_big_lmmsize
> 0) {
1457 /* free old buffer */
1458 LASSERT(info
->eti_big_lmm
);
1459 OBD_FREE_LARGE(info
->eti_big_lmm
,
1460 info
->eti_big_lmmsize
);
1461 info
->eti_big_lmm
= NULL
;
1462 info
->eti_big_lmmsize
= 0;
1465 OBD_ALLOC_LARGE(info
->eti_big_lmm
, size
);
1466 if (info
->eti_big_lmm
== NULL
)
1468 info
->eti_big_lmmsize
= size
;
1470 LASSERT(info
->eti_big_lmmsize
>= rc
);
1472 info
->eti_buf
.lb_buf
= info
->eti_big_lmm
;
1473 info
->eti_buf
.lb_len
= info
->eti_big_lmmsize
;
1474 rc
= mo_xattr_get(env
, o
, &info
->eti_buf
, XATTR_NAME_LOV
);
1478 ma
->ma_valid
|= MA_LOV
;
1479 ma
->ma_lmm
= info
->eti_big_lmm
;
1480 ma
->ma_lmm_size
= rc
;
1485 int echo_attr_get_complex(const struct lu_env
*env
, struct md_object
*next
,
1488 struct echo_thread_info
*info
= echo_env_info(env
);
1489 struct lu_buf
*buf
= &info
->eti_buf
;
1490 umode_t mode
= lu_object_attr(&next
->mo_lu
);
1491 int need
= ma
->ma_need
;
1496 if (need
& MA_INODE
) {
1497 ma
->ma_need
= MA_INODE
;
1498 rc
= mo_attr_get(env
, next
, ma
);
1501 ma
->ma_valid
|= MA_INODE
;
1504 if (need
& MA_LOV
) {
1505 if (S_ISREG(mode
) || S_ISDIR(mode
)) {
1506 LASSERT(ma
->ma_lmm_size
> 0);
1507 buf
->lb_buf
= ma
->ma_lmm
;
1508 buf
->lb_len
= ma
->ma_lmm_size
;
1509 rc2
= mo_xattr_get(env
, next
, buf
, XATTR_NAME_LOV
);
1511 ma
->ma_lmm_size
= rc2
;
1512 ma
->ma_valid
|= MA_LOV
;
1513 } else if (rc2
== -ENODATA
) {
1515 ma
->ma_lmm_size
= 0;
1516 } else if (rc2
== -ERANGE
) {
1517 rc2
= echo_big_lmm_get(env
, next
, ma
);
1519 GOTO(out
, rc
= rc2
);
1521 GOTO(out
, rc
= rc2
);
1526 #ifdef CONFIG_FS_POSIX_ACL
1527 if (need
& MA_ACL_DEF
&& S_ISDIR(mode
)) {
1528 buf
->lb_buf
= ma
->ma_acl
;
1529 buf
->lb_len
= ma
->ma_acl_size
;
1530 rc2
= mo_xattr_get(env
, next
, buf
, XATTR_NAME_ACL_DEFAULT
);
1532 ma
->ma_acl_size
= rc2
;
1533 ma
->ma_valid
|= MA_ACL_DEF
;
1534 } else if (rc2
== -ENODATA
) {
1536 ma
->ma_acl_size
= 0;
1538 GOTO(out
, rc
= rc2
);
1544 CDEBUG(D_INODE
, "after getattr rc = %d, ma_valid = "LPX64
" ma_lmm=%p\n",
1545 rc
, ma
->ma_valid
, ma
->ma_lmm
);
1550 echo_md_create_internal(const struct lu_env
*env
, struct echo_device
*ed
,
1551 struct md_object
*parent
, struct lu_fid
*fid
,
1552 struct lu_name
*lname
, struct md_op_spec
*spec
,
1555 struct lu_object
*ec_child
, *child
;
1556 struct lu_device
*ld
= ed
->ed_next
;
1557 struct echo_thread_info
*info
= echo_env_info(env
);
1558 struct lu_fid
*fid2
= &info
->eti_fid2
;
1559 struct lu_object_conf conf
= { .loc_flags
= LOC_F_NEW
};
1562 rc
= mdo_lookup(env
, parent
, lname
, fid2
, spec
);
1565 else if (rc
!= -ENOENT
)
1568 ec_child
= lu_object_find_at(env
, &ed
->ed_cl
.cd_lu_dev
,
1570 if (IS_ERR(ec_child
)) {
1571 CERROR("Can not find the child "DFID
": rc = %ld\n", PFID(fid
),
1573 return PTR_ERR(ec_child
);
1576 child
= lu_object_locate(ec_child
->lo_header
, ld
->ld_type
);
1577 if (child
== NULL
) {
1578 CERROR("Can not locate the child "DFID
"\n", PFID(fid
));
1579 GOTO(out_put
, rc
= -EINVAL
);
1582 CDEBUG(D_RPCTRACE
, "Start creating object "DFID
" %s %p\n",
1583 PFID(lu_object_fid(&parent
->mo_lu
)), lname
->ln_name
, parent
);
1586 * Do not perform lookup sanity check. We know that name does not exist.
1588 spec
->sp_cr_lookup
= 0;
1589 rc
= mdo_create(env
, parent
, lname
, lu2md(child
), spec
, ma
);
1591 CERROR("Can not create child "DFID
": rc = %d\n", PFID(fid
), rc
);
1594 CDEBUG(D_RPCTRACE
, "End creating object "DFID
" %s %p rc = %d\n",
1595 PFID(lu_object_fid(&parent
->mo_lu
)), lname
->ln_name
, parent
, rc
);
1597 lu_object_put(env
, ec_child
);
1601 static int echo_set_lmm_size(const struct lu_env
*env
, struct lu_device
*ld
,
1604 struct echo_thread_info
*info
= echo_env_info(env
);
1606 if (strcmp(ld
->ld_type
->ldt_name
, LUSTRE_MDD_NAME
)) {
1607 ma
->ma_lmm
= (void *)&info
->eti_lmm
;
1608 ma
->ma_lmm_size
= sizeof(info
->eti_lmm
);
1610 LASSERT(info
->eti_big_lmmsize
);
1611 ma
->ma_lmm
= info
->eti_big_lmm
;
1612 ma
->ma_lmm_size
= info
->eti_big_lmmsize
;
1618 static int echo_create_md_object(const struct lu_env
*env
,
1619 struct echo_device
*ed
,
1620 struct lu_object
*ec_parent
,
1622 char *name
, int namelen
,
1623 __u64 id
, __u32 mode
, int count
,
1624 int stripe_count
, int stripe_offset
)
1626 struct lu_object
*parent
;
1627 struct echo_thread_info
*info
= echo_env_info(env
);
1628 struct lu_name
*lname
= &info
->eti_lname
;
1629 struct md_op_spec
*spec
= &info
->eti_spec
;
1630 struct md_attr
*ma
= &info
->eti_ma
;
1631 struct lu_device
*ld
= ed
->ed_next
;
1635 if (ec_parent
== NULL
)
1637 parent
= lu_object_locate(ec_parent
->lo_header
, ld
->ld_type
);
1641 memset(ma
, 0, sizeof(*ma
));
1642 memset(spec
, 0, sizeof(*spec
));
1643 if (stripe_count
!= 0) {
1644 spec
->sp_cr_flags
|= FMODE_WRITE
;
1645 echo_set_lmm_size(env
, ld
, ma
);
1646 if (stripe_count
!= -1) {
1647 struct lov_user_md_v3
*lum
= &info
->eti_lum
;
1649 lum
->lmm_magic
= LOV_USER_MAGIC_V3
;
1650 lum
->lmm_stripe_count
= stripe_count
;
1651 lum
->lmm_stripe_offset
= stripe_offset
;
1652 lum
->lmm_pattern
= 0;
1653 spec
->u
.sp_ea
.eadata
= lum
;
1654 spec
->u
.sp_ea
.eadatalen
= sizeof(*lum
);
1655 spec
->sp_cr_flags
|= MDS_OPEN_HAS_EA
;
1659 ma
->ma_attr
.la_mode
= mode
;
1660 ma
->ma_attr
.la_valid
= LA_CTIME
| LA_MODE
;
1661 ma
->ma_attr
.la_ctime
= cfs_time_current_64();
1664 lname
->ln_name
= name
;
1665 lname
->ln_namelen
= namelen
;
1666 /* If name is specified, only create one object by name */
1667 rc
= echo_md_create_internal(env
, ed
, lu2md(parent
), fid
, lname
,
1672 /* Create multiple object sequenced by id */
1673 for (i
= 0; i
< count
; i
++) {
1674 char *tmp_name
= info
->eti_name
;
1676 echo_md_build_name(lname
, tmp_name
, id
);
1678 rc
= echo_md_create_internal(env
, ed
, lu2md(parent
), fid
, lname
,
1681 CERROR("Can not create child %s: rc = %d\n", tmp_name
,
1692 static struct lu_object
*echo_md_lookup(const struct lu_env
*env
,
1693 struct echo_device
*ed
,
1694 struct md_object
*parent
,
1695 struct lu_name
*lname
)
1697 struct echo_thread_info
*info
= echo_env_info(env
);
1698 struct lu_fid
*fid
= &info
->eti_fid
;
1699 struct lu_object
*child
;
1702 CDEBUG(D_INFO
, "lookup %s in parent "DFID
" %p\n", lname
->ln_name
,
1704 rc
= mdo_lookup(env
, parent
, lname
, fid
, NULL
);
1706 CERROR("lookup %s: rc = %d\n", lname
->ln_name
, rc
);
1710 /* In the function below, .hs_keycmp resolves to
1711 * lu_obj_hop_keycmp() */
1712 /* coverity[overrun-buffer-val] */
1713 child
= lu_object_find_at(env
, &ed
->ed_cl
.cd_lu_dev
, fid
, NULL
);
1718 static int echo_setattr_object(const struct lu_env
*env
,
1719 struct echo_device
*ed
,
1720 struct lu_object
*ec_parent
,
1721 __u64 id
, int count
)
1723 struct lu_object
*parent
;
1724 struct echo_thread_info
*info
= echo_env_info(env
);
1725 struct lu_name
*lname
= &info
->eti_lname
;
1726 char *name
= info
->eti_name
;
1727 struct lu_device
*ld
= ed
->ed_next
;
1728 struct lu_buf
*buf
= &info
->eti_buf
;
1732 if (ec_parent
== NULL
)
1734 parent
= lu_object_locate(ec_parent
->lo_header
, ld
->ld_type
);
1738 for (i
= 0; i
< count
; i
++) {
1739 struct lu_object
*ec_child
, *child
;
1741 echo_md_build_name(lname
, name
, id
);
1743 ec_child
= echo_md_lookup(env
, ed
, lu2md(parent
), lname
);
1744 if (IS_ERR(ec_child
)) {
1745 CERROR("Can't find child %s: rc = %ld\n",
1746 lname
->ln_name
, PTR_ERR(ec_child
));
1747 return PTR_ERR(ec_child
);
1750 child
= lu_object_locate(ec_child
->lo_header
, ld
->ld_type
);
1751 if (child
== NULL
) {
1752 CERROR("Can not locate the child %s\n", lname
->ln_name
);
1753 lu_object_put(env
, ec_child
);
1758 CDEBUG(D_RPCTRACE
, "Start setattr object "DFID
"\n",
1759 PFID(lu_object_fid(child
)));
1761 buf
->lb_buf
= info
->eti_xattr_buf
;
1762 buf
->lb_len
= sizeof(info
->eti_xattr_buf
);
1764 sprintf(name
, "%s.test1", XATTR_USER_PREFIX
);
1765 rc
= mo_xattr_set(env
, lu2md(child
), buf
, name
,
1768 CERROR("Can not setattr child "DFID
": rc = %d\n",
1769 PFID(lu_object_fid(child
)), rc
);
1770 lu_object_put(env
, ec_child
);
1773 CDEBUG(D_RPCTRACE
, "End setattr object "DFID
"\n",
1774 PFID(lu_object_fid(child
)));
1776 lu_object_put(env
, ec_child
);
1781 static int echo_getattr_object(const struct lu_env
*env
,
1782 struct echo_device
*ed
,
1783 struct lu_object
*ec_parent
,
1784 __u64 id
, int count
)
1786 struct lu_object
*parent
;
1787 struct echo_thread_info
*info
= echo_env_info(env
);
1788 struct lu_name
*lname
= &info
->eti_lname
;
1789 char *name
= info
->eti_name
;
1790 struct md_attr
*ma
= &info
->eti_ma
;
1791 struct lu_device
*ld
= ed
->ed_next
;
1795 if (ec_parent
== NULL
)
1797 parent
= lu_object_locate(ec_parent
->lo_header
, ld
->ld_type
);
1801 memset(ma
, 0, sizeof(*ma
));
1802 ma
->ma_need
|= MA_INODE
| MA_LOV
| MA_PFID
| MA_HSM
| MA_ACL_DEF
;
1803 ma
->ma_acl
= info
->eti_xattr_buf
;
1804 ma
->ma_acl_size
= sizeof(info
->eti_xattr_buf
);
1806 for (i
= 0; i
< count
; i
++) {
1807 struct lu_object
*ec_child
, *child
;
1810 echo_md_build_name(lname
, name
, id
);
1811 echo_set_lmm_size(env
, ld
, ma
);
1813 ec_child
= echo_md_lookup(env
, ed
, lu2md(parent
), lname
);
1814 if (IS_ERR(ec_child
)) {
1815 CERROR("Can't find child %s: rc = %ld\n",
1816 lname
->ln_name
, PTR_ERR(ec_child
));
1817 return PTR_ERR(ec_child
);
1820 child
= lu_object_locate(ec_child
->lo_header
, ld
->ld_type
);
1821 if (child
== NULL
) {
1822 CERROR("Can not locate the child %s\n", lname
->ln_name
);
1823 lu_object_put(env
, ec_child
);
1827 CDEBUG(D_RPCTRACE
, "Start getattr object "DFID
"\n",
1828 PFID(lu_object_fid(child
)));
1829 rc
= echo_attr_get_complex(env
, lu2md(child
), ma
);
1831 CERROR("Can not getattr child "DFID
": rc = %d\n",
1832 PFID(lu_object_fid(child
)), rc
);
1833 lu_object_put(env
, ec_child
);
1836 CDEBUG(D_RPCTRACE
, "End getattr object "DFID
"\n",
1837 PFID(lu_object_fid(child
)));
1839 lu_object_put(env
, ec_child
);
1845 static int echo_lookup_object(const struct lu_env
*env
,
1846 struct echo_device
*ed
,
1847 struct lu_object
*ec_parent
,
1848 __u64 id
, int count
)
1850 struct lu_object
*parent
;
1851 struct echo_thread_info
*info
= echo_env_info(env
);
1852 struct lu_name
*lname
= &info
->eti_lname
;
1853 char *name
= info
->eti_name
;
1854 struct lu_fid
*fid
= &info
->eti_fid
;
1855 struct lu_device
*ld
= ed
->ed_next
;
1859 if (ec_parent
== NULL
)
1861 parent
= lu_object_locate(ec_parent
->lo_header
, ld
->ld_type
);
1865 /*prepare the requests*/
1866 for (i
= 0; i
< count
; i
++) {
1867 echo_md_build_name(lname
, name
, id
);
1869 CDEBUG(D_RPCTRACE
, "Start lookup object "DFID
" %s %p\n",
1870 PFID(lu_object_fid(parent
)), lname
->ln_name
, parent
);
1872 rc
= mdo_lookup(env
, lu2md(parent
), lname
, fid
, NULL
);
1874 CERROR("Can not lookup child %s: rc = %d\n", name
, rc
);
1877 CDEBUG(D_RPCTRACE
, "End lookup object "DFID
" %s %p\n",
1878 PFID(lu_object_fid(parent
)), lname
->ln_name
, parent
);
1885 static int echo_md_destroy_internal(const struct lu_env
*env
,
1886 struct echo_device
*ed
,
1887 struct md_object
*parent
,
1888 struct lu_name
*lname
,
1891 struct lu_device
*ld
= ed
->ed_next
;
1892 struct lu_object
*ec_child
;
1893 struct lu_object
*child
;
1896 ec_child
= echo_md_lookup(env
, ed
, parent
, lname
);
1897 if (IS_ERR(ec_child
)) {
1898 CERROR("Can't find child %s: rc = %ld\n", lname
->ln_name
,
1900 return PTR_ERR(ec_child
);
1903 child
= lu_object_locate(ec_child
->lo_header
, ld
->ld_type
);
1904 if (child
== NULL
) {
1905 CERROR("Can not locate the child %s\n", lname
->ln_name
);
1906 GOTO(out_put
, rc
= -EINVAL
);
1909 CDEBUG(D_RPCTRACE
, "Start destroy object "DFID
" %s %p\n",
1910 PFID(lu_object_fid(&parent
->mo_lu
)), lname
->ln_name
, parent
);
1912 rc
= mdo_unlink(env
, parent
, lu2md(child
), lname
, ma
, 0);
1914 CERROR("Can not unlink child %s: rc = %d\n",
1915 lname
->ln_name
, rc
);
1918 CDEBUG(D_RPCTRACE
, "End destroy object "DFID
" %s %p\n",
1919 PFID(lu_object_fid(&parent
->mo_lu
)), lname
->ln_name
, parent
);
1921 lu_object_put(env
, ec_child
);
1925 static int echo_destroy_object(const struct lu_env
*env
,
1926 struct echo_device
*ed
,
1927 struct lu_object
*ec_parent
,
1928 char *name
, int namelen
,
1929 __u64 id
, __u32 mode
,
1932 struct echo_thread_info
*info
= echo_env_info(env
);
1933 struct lu_name
*lname
= &info
->eti_lname
;
1934 struct md_attr
*ma
= &info
->eti_ma
;
1935 struct lu_device
*ld
= ed
->ed_next
;
1936 struct lu_object
*parent
;
1940 parent
= lu_object_locate(ec_parent
->lo_header
, ld
->ld_type
);
1944 memset(ma
, 0, sizeof(*ma
));
1945 ma
->ma_attr
.la_mode
= mode
;
1946 ma
->ma_attr
.la_valid
= LA_CTIME
;
1947 ma
->ma_attr
.la_ctime
= cfs_time_current_64();
1948 ma
->ma_need
= MA_INODE
;
1952 lname
->ln_name
= name
;
1953 lname
->ln_namelen
= namelen
;
1954 rc
= echo_md_destroy_internal(env
, ed
, lu2md(parent
), lname
,
1959 /*prepare the requests*/
1960 for (i
= 0; i
< count
; i
++) {
1961 char *tmp_name
= info
->eti_name
;
1964 echo_md_build_name(lname
, tmp_name
, id
);
1966 rc
= echo_md_destroy_internal(env
, ed
, lu2md(parent
), lname
,
1969 CERROR("Can not unlink child %s: rc = %d\n", name
, rc
);
1978 static struct lu_object
*echo_resolve_path(const struct lu_env
*env
,
1979 struct echo_device
*ed
, char *path
,
1982 struct lu_device
*ld
= ed
->ed_next
;
1983 struct md_device
*md
= lu2md_dev(ld
);
1984 struct echo_thread_info
*info
= echo_env_info(env
);
1985 struct lu_fid
*fid
= &info
->eti_fid
;
1986 struct lu_name
*lname
= &info
->eti_lname
;
1987 struct lu_object
*parent
= NULL
;
1988 struct lu_object
*child
= NULL
;
1991 /*Only support MDD layer right now*/
1992 rc
= md
->md_ops
->mdo_root_get(env
, md
, fid
);
1994 CERROR("get root error: rc = %d\n", rc
);
1998 /* In the function below, .hs_keycmp resolves to
1999 * lu_obj_hop_keycmp() */
2000 /* coverity[overrun-buffer-val] */
2001 parent
= lu_object_find_at(env
, &ed
->ed_cl
.cd_lu_dev
, fid
, NULL
);
2002 if (IS_ERR(parent
)) {
2003 CERROR("Can not find the parent "DFID
": rc = %ld\n",
2004 PFID(fid
), PTR_ERR(parent
));
2009 struct lu_object
*ld_parent
;
2012 e
= strsep(&path
, "/");
2017 if (!path
|| path
[0] == '\0')
2023 lname
->ln_namelen
= strlen(e
);
2025 ld_parent
= lu_object_locate(parent
->lo_header
, ld
->ld_type
);
2026 if (ld_parent
== NULL
) {
2027 lu_object_put(env
, parent
);
2032 child
= echo_md_lookup(env
, ed
, lu2md(ld_parent
), lname
);
2033 lu_object_put(env
, parent
);
2034 if (IS_ERR(child
)) {
2035 rc
= (int)PTR_ERR(child
);
2036 CERROR("lookup %s under parent "DFID
": rc = %d\n",
2037 lname
->ln_name
, PFID(lu_object_fid(ld_parent
)),
2049 static void echo_ucred_init(struct lu_env
*env
)
2051 struct lu_ucred
*ucred
= lu_ucred(env
);
2053 ucred
->uc_valid
= UCRED_INVALID
;
2055 ucred
->uc_suppgids
[0] = -1;
2056 ucred
->uc_suppgids
[1] = -1;
2058 ucred
->uc_uid
= ucred
->uc_o_uid
=
2059 from_kuid(&init_user_ns
, current_uid());
2060 ucred
->uc_gid
= ucred
->uc_o_gid
=
2061 from_kgid(&init_user_ns
, current_gid());
2062 ucred
->uc_fsuid
= ucred
->uc_o_fsuid
=
2063 from_kuid(&init_user_ns
, current_fsuid());
2064 ucred
->uc_fsgid
= ucred
->uc_o_fsgid
=
2065 from_kgid(&init_user_ns
, current_fsgid());
2066 ucred
->uc_cap
= cfs_curproc_cap_pack();
2068 /* remove fs privilege for non-root user. */
2069 if (ucred
->uc_fsuid
)
2070 ucred
->uc_cap
&= ~CFS_CAP_FS_MASK
;
2071 ucred
->uc_valid
= UCRED_NEW
;
2074 static void echo_ucred_fini(struct lu_env
*env
)
2076 struct lu_ucred
*ucred
= lu_ucred(env
);
2077 ucred
->uc_valid
= UCRED_INIT
;
2080 #define ECHO_MD_CTX_TAG (LCT_REMEMBER | LCT_MD_THREAD)
2081 #define ECHO_MD_SES_TAG (LCT_REMEMBER | LCT_SESSION)
2082 static int echo_md_handler(struct echo_device
*ed
, int command
,
2083 char *path
, int path_len
, __u64 id
, int count
,
2084 struct obd_ioctl_data
*data
)
2086 struct echo_thread_info
*info
;
2087 struct lu_device
*ld
= ed
->ed_next
;
2090 struct lu_object
*parent
;
2092 int namelen
= data
->ioc_plen2
;
2096 CERROR("MD echo client is not being initialized properly\n");
2100 if (strcmp(ld
->ld_type
->ldt_name
, LUSTRE_MDD_NAME
)) {
2101 CERROR("Only support MDD layer right now!\n");
2105 env
= cl_env_get(&refcheck
);
2107 return PTR_ERR(env
);
2109 rc
= lu_env_refill_by_tags(env
, ECHO_MD_CTX_TAG
, ECHO_MD_SES_TAG
);
2113 /* init big_lmm buffer */
2114 info
= echo_env_info(env
);
2115 LASSERT(info
->eti_big_lmm
== NULL
);
2116 OBD_ALLOC_LARGE(info
->eti_big_lmm
, MIN_MD_SIZE
);
2117 if (info
->eti_big_lmm
== NULL
)
2118 GOTO(out_env
, rc
= -ENOMEM
);
2119 info
->eti_big_lmmsize
= MIN_MD_SIZE
;
2121 parent
= echo_resolve_path(env
, ed
, path
, path_len
);
2122 if (IS_ERR(parent
)) {
2123 CERROR("Can not resolve the path %s: rc = %ld\n", path
,
2125 GOTO(out_free
, rc
= PTR_ERR(parent
));
2129 OBD_ALLOC(name
, namelen
+ 1);
2131 GOTO(out_put
, rc
= -ENOMEM
);
2132 if (copy_from_user(name
, data
->ioc_pbuf2
, namelen
))
2133 GOTO(out_name
, rc
= -EFAULT
);
2136 echo_ucred_init(env
);
2139 case ECHO_MD_CREATE
:
2140 case ECHO_MD_MKDIR
: {
2141 struct echo_thread_info
*info
= echo_env_info(env
);
2142 __u32 mode
= data
->ioc_obdo2
.o_mode
;
2143 struct lu_fid
*fid
= &info
->eti_fid
;
2144 int stripe_count
= (int)data
->ioc_obdo2
.o_misc
;
2145 int stripe_index
= (int)data
->ioc_obdo2
.o_stripe_idx
;
2147 rc
= ostid_to_fid(fid
, &data
->ioc_obdo1
.o_oi
, 0);
2151 /* In the function below, .hs_keycmp resolves to
2152 * lu_obj_hop_keycmp() */
2153 /* coverity[overrun-buffer-val] */
2154 rc
= echo_create_md_object(env
, ed
, parent
, fid
, name
, namelen
,
2155 id
, mode
, count
, stripe_count
,
2159 case ECHO_MD_DESTROY
:
2160 case ECHO_MD_RMDIR
: {
2161 __u32 mode
= data
->ioc_obdo2
.o_mode
;
2163 rc
= echo_destroy_object(env
, ed
, parent
, name
, namelen
,
2167 case ECHO_MD_LOOKUP
:
2168 rc
= echo_lookup_object(env
, ed
, parent
, id
, count
);
2170 case ECHO_MD_GETATTR
:
2171 rc
= echo_getattr_object(env
, ed
, parent
, id
, count
);
2173 case ECHO_MD_SETATTR
:
2174 rc
= echo_setattr_object(env
, ed
, parent
, id
, count
);
2177 CERROR("unknown command %d\n", command
);
2181 echo_ucred_fini(env
);
2185 OBD_FREE(name
, namelen
+ 1);
2187 lu_object_put(env
, parent
);
2189 LASSERT(info
->eti_big_lmm
);
2190 OBD_FREE_LARGE(info
->eti_big_lmm
, info
->eti_big_lmmsize
);
2191 info
->eti_big_lmm
= NULL
;
2192 info
->eti_big_lmmsize
= 0;
2194 cl_env_put(env
, &refcheck
);
2198 static int echo_create_object(const struct lu_env
*env
, struct echo_device
*ed
,
2199 int on_target
, struct obdo
*oa
, void *ulsm
,
2200 int ulsm_nob
, struct obd_trans_info
*oti
)
2202 struct echo_object
*eco
;
2203 struct echo_client_obd
*ec
= ed
->ed_ec
;
2204 struct lov_stripe_md
*lsm
= NULL
;
2208 if ((oa
->o_valid
& OBD_MD_FLID
) == 0 && /* no obj id */
2209 (on_target
|| /* set_stripe */
2210 ec
->ec_nstripes
!= 0)) { /* LOV */
2211 CERROR ("No valid oid\n");
2215 rc
= echo_alloc_memmd(ed
, &lsm
);
2217 CERROR("Cannot allocate md: rc = %d\n", rc
);
2224 rc
= echo_copyin_lsm (ed
, lsm
, ulsm
, ulsm_nob
);
2228 if (lsm
->lsm_stripe_count
== 0)
2229 lsm
->lsm_stripe_count
= ec
->ec_nstripes
;
2231 if (lsm
->lsm_stripe_size
== 0)
2232 lsm
->lsm_stripe_size
= PAGE_CACHE_SIZE
;
2236 /* setup stripes: indices + default ids if required */
2237 for (i
= 0; i
< lsm
->lsm_stripe_count
; i
++) {
2238 if (ostid_id(&lsm
->lsm_oinfo
[i
]->loi_oi
) == 0)
2239 lsm
->lsm_oinfo
[i
]->loi_oi
= lsm
->lsm_oi
;
2241 lsm
->lsm_oinfo
[i
]->loi_ost_idx
=
2242 (idx
+ i
) % ec
->ec_nstripes
;
2246 /* setup object ID here for !on_target and LOV hint */
2247 if (oa
->o_valid
& OBD_MD_FLID
) {
2248 LASSERT(oa
->o_valid
& OBD_MD_FLGROUP
);
2249 lsm
->lsm_oi
= oa
->o_oi
;
2252 if (ostid_id(&lsm
->lsm_oi
) == 0)
2253 ostid_set_id(&lsm
->lsm_oi
, ++last_object_id
);
2257 /* Only echo objects are allowed to be created */
2258 LASSERT((oa
->o_valid
& OBD_MD_FLGROUP
) &&
2259 (ostid_seq(&oa
->o_oi
) == FID_SEQ_ECHO
));
2260 rc
= obd_create(env
, ec
->ec_exp
, oa
, &lsm
, oti
);
2262 CERROR("Cannot create objects: rc = %d\n", rc
);
2268 /* See what object ID we were given */
2269 oa
->o_oi
= lsm
->lsm_oi
;
2270 oa
->o_valid
|= OBD_MD_FLID
;
2272 eco
= cl_echo_object_find(ed
, &lsm
);
2274 GOTO(failed
, rc
= PTR_ERR(eco
));
2275 cl_echo_object_put(eco
);
2277 CDEBUG(D_INFO
, "oa oid "DOSTID
"\n", POSTID(&oa
->o_oi
));
2281 obd_destroy(env
, ec
->ec_exp
, oa
, lsm
, oti
, NULL
, NULL
);
2283 echo_free_memmd(ed
, &lsm
);
2285 CERROR("create object failed with: rc = %d\n", rc
);
2289 static int echo_get_object(struct echo_object
**ecop
, struct echo_device
*ed
,
2292 struct lov_stripe_md
*lsm
= NULL
;
2293 struct echo_object
*eco
;
2296 if ((oa
->o_valid
& OBD_MD_FLID
) == 0 || ostid_id(&oa
->o_oi
) == 0) {
2297 /* disallow use of object id 0 */
2298 CERROR ("No valid oid\n");
2302 rc
= echo_alloc_memmd(ed
, &lsm
);
2306 lsm
->lsm_oi
= oa
->o_oi
;
2307 if (!(oa
->o_valid
& OBD_MD_FLGROUP
))
2308 ostid_set_seq_echo(&lsm
->lsm_oi
);
2311 eco
= cl_echo_object_find(ed
, &lsm
);
2317 echo_free_memmd(ed
, &lsm
);
2321 static void echo_put_object(struct echo_object
*eco
)
2323 if (cl_echo_object_put(eco
))
2324 CERROR("echo client: drop an object failed");
2328 echo_get_stripe_off_id (struct lov_stripe_md
*lsm
, obd_off
*offp
, obd_id
*idp
)
2330 unsigned long stripe_count
;
2331 unsigned long stripe_size
;
2332 unsigned long width
;
2333 unsigned long woffset
;
2337 if (lsm
->lsm_stripe_count
<= 1)
2341 stripe_size
= lsm
->lsm_stripe_size
;
2342 stripe_count
= lsm
->lsm_stripe_count
;
2344 /* width = # bytes in all stripes */
2345 width
= stripe_size
* stripe_count
;
2347 /* woffset = offset within a width; offset = whole number of widths */
2348 woffset
= do_div (offset
, width
);
2350 stripe_index
= woffset
/ stripe_size
;
2352 *idp
= ostid_id(&lsm
->lsm_oinfo
[stripe_index
]->loi_oi
);
2353 *offp
= offset
* stripe_size
+ woffset
% stripe_size
;
2357 echo_client_page_debug_setup(struct lov_stripe_md
*lsm
,
2358 struct page
*page
, int rw
, obd_id id
,
2359 obd_off offset
, obd_off count
)
2366 /* no partial pages on the client */
2367 LASSERT(count
== PAGE_CACHE_SIZE
);
2371 for (delta
= 0; delta
< PAGE_CACHE_SIZE
; delta
+= OBD_ECHO_BLOCK_SIZE
) {
2372 if (rw
== OBD_BRW_WRITE
) {
2373 stripe_off
= offset
+ delta
;
2375 echo_get_stripe_off_id(lsm
, &stripe_off
, &stripe_id
);
2377 stripe_off
= 0xdeadbeef00c0ffeeULL
;
2378 stripe_id
= 0xdeadbeef00c0ffeeULL
;
2380 block_debug_setup(addr
+ delta
, OBD_ECHO_BLOCK_SIZE
,
2381 stripe_off
, stripe_id
);
2387 static int echo_client_page_debug_check(struct lov_stripe_md
*lsm
,
2388 struct page
*page
, obd_id id
,
2389 obd_off offset
, obd_off count
)
2398 /* no partial pages on the client */
2399 LASSERT(count
== PAGE_CACHE_SIZE
);
2403 for (rc
= delta
= 0; delta
< PAGE_CACHE_SIZE
; delta
+= OBD_ECHO_BLOCK_SIZE
) {
2404 stripe_off
= offset
+ delta
;
2406 echo_get_stripe_off_id (lsm
, &stripe_off
, &stripe_id
);
2408 rc2
= block_debug_check("test_brw",
2409 addr
+ delta
, OBD_ECHO_BLOCK_SIZE
,
2410 stripe_off
, stripe_id
);
2412 CERROR ("Error in echo object "LPX64
"\n", id
);
2421 static int echo_client_kbrw(struct echo_device
*ed
, int rw
, struct obdo
*oa
,
2422 struct echo_object
*eco
, obd_off offset
,
2423 obd_size count
, int async
,
2424 struct obd_trans_info
*oti
)
2426 struct lov_stripe_md
*lsm
= eco
->eo_lsm
;
2428 struct brw_page
*pga
;
2429 struct brw_page
*pgp
;
2430 struct page
**pages
;
2438 verify
= (ostid_id(&oa
->o_oi
) != ECHO_PERSISTENT_OBJID
&&
2439 (oa
->o_valid
& OBD_MD_FLFLAGS
) != 0 &&
2440 (oa
->o_flags
& OBD_FL_DEBUG_CHECK
) != 0);
2442 gfp_mask
= ((ostid_id(&oa
->o_oi
) & 2) == 0) ? GFP_IOFS
: GFP_HIGHUSER
;
2444 LASSERT(rw
== OBD_BRW_WRITE
|| rw
== OBD_BRW_READ
);
2445 LASSERT(lsm
!= NULL
);
2446 LASSERT(ostid_id(&lsm
->lsm_oi
) == ostid_id(&oa
->o_oi
));
2449 (count
& (~CFS_PAGE_MASK
)) != 0)
2452 /* XXX think again with misaligned I/O */
2453 npages
= count
>> PAGE_CACHE_SHIFT
;
2455 if (rw
== OBD_BRW_WRITE
)
2456 brw_flags
= OBD_BRW_ASYNC
;
2458 OBD_ALLOC(pga
, npages
* sizeof(*pga
));
2462 OBD_ALLOC(pages
, npages
* sizeof(*pages
));
2463 if (pages
== NULL
) {
2464 OBD_FREE(pga
, npages
* sizeof(*pga
));
2468 for (i
= 0, pgp
= pga
, off
= offset
;
2470 i
++, pgp
++, off
+= PAGE_CACHE_SIZE
) {
2472 LASSERT (pgp
->pg
== NULL
); /* for cleanup */
2475 OBD_PAGE_ALLOC(pgp
->pg
, gfp_mask
);
2476 if (pgp
->pg
== NULL
)
2480 pgp
->count
= PAGE_CACHE_SIZE
;
2482 pgp
->flag
= brw_flags
;
2485 echo_client_page_debug_setup(lsm
, pgp
->pg
, rw
,
2486 ostid_id(&oa
->o_oi
), off
,
2490 /* brw mode can only be used at client */
2491 LASSERT(ed
->ed_next
!= NULL
);
2492 rc
= cl_echo_object_brw(eco
, rw
, offset
, pages
, npages
, async
);
2495 if (rc
!= 0 || rw
!= OBD_BRW_READ
)
2498 for (i
= 0, pgp
= pga
; i
< npages
; i
++, pgp
++) {
2499 if (pgp
->pg
== NULL
)
2504 vrc
= echo_client_page_debug_check(lsm
, pgp
->pg
,
2505 ostid_id(&oa
->o_oi
),
2506 pgp
->off
, pgp
->count
);
2507 if (vrc
!= 0 && rc
== 0)
2510 OBD_PAGE_FREE(pgp
->pg
);
2512 OBD_FREE(pga
, npages
* sizeof(*pga
));
2513 OBD_FREE(pages
, npages
* sizeof(*pages
));
2517 static int echo_client_prep_commit(const struct lu_env
*env
,
2518 struct obd_export
*exp
, int rw
,
2519 struct obdo
*oa
, struct echo_object
*eco
,
2520 obd_off offset
, obd_size count
,
2521 obd_size batch
, struct obd_trans_info
*oti
,
2524 struct lov_stripe_md
*lsm
= eco
->eo_lsm
;
2525 struct obd_ioobj ioo
;
2526 struct niobuf_local
*lnb
;
2527 struct niobuf_remote
*rnb
;
2529 obd_size npages
, tot_pages
;
2530 int i
, ret
= 0, brw_flags
= 0;
2532 if (count
<= 0 || (count
& (~CFS_PAGE_MASK
)) != 0 ||
2533 (lsm
!= NULL
&& ostid_id(&lsm
->lsm_oi
) != ostid_id(&oa
->o_oi
)))
2536 npages
= batch
>> PAGE_CACHE_SHIFT
;
2537 tot_pages
= count
>> PAGE_CACHE_SHIFT
;
2539 OBD_ALLOC(lnb
, npages
* sizeof(struct niobuf_local
));
2540 OBD_ALLOC(rnb
, npages
* sizeof(struct niobuf_remote
));
2542 if (lnb
== NULL
|| rnb
== NULL
)
2543 GOTO(out
, ret
= -ENOMEM
);
2545 if (rw
== OBD_BRW_WRITE
&& async
)
2546 brw_flags
|= OBD_BRW_ASYNC
;
2548 obdo_to_ioobj(oa
, &ioo
);
2552 for(; tot_pages
; tot_pages
-= npages
) {
2555 if (tot_pages
< npages
)
2558 for (i
= 0; i
< npages
; i
++, off
+= PAGE_CACHE_SIZE
) {
2559 rnb
[i
].offset
= off
;
2560 rnb
[i
].len
= PAGE_CACHE_SIZE
;
2561 rnb
[i
].flags
= brw_flags
;
2564 ioo
.ioo_bufcnt
= npages
;
2565 oti
->oti_transno
= 0;
2568 ret
= obd_preprw(env
, rw
, exp
, oa
, 1, &ioo
, rnb
, &lpages
,
2572 LASSERT(lpages
== npages
);
2574 for (i
= 0; i
< lpages
; i
++) {
2575 struct page
*page
= lnb
[i
].page
;
2577 /* read past eof? */
2578 if (page
== NULL
&& lnb
[i
].rc
== 0)
2582 lnb
[i
].flags
|= OBD_BRW_ASYNC
;
2584 if (ostid_id(&oa
->o_oi
) == ECHO_PERSISTENT_OBJID
||
2585 (oa
->o_valid
& OBD_MD_FLFLAGS
) == 0 ||
2586 (oa
->o_flags
& OBD_FL_DEBUG_CHECK
) == 0)
2589 if (rw
== OBD_BRW_WRITE
)
2590 echo_client_page_debug_setup(lsm
, page
, rw
,
2591 ostid_id(&oa
->o_oi
),
2595 echo_client_page_debug_check(lsm
, page
,
2596 ostid_id(&oa
->o_oi
),
2601 ret
= obd_commitrw(env
, rw
, exp
, oa
, 1, &ioo
,
2602 rnb
, npages
, lnb
, oti
, ret
);
2606 /* Reset oti otherwise it would confuse ldiskfs. */
2607 memset(oti
, 0, sizeof(*oti
));
2609 /* Reuse env context. */
2610 lu_context_exit((struct lu_context
*)&env
->le_ctx
);
2611 lu_context_enter((struct lu_context
*)&env
->le_ctx
);
2616 OBD_FREE(lnb
, npages
* sizeof(struct niobuf_local
));
2618 OBD_FREE(rnb
, npages
* sizeof(struct niobuf_remote
));
2622 static int echo_client_brw_ioctl(const struct lu_env
*env
, int rw
,
2623 struct obd_export
*exp
,
2624 struct obd_ioctl_data
*data
,
2625 struct obd_trans_info
*dummy_oti
)
2627 struct obd_device
*obd
= class_exp2obd(exp
);
2628 struct echo_device
*ed
= obd2echo_dev(obd
);
2629 struct echo_client_obd
*ec
= ed
->ed_ec
;
2630 struct obdo
*oa
= &data
->ioc_obdo1
;
2631 struct echo_object
*eco
;
2636 LASSERT(oa
->o_valid
& OBD_MD_FLGROUP
);
2638 rc
= echo_get_object(&eco
, ed
, oa
);
2642 oa
->o_valid
&= ~OBD_MD_FLHANDLE
;
2644 /* OFD/obdfilter works only via prep/commit */
2645 test_mode
= (long)data
->ioc_pbuf1
;
2649 if (ed
->ed_next
== NULL
&& test_mode
!= 3) {
2651 data
->ioc_plen1
= data
->ioc_count
;
2654 /* Truncate batch size to maximum */
2655 if (data
->ioc_plen1
> PTLRPC_MAX_BRW_SIZE
)
2656 data
->ioc_plen1
= PTLRPC_MAX_BRW_SIZE
;
2658 switch (test_mode
) {
2662 rc
= echo_client_kbrw(ed
, rw
, oa
,
2663 eco
, data
->ioc_offset
,
2664 data
->ioc_count
, async
, dummy_oti
);
2667 rc
= echo_client_prep_commit(env
, ec
->ec_exp
, rw
, oa
,
2668 eco
, data
->ioc_offset
,
2669 data
->ioc_count
, data
->ioc_plen1
,
2675 echo_put_object(eco
);
2680 echo_client_enqueue(struct obd_export
*exp
, struct obdo
*oa
,
2681 int mode
, obd_off offset
, obd_size nob
)
2683 struct echo_device
*ed
= obd2echo_dev(exp
->exp_obd
);
2684 struct lustre_handle
*ulh
= &oa
->o_handle
;
2685 struct echo_object
*eco
;
2689 if (ed
->ed_next
== NULL
)
2692 if (!(mode
== LCK_PR
|| mode
== LCK_PW
))
2695 if ((offset
& (~CFS_PAGE_MASK
)) != 0 ||
2696 (nob
& (~CFS_PAGE_MASK
)) != 0)
2699 rc
= echo_get_object (&eco
, ed
, oa
);
2703 end
= (nob
== 0) ? ((obd_off
) -1) : (offset
+ nob
- 1);
2704 rc
= cl_echo_enqueue(eco
, offset
, end
, mode
, &ulh
->cookie
);
2706 oa
->o_valid
|= OBD_MD_FLHANDLE
;
2707 CDEBUG(D_INFO
, "Cookie is "LPX64
"\n", ulh
->cookie
);
2709 echo_put_object(eco
);
2714 echo_client_cancel(struct obd_export
*exp
, struct obdo
*oa
)
2716 struct echo_device
*ed
= obd2echo_dev(exp
->exp_obd
);
2717 __u64 cookie
= oa
->o_handle
.cookie
;
2719 if ((oa
->o_valid
& OBD_MD_FLHANDLE
) == 0)
2722 CDEBUG(D_INFO
, "Cookie is "LPX64
"\n", cookie
);
2723 return cl_echo_cancel(ed
, cookie
);
2727 echo_client_iocontrol(unsigned int cmd
, struct obd_export
*exp
, int len
,
2728 void *karg
, void *uarg
)
2730 struct obd_device
*obd
= exp
->exp_obd
;
2731 struct echo_device
*ed
= obd2echo_dev(obd
);
2732 struct echo_client_obd
*ec
= ed
->ed_ec
;
2733 struct echo_object
*eco
;
2734 struct obd_ioctl_data
*data
= karg
;
2735 struct obd_trans_info dummy_oti
;
2737 struct oti_req_ack_lock
*ack_lock
;
2740 int rw
= OBD_BRW_READ
;
2744 memset(&dummy_oti
, 0, sizeof(dummy_oti
));
2746 oa
= &data
->ioc_obdo1
;
2747 if (!(oa
->o_valid
& OBD_MD_FLGROUP
)) {
2748 oa
->o_valid
|= OBD_MD_FLGROUP
;
2749 ostid_set_seq_echo(&oa
->o_oi
);
2752 /* This FID is unpacked just for validation at this point */
2753 rc
= ostid_to_fid(&fid
, &oa
->o_oi
, 0);
2761 rc
= lu_env_init(env
, LCT_DT_THREAD
);
2763 GOTO(out
, rc
= -ENOMEM
);
2766 case OBD_IOC_CREATE
: /* may create echo object */
2767 if (!cfs_capable(CFS_CAP_SYS_ADMIN
))
2768 GOTO (out
, rc
= -EPERM
);
2770 rc
= echo_create_object(env
, ed
, 1, oa
, data
->ioc_pbuf1
,
2771 data
->ioc_plen1
, &dummy_oti
);
2774 case OBD_IOC_ECHO_MD
: {
2781 if (!cfs_capable(CFS_CAP_SYS_ADMIN
))
2782 GOTO(out
, rc
= -EPERM
);
2784 count
= data
->ioc_count
;
2785 cmd
= data
->ioc_command
;
2787 id
= ostid_id(&data
->ioc_obdo2
.o_oi
);
2789 dirlen
= data
->ioc_plen1
;
2790 OBD_ALLOC(dir
, dirlen
+ 1);
2792 GOTO(out
, rc
= -ENOMEM
);
2794 if (copy_from_user(dir
, data
->ioc_pbuf1
, dirlen
)) {
2795 OBD_FREE(dir
, data
->ioc_plen1
+ 1);
2796 GOTO(out
, rc
= -EFAULT
);
2799 rc
= echo_md_handler(ed
, cmd
, dir
, dirlen
, id
, count
, data
);
2800 OBD_FREE(dir
, dirlen
+ 1);
2803 case OBD_IOC_ECHO_ALLOC_SEQ
: {
2804 struct lu_env
*cl_env
;
2809 if (!cfs_capable(CFS_CAP_SYS_ADMIN
))
2810 GOTO(out
, rc
= -EPERM
);
2812 cl_env
= cl_env_get(&refcheck
);
2814 GOTO(out
, rc
= PTR_ERR(cl_env
));
2816 rc
= lu_env_refill_by_tags(cl_env
, ECHO_MD_CTX_TAG
,
2819 cl_env_put(cl_env
, &refcheck
);
2823 rc
= seq_client_get_seq(cl_env
, ed
->ed_cl_seq
, &seq
);
2824 cl_env_put(cl_env
, &refcheck
);
2826 CERROR("%s: Can not alloc seq: rc = %d\n",
2831 if (copy_to_user(data
->ioc_pbuf1
, &seq
, data
->ioc_plen1
))
2834 max_count
= LUSTRE_METADATA_SEQ_MAX_WIDTH
;
2835 if (copy_to_user(data
->ioc_pbuf2
, &max_count
,
2840 case OBD_IOC_DESTROY
:
2841 if (!cfs_capable(CFS_CAP_SYS_ADMIN
))
2842 GOTO (out
, rc
= -EPERM
);
2844 rc
= echo_get_object(&eco
, ed
, oa
);
2846 rc
= obd_destroy(env
, ec
->ec_exp
, oa
, eco
->eo_lsm
,
2847 &dummy_oti
, NULL
, NULL
);
2849 eco
->eo_deleted
= 1;
2850 echo_put_object(eco
);
2854 case OBD_IOC_GETATTR
:
2855 rc
= echo_get_object(&eco
, ed
, oa
);
2857 struct obd_info oinfo
= { { { 0 } } };
2858 oinfo
.oi_md
= eco
->eo_lsm
;
2860 rc
= obd_getattr(env
, ec
->ec_exp
, &oinfo
);
2861 echo_put_object(eco
);
2865 case OBD_IOC_SETATTR
:
2866 if (!cfs_capable(CFS_CAP_SYS_ADMIN
))
2867 GOTO (out
, rc
= -EPERM
);
2869 rc
= echo_get_object(&eco
, ed
, oa
);
2871 struct obd_info oinfo
= { { { 0 } } };
2873 oinfo
.oi_md
= eco
->eo_lsm
;
2875 rc
= obd_setattr(env
, ec
->ec_exp
, &oinfo
, NULL
);
2876 echo_put_object(eco
);
2880 case OBD_IOC_BRW_WRITE
:
2881 if (!cfs_capable(CFS_CAP_SYS_ADMIN
))
2882 GOTO (out
, rc
= -EPERM
);
2886 case OBD_IOC_BRW_READ
:
2887 rc
= echo_client_brw_ioctl(env
, rw
, exp
, data
, &dummy_oti
);
2890 case ECHO_IOC_GET_STRIPE
:
2891 rc
= echo_get_object(&eco
, ed
, oa
);
2893 rc
= echo_copyout_lsm(eco
->eo_lsm
, data
->ioc_pbuf1
,
2895 echo_put_object(eco
);
2899 case ECHO_IOC_SET_STRIPE
:
2900 if (!cfs_capable(CFS_CAP_SYS_ADMIN
))
2901 GOTO (out
, rc
= -EPERM
);
2903 if (data
->ioc_pbuf1
== NULL
) { /* unset */
2904 rc
= echo_get_object(&eco
, ed
, oa
);
2906 eco
->eo_deleted
= 1;
2907 echo_put_object(eco
);
2910 rc
= echo_create_object(env
, ed
, 0, oa
,
2912 data
->ioc_plen1
, &dummy_oti
);
2916 case ECHO_IOC_ENQUEUE
:
2917 if (!cfs_capable(CFS_CAP_SYS_ADMIN
))
2918 GOTO (out
, rc
= -EPERM
);
2920 rc
= echo_client_enqueue(exp
, oa
,
2921 data
->ioc_conn1
, /* lock mode */
2923 data
->ioc_count
);/*extent*/
2926 case ECHO_IOC_CANCEL
:
2927 rc
= echo_client_cancel(exp
, oa
);
2931 CERROR ("echo_ioctl(): unrecognised ioctl %#x\n", cmd
);
2932 GOTO (out
, rc
= -ENOTTY
);
2939 /* XXX this should be in a helper also called by target_send_reply */
2940 for (ack_lock
= dummy_oti
.oti_ack_locks
, i
= 0; i
< 4;
2942 if (!ack_lock
->mode
)
2944 ldlm_lock_decref(&ack_lock
->lock
, ack_lock
->mode
);
2950 static int echo_client_setup(const struct lu_env
*env
,
2951 struct obd_device
*obddev
, struct lustre_cfg
*lcfg
)
2953 struct echo_client_obd
*ec
= &obddev
->u
.echo_client
;
2954 struct obd_device
*tgt
;
2955 struct obd_uuid echo_uuid
= { "ECHO_UUID" };
2956 struct obd_connect_data
*ocd
= NULL
;
2959 if (lcfg
->lcfg_bufcount
< 2 || LUSTRE_CFG_BUFLEN(lcfg
, 1) < 1) {
2960 CERROR("requires a TARGET OBD name\n");
2964 tgt
= class_name2obd(lustre_cfg_string(lcfg
, 1));
2965 if (!tgt
|| !tgt
->obd_attached
|| !tgt
->obd_set_up
) {
2966 CERROR("device not attached or not set up (%s)\n",
2967 lustre_cfg_string(lcfg
, 1));
2971 spin_lock_init(&ec
->ec_lock
);
2972 INIT_LIST_HEAD (&ec
->ec_objects
);
2973 INIT_LIST_HEAD (&ec
->ec_locks
);
2975 ec
->ec_nstripes
= 0;
2977 if (!strcmp(tgt
->obd_type
->typ_name
, LUSTRE_MDT_NAME
)) {
2978 lu_context_tags_update(ECHO_MD_CTX_TAG
);
2979 lu_session_tags_update(ECHO_MD_SES_TAG
);
2983 OBD_ALLOC(ocd
, sizeof(*ocd
));
2985 CERROR("Can't alloc ocd connecting to %s\n",
2986 lustre_cfg_string(lcfg
, 1));
2990 ocd
->ocd_connect_flags
= OBD_CONNECT_VERSION
| OBD_CONNECT_REQPORTAL
|
2991 OBD_CONNECT_BRW_SIZE
|
2992 OBD_CONNECT_GRANT
| OBD_CONNECT_FULL20
|
2993 OBD_CONNECT_64BITHASH
| OBD_CONNECT_LVB_TYPE
|
2995 ocd
->ocd_brw_size
= DT_MAX_BRW_SIZE
;
2996 ocd
->ocd_version
= LUSTRE_VERSION_CODE
;
2997 ocd
->ocd_group
= FID_SEQ_ECHO
;
2999 rc
= obd_connect(env
, &ec
->ec_exp
, tgt
, &echo_uuid
, ocd
, NULL
);
3001 /* Turn off pinger because it connects to tgt obd directly. */
3002 spin_lock(&tgt
->obd_dev_lock
);
3003 list_del_init(&ec
->ec_exp
->exp_obd_chain_timed
);
3004 spin_unlock(&tgt
->obd_dev_lock
);
3007 OBD_FREE(ocd
, sizeof(*ocd
));
3010 CERROR("fail to connect to device %s\n",
3011 lustre_cfg_string(lcfg
, 1));
3018 static int echo_client_cleanup(struct obd_device
*obddev
)
3020 struct echo_device
*ed
= obd2echo_dev(obddev
);
3021 struct echo_client_obd
*ec
= &obddev
->u
.echo_client
;
3024 /*Do nothing for Metadata echo client*/
3028 if (ed
->ed_next_ismd
) {
3029 lu_context_tags_clear(ECHO_MD_CTX_TAG
);
3030 lu_session_tags_clear(ECHO_MD_SES_TAG
);
3034 if (!list_empty(&obddev
->obd_exports
)) {
3035 CERROR("still has clients!\n");
3039 LASSERT(atomic_read(&ec
->ec_exp
->exp_refcount
) > 0);
3040 rc
= obd_disconnect(ec
->ec_exp
);
3042 CERROR("fail to disconnect device: %d\n", rc
);
3047 static int echo_client_connect(const struct lu_env
*env
,
3048 struct obd_export
**exp
,
3049 struct obd_device
*src
, struct obd_uuid
*cluuid
,
3050 struct obd_connect_data
*data
, void *localdata
)
3053 struct lustre_handle conn
= { 0 };
3055 rc
= class_connect(&conn
, src
, cluuid
);
3057 *exp
= class_conn2export(&conn
);
3063 static int echo_client_disconnect(struct obd_export
*exp
)
3066 struct obd_device
*obd
;
3067 struct echo_client_obd
*ec
;
3068 struct ec_lock
*ecl
;
3073 GOTO(out
, rc
= -EINVAL
);
3077 ec
= &obd
->u
.echo_client
;
3079 /* no more contention on export's lock list */
3080 while (!list_empty (&exp
->exp_ec_data
.eced_locks
)) {
3081 ecl
= list_entry (exp
->exp_ec_data
.eced_locks
.next
,
3082 struct ec_lock
, ecl_exp_chain
);
3083 list_del (&ecl
->ecl_exp_chain
);
3085 rc
= obd_cancel(ec
->ec_exp
, ecl
->ecl_object
->eco_lsm
,
3086 ecl
->ecl_mode
, &ecl
->ecl_lock_handle
);
3088 CDEBUG (D_INFO
, "Cancel lock on object "LPX64
" on disconnect "
3089 "(%d)\n", ecl
->ecl_object
->eco_id
, rc
);
3091 echo_put_object (ecl
->ecl_object
);
3092 OBD_FREE (ecl
, sizeof (*ecl
));
3096 rc
= class_disconnect(exp
);
3102 static struct obd_ops echo_client_obd_ops
= {
3103 .o_owner
= THIS_MODULE
,
3106 .o_setup
= echo_client_setup
,
3107 .o_cleanup
= echo_client_cleanup
,
3110 .o_iocontrol
= echo_client_iocontrol
,
3111 .o_connect
= echo_client_connect
,
3112 .o_disconnect
= echo_client_disconnect
3115 int echo_client_init(void)
3117 struct lprocfs_static_vars lvars
= { 0 };
3120 lprocfs_echo_init_vars(&lvars
);
3122 rc
= lu_kmem_init(echo_caches
);
3124 rc
= class_register_type(&echo_client_obd_ops
, NULL
,
3126 LUSTRE_ECHO_CLIENT_NAME
,
3129 lu_kmem_fini(echo_caches
);
3134 void echo_client_exit(void)
3136 class_unregister_type(LUSTRE_ECHO_CLIENT_NAME
);
3137 lu_kmem_fini(echo_caches
);
3140 static int __init
obdecho_init(void)
3142 struct lprocfs_static_vars lvars
;
3145 LCONSOLE_INFO("Echo OBD driver; http://www.lustre.org/\n");
3147 LASSERT(PAGE_CACHE_SIZE
% OBD_ECHO_BLOCK_SIZE
== 0);
3149 lprocfs_echo_init_vars(&lvars
);
3152 rc
= echo_client_init();
3157 static void /*__exit*/ obdecho_exit(void)
3163 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
3164 MODULE_DESCRIPTION("Lustre Testing Echo OBD driver");
3165 MODULE_LICENSE("GPL");
3166 MODULE_VERSION(LUSTRE_VERSION_STRING
);
3168 module_init(obdecho_init
);
3169 module_exit(obdecho_exit
);
3171 /** @} echo_client */