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) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/obdclass/llog_test.c
38 * Author: Phil Schwan <phil@clusterfs.com>
39 * Author: Mikhail Pershin <mike.pershin@intel.com>
42 #define DEBUG_SUBSYSTEM S_CLASS
44 #include <linux/module.h>
45 #include <linux/init.h>
47 #include <obd_class.h>
48 #include <lustre_fid.h>
49 #include <lustre_log.h>
51 /* This is slightly more than the number of records that can fit into a
52 * single llog file, because the llog_log_header takes up some of the
53 * space in the first block that cannot be used for the bitmap. */
54 #define LLOG_TEST_RECNUM (LLOG_CHUNK_SIZE * 8)
56 static int llog_test_rand
;
57 static struct obd_uuid uuid
= { .uuid
= "test_uuid" };
58 static struct llog_logid cat_logid
;
60 struct llog_mini_rec
{
61 struct llog_rec_hdr lmr_hdr
;
62 struct llog_rec_tail lmr_tail
;
63 } __attribute__((packed
));
65 static int verify_handle(char *test
, struct llog_handle
*llh
, int num_recs
)
71 for (i
= 0; i
< LLOG_BITMAP_BYTES
* 8; i
++) {
72 if (ext2_test_bit(i
, llh
->lgh_hdr
->llh_bitmap
)) {
78 if (active_recs
!= num_recs
) {
79 CERROR("%s: expected %d active recs after write, found %d\n",
80 test
, num_recs
, active_recs
);
84 if (llh
->lgh_hdr
->llh_count
!= num_recs
) {
85 CERROR("%s: handle->count is %d, expected %d after write\n",
86 test
, llh
->lgh_hdr
->llh_count
, num_recs
);
90 if (llh
->lgh_last_idx
< last_idx
) {
91 CERROR("%s: handle->last_idx is %d, expected %d after write\n",
92 test
, llh
->lgh_last_idx
, last_idx
);
99 /* Test named-log create/open, close */
100 static int llog_test_1(const struct lu_env
*env
,
101 struct obd_device
*obd
, char *name
)
103 struct llog_handle
*llh
;
104 struct llog_ctxt
*ctxt
;
108 CWARN("1a: create a log with name: %s\n", name
);
109 ctxt
= llog_get_context(obd
, LLOG_TEST_ORIG_CTXT
);
112 rc
= llog_open_create(env
, ctxt
, &llh
, NULL
, name
);
114 CERROR("1a: llog_create with name %s failed: %d\n", name
, rc
);
117 rc
= llog_init_handle(env
, llh
, LLOG_F_IS_PLAIN
, &uuid
);
119 CERROR("1a: can't init llog handle: %d\n", rc
);
123 rc
= verify_handle("1", llh
, 1);
125 CWARN("1b: close newly-created log\n");
127 rc2
= llog_close(env
, llh
);
129 CERROR("1b: close log %s failed: %d\n", name
, rc2
);
138 /* Test named-log reopen; returns opened log on success */
139 static int llog_test_2(const struct lu_env
*env
, struct obd_device
*obd
,
140 char *name
, struct llog_handle
**llh
)
142 struct llog_ctxt
*ctxt
;
143 struct llog_handle
*loghandle
;
144 struct llog_logid logid
;
147 CWARN("2a: re-open a log with name: %s\n", name
);
148 ctxt
= llog_get_context(obd
, LLOG_TEST_ORIG_CTXT
);
151 rc
= llog_open(env
, ctxt
, llh
, NULL
, name
, LLOG_OPEN_EXISTS
);
153 CERROR("2a: re-open log with name %s failed: %d\n", name
, rc
);
157 rc
= llog_init_handle(env
, *llh
, LLOG_F_IS_PLAIN
, &uuid
);
159 CERROR("2a: can't init llog handle: %d\n", rc
);
160 GOTO(out_close_llh
, rc
);
163 rc
= verify_handle("2", *llh
, 1);
165 GOTO(out_close_llh
, rc
);
167 /* XXX: there is known issue with tests 2b, MGS is not able to create
168 * anonymous llog, exit now to allow following tests run.
169 * It is fixed in upcoming llog over OSD code */
172 CWARN("2b: create a log without specified NAME & LOGID\n");
173 rc
= llog_open_create(env
, ctxt
, &loghandle
, NULL
, NULL
);
175 CERROR("2b: create log failed\n");
176 GOTO(out_close_llh
, rc
);
178 rc
= llog_init_handle(env
, loghandle
, LLOG_F_IS_PLAIN
, &uuid
);
180 CERROR("2b: can't init llog handle: %d\n", rc
);
184 logid
= loghandle
->lgh_id
;
185 llog_close(env
, loghandle
);
187 CWARN("2c: re-open the log by LOGID\n");
188 rc
= llog_open(env
, ctxt
, &loghandle
, &logid
, NULL
, LLOG_OPEN_EXISTS
);
190 CERROR("2c: re-open log by LOGID failed\n");
191 GOTO(out_close_llh
, rc
);
194 rc
= llog_init_handle(env
, loghandle
, LLOG_F_IS_PLAIN
, &uuid
);
196 CERROR("2c: can't init llog handle: %d\n", rc
);
200 CWARN("2b: destroy this log\n");
201 rc
= llog_destroy(env
, loghandle
);
203 CERROR("2d: destroy log failed\n");
205 llog_close(env
, loghandle
);
208 llog_close(env
, *llh
);
215 /* Test record writing, single and in bulk */
216 static int llog_test_3(const struct lu_env
*env
, struct obd_device
*obd
,
217 struct llog_handle
*llh
)
219 struct llog_gen_rec lgr
;
221 int num_recs
= 1; /* 1 for the header */
223 lgr
.lgr_hdr
.lrh_len
= lgr
.lgr_tail
.lrt_len
= sizeof(lgr
);
224 lgr
.lgr_hdr
.lrh_type
= LLOG_GEN_REC
;
226 CWARN("3a: write one create_rec\n");
227 rc
= llog_write(env
, llh
, &lgr
.lgr_hdr
, NULL
, 0, NULL
, -1);
230 CERROR("3a: write one log record failed: %d\n", rc
);
234 rc
= verify_handle("3a", llh
, num_recs
);
238 CWARN("3b: write 10 cfg log records with 8 bytes bufs\n");
239 for (i
= 0; i
< 10; i
++) {
240 struct llog_rec_hdr hdr
;
244 hdr
.lrh_type
= OBD_CFG_REC
;
245 memset(buf
, 0, sizeof buf
);
246 rc
= llog_write(env
, llh
, &hdr
, NULL
, 0, buf
, -1);
248 CERROR("3b: write 10 records failed at #%d: %d\n",
255 rc
= verify_handle("3b", llh
, num_recs
);
259 CWARN("3c: write 1000 more log records\n");
260 for (i
= 0; i
< 1000; i
++) {
261 rc
= llog_write(env
, llh
, &lgr
.lgr_hdr
, NULL
, 0, NULL
, -1);
263 CERROR("3c: write 1000 records failed at #%d: %d\n",
270 rc
= verify_handle("3c", llh
, num_recs
);
274 CWARN("3d: write log more than BITMAP_SIZE, return -ENOSPC\n");
275 for (i
= 0; i
< LLOG_BITMAP_SIZE(llh
->lgh_hdr
) + 1; i
++) {
276 struct llog_rec_hdr hdr
;
280 memset(buf_odd
, 0, sizeof buf_odd
);
281 memset(buf_even
, 0, sizeof buf_even
);
284 hdr
.lrh_type
= OBD_CFG_REC
;
285 rc
= llog_write(env
, llh
, &hdr
, NULL
, 0, buf_even
, -1);
288 hdr
.lrh_type
= OBD_CFG_REC
;
289 rc
= llog_write(env
, llh
, &hdr
, NULL
, 0, buf_odd
, -1);
294 CERROR("3d: write recs failed at #%d: %d\n",
301 CWARN("3d: write record more than BITMAP size!\n");
304 CWARN("3d: wrote %d more records before end of llog is reached\n",
307 rc
= verify_handle("3d", llh
, num_recs
);
312 /* Test catalogue additions */
313 static int llog_test_4(const struct lu_env
*env
, struct obd_device
*obd
)
315 struct llog_handle
*cath
;
317 int rc
, rc2
, i
, buflen
;
318 struct llog_mini_rec lmr
;
319 struct llog_cookie cookie
;
320 struct llog_ctxt
*ctxt
;
323 struct llog_rec_hdr rec
;
325 ctxt
= llog_get_context(obd
, LLOG_TEST_ORIG_CTXT
);
328 lmr
.lmr_hdr
.lrh_len
= lmr
.lmr_tail
.lrt_len
= LLOG_MIN_REC_SIZE
;
329 lmr
.lmr_hdr
.lrh_type
= 0xf00f00;
331 sprintf(name
, "%x", llog_test_rand
+ 1);
332 CWARN("4a: create a catalog log with name: %s\n", name
);
333 rc
= llog_open_create(env
, ctxt
, &cath
, NULL
, name
);
335 CERROR("4a: llog_create with name %s failed: %d\n", name
, rc
);
336 GOTO(ctxt_release
, rc
);
338 rc
= llog_init_handle(env
, cath
, LLOG_F_IS_CAT
, &uuid
);
340 CERROR("4a: can't init llog handle: %d\n", rc
);
345 cat_logid
= cath
->lgh_id
;
347 CWARN("4b: write 1 record into the catalog\n");
348 rc
= llog_cat_add(env
, cath
, &lmr
.lmr_hdr
, &cookie
, NULL
);
350 CERROR("4b: write 1 catalog record failed at: %d\n", rc
);
354 rc
= verify_handle("4b", cath
, 2);
358 rc
= verify_handle("4b", cath
->u
.chd
.chd_current_log
, num_recs
);
362 CWARN("4c: cancel 1 log record\n");
363 rc
= llog_cat_cancel_records(env
, cath
, 1, &cookie
);
365 CERROR("4c: cancel 1 catalog based record failed: %d\n", rc
);
370 rc
= verify_handle("4c", cath
->u
.chd
.chd_current_log
, num_recs
);
374 CWARN("4d: write %d more log records\n", LLOG_TEST_RECNUM
);
375 for (i
= 0; i
< LLOG_TEST_RECNUM
; i
++) {
376 rc
= llog_cat_add(env
, cath
, &lmr
.lmr_hdr
, NULL
, NULL
);
378 CERROR("4d: write %d records failed at #%d: %d\n",
379 LLOG_TEST_RECNUM
, i
+ 1, rc
);
385 /* make sure new plain llog appears */
386 rc
= verify_handle("4d", cath
, 3);
390 CWARN("4e: add 5 large records, one record per block\n");
391 buflen
= LLOG_CHUNK_SIZE
- sizeof(struct llog_rec_hdr
) -
392 sizeof(struct llog_rec_tail
);
393 OBD_ALLOC(buf
, buflen
);
395 GOTO(out
, rc
= -ENOMEM
);
396 for (i
= 0; i
< 5; i
++) {
397 rec
.lrh_len
= buflen
;
398 rec
.lrh_type
= OBD_CFG_REC
;
399 rc
= llog_cat_add(env
, cath
, &rec
, NULL
, buf
);
401 CERROR("4e: write 5 records failed at #%d: %d\n",
408 OBD_FREE(buf
, buflen
);
410 CWARN("4f: put newly-created catalog\n");
411 rc2
= llog_cat_close(env
, cath
);
413 CERROR("4: close log %s failed: %d\n", name
, rc2
);
422 static int cat_counter
;
424 static int cat_print_cb(const struct lu_env
*env
, struct llog_handle
*llh
,
425 struct llog_rec_hdr
*rec
, void *data
)
427 struct llog_logid_rec
*lir
= (struct llog_logid_rec
*)rec
;
428 struct lu_fid fid
= {0};
430 if (rec
->lrh_type
!= LLOG_LOGID_MAGIC
) {
431 CERROR("invalid record in catalog\n");
435 logid_to_fid(&lir
->lid_id
, &fid
);
437 CWARN("seeing record at index %d - "DFID
" in log "DFID
"\n",
438 rec
->lrh_index
, PFID(&fid
),
439 PFID(lu_object_fid(&llh
->lgh_obj
->do_lu
)));
446 static int plain_counter
;
448 static int plain_print_cb(const struct lu_env
*env
, struct llog_handle
*llh
,
449 struct llog_rec_hdr
*rec
, void *data
)
451 struct lu_fid fid
= {0};
453 if (!(llh
->lgh_hdr
->llh_flags
& LLOG_F_IS_PLAIN
)) {
454 CERROR("log is not plain\n");
458 logid_to_fid(&llh
->lgh_id
, &fid
);
460 CDEBUG(D_INFO
, "seeing record at index %d in log "DFID
"\n",
461 rec
->lrh_index
, PFID(&fid
));
468 static int cancel_count
;
470 static int llog_cancel_rec_cb(const struct lu_env
*env
,
471 struct llog_handle
*llh
,
472 struct llog_rec_hdr
*rec
, void *data
)
474 struct llog_cookie cookie
;
476 if (!(llh
->lgh_hdr
->llh_flags
& LLOG_F_IS_PLAIN
)) {
477 CERROR("log is not plain\n");
481 cookie
.lgc_lgl
= llh
->lgh_id
;
482 cookie
.lgc_index
= rec
->lrh_index
;
484 llog_cat_cancel_records(env
, llh
->u
.phd
.phd_cat_handle
, 1, &cookie
);
486 if (cancel_count
== LLOG_TEST_RECNUM
)
491 /* Test log and catalogue processing */
492 static int llog_test_5(const struct lu_env
*env
, struct obd_device
*obd
)
494 struct llog_handle
*llh
= NULL
;
497 struct llog_mini_rec lmr
;
498 struct llog_ctxt
*ctxt
;
500 ctxt
= llog_get_context(obd
, LLOG_TEST_ORIG_CTXT
);
503 lmr
.lmr_hdr
.lrh_len
= lmr
.lmr_tail
.lrt_len
= LLOG_MIN_REC_SIZE
;
504 lmr
.lmr_hdr
.lrh_type
= 0xf00f00;
506 CWARN("5a: re-open catalog by id\n");
507 rc
= llog_open(env
, ctxt
, &llh
, &cat_logid
, NULL
, LLOG_OPEN_EXISTS
);
509 CERROR("5a: llog_create with logid failed: %d\n", rc
);
513 rc
= llog_init_handle(env
, llh
, LLOG_F_IS_CAT
, &uuid
);
515 CERROR("5a: can't init llog handle: %d\n", rc
);
519 CWARN("5b: print the catalog entries.. we expect 2\n");
521 rc
= llog_process(env
, llh
, cat_print_cb
, "test 5", NULL
);
523 CERROR("5b: process with cat_print_cb failed: %d\n", rc
);
526 if (cat_counter
!= 2) {
527 CERROR("5b: %d entries in catalog\n", cat_counter
);
528 GOTO(out
, rc
= -EINVAL
);
531 CWARN("5c: Cancel %d records, see one log zapped\n", LLOG_TEST_RECNUM
);
533 rc
= llog_cat_process(env
, llh
, llog_cancel_rec_cb
, "foobar", 0, 0);
534 if (rc
!= -LLOG_EEMPTY
) {
535 CERROR("5c: process with cat_cancel_cb failed: %d\n", rc
);
539 CWARN("5c: print the catalog entries.. we expect 1\n");
541 rc
= llog_process(env
, llh
, cat_print_cb
, "test 5", NULL
);
543 CERROR("5c: process with cat_print_cb failed: %d\n", rc
);
546 if (cat_counter
!= 1) {
547 CERROR("5c: %d entries in catalog\n", cat_counter
);
548 GOTO(out
, rc
= -EINVAL
);
551 CWARN("5d: add 1 record to the log with many canceled empty pages\n");
552 rc
= llog_cat_add(env
, llh
, &lmr
.lmr_hdr
, NULL
, NULL
);
554 CERROR("5d: add record to the log with many canceled empty "
559 CWARN("5e: print plain log entries.. expect 6\n");
561 rc
= llog_cat_process(env
, llh
, plain_print_cb
, "foobar", 0, 0);
563 CERROR("5e: process with plain_print_cb failed: %d\n", rc
);
566 if (plain_counter
!= 6) {
567 CERROR("5e: found %d records\n", plain_counter
);
568 GOTO(out
, rc
= -EINVAL
);
571 CWARN("5f: print plain log entries reversely.. expect 6\n");
573 rc
= llog_cat_reverse_process(env
, llh
, plain_print_cb
, "foobar");
575 CERROR("5f: reversely process with plain_print_cb failed:"
579 if (plain_counter
!= 6) {
580 CERROR("5f: found %d records\n", plain_counter
);
581 GOTO(out
, rc
= -EINVAL
);
585 CWARN("5g: close re-opened catalog\n");
586 rc2
= llog_cat_close(env
, llh
);
588 CERROR("5g: close log %s failed: %d\n", name
, rc2
);
598 /* Test client api; open log by name and process */
599 static int llog_test_6(const struct lu_env
*env
, struct obd_device
*obd
,
602 struct obd_device
*mgc_obd
;
603 struct llog_ctxt
*ctxt
;
604 struct obd_uuid
*mgs_uuid
;
605 struct obd_export
*exp
;
606 struct obd_uuid uuid
= { "LLOG_TEST6_UUID" };
607 struct llog_handle
*llh
= NULL
;
608 struct llog_ctxt
*nctxt
;
611 ctxt
= llog_get_context(obd
, LLOG_TEST_ORIG_CTXT
);
613 mgs_uuid
= &ctxt
->loc_exp
->exp_obd
->obd_uuid
;
615 CWARN("6a: re-open log %s using client API\n", name
);
616 mgc_obd
= class_find_client_obd(mgs_uuid
, LUSTRE_MGC_NAME
, NULL
);
617 if (mgc_obd
== NULL
) {
618 CERROR("6a: no MGC devices connected to %s found.\n",
620 GOTO(ctxt_release
, rc
= -ENOENT
);
623 rc
= obd_connect(NULL
, &exp
, mgc_obd
, &uuid
,
624 NULL
/* obd_connect_data */, NULL
);
625 if (rc
!= -EALREADY
) {
626 CERROR("6a: connect on connected MGC (%s) failed to return"
627 " -EALREADY", mgc_obd
->obd_name
);
630 GOTO(ctxt_release
, rc
= -EINVAL
);
633 nctxt
= llog_get_context(mgc_obd
, LLOG_CONFIG_REPL_CTXT
);
634 rc
= llog_open(env
, nctxt
, &llh
, NULL
, name
, LLOG_OPEN_EXISTS
);
636 CERROR("6a: llog_open failed %d\n", rc
);
640 rc
= llog_init_handle(env
, llh
, LLOG_F_IS_PLAIN
, NULL
);
642 CERROR("6a: llog_init_handle failed %d\n", rc
);
646 plain_counter
= 1; /* llog header is first record */
647 CWARN("6b: process log %s using client API\n", name
);
648 rc
= llog_process(env
, llh
, plain_print_cb
, NULL
, NULL
);
650 CERROR("6b: llog_process failed %d\n", rc
);
651 CWARN("6b: processed %d records\n", plain_counter
);
653 rc
= verify_handle("6b", llh
, plain_counter
);
657 plain_counter
= 1; /* llog header is first record */
658 CWARN("6c: process log %s reversely using client API\n", name
);
659 rc
= llog_reverse_process(env
, llh
, plain_print_cb
, NULL
, NULL
);
661 CERROR("6c: llog_reverse_process failed %d\n", rc
);
662 CWARN("6c: processed %d records\n", plain_counter
);
664 rc
= verify_handle("6c", llh
, plain_counter
);
669 rc2
= llog_close(env
, llh
);
671 CERROR("6: llog_close failed: rc = %d\n", rc2
);
676 llog_ctxt_put(nctxt
);
683 struct llog_rec_hdr lrh
; /* common header */
684 struct llog_logid_rec llr
; /* LLOG_LOGID_MAGIC */
685 struct llog_unlink64_rec lur
; /* MDS_UNLINK64_REC */
686 struct llog_setattr64_rec lsr64
; /* MDS_SETATTR64_REC */
687 struct llog_size_change_rec lscr
; /* OST_SZ_REC */
688 struct llog_changelog_rec lcr
; /* CHANGELOG_REC */
689 struct llog_changelog_user_rec lcur
; /* CHANGELOG_USER_REC */
690 struct llog_gen_rec lgr
; /* LLOG_GEN_REC */
693 static int test_7_print_cb(const struct lu_env
*env
, struct llog_handle
*llh
,
694 struct llog_rec_hdr
*rec
, void *data
)
696 struct lu_fid fid
= {0};
698 logid_to_fid(&llh
->lgh_id
, &fid
);
700 CDEBUG(D_OTHER
, "record type %#x at index %d in log "DFID
"\n",
701 rec
->lrh_type
, rec
->lrh_index
, PFID(&fid
));
707 static int test_7_cancel_cb(const struct lu_env
*env
, struct llog_handle
*llh
,
708 struct llog_rec_hdr
*rec
, void *data
)
711 /* test LLOG_DEL_RECORD is working */
712 return LLOG_DEL_RECORD
;
715 static int llog_test_7_sub(const struct lu_env
*env
, struct llog_ctxt
*ctxt
)
717 struct llog_handle
*llh
;
718 int rc
= 0, i
, process_count
;
721 rc
= llog_open_create(env
, ctxt
, &llh
, NULL
, NULL
);
723 CERROR("7_sub: create log failed\n");
727 rc
= llog_init_handle(env
, llh
,
728 LLOG_F_IS_PLAIN
| LLOG_F_ZAP_WHEN_EMPTY
,
731 CERROR("7_sub: can't init llog handle: %d\n", rc
);
734 for (i
= 0; i
< LLOG_BITMAP_SIZE(llh
->lgh_hdr
); i
++) {
735 rc
= llog_write(env
, llh
, &llog_records
.lrh
, NULL
, 0,
740 CERROR("7_sub: write recs failed at #%d: %d\n",
747 CWARN("7_sub: write record more than BITMAP size!\n");
748 GOTO(out_close
, rc
= -EINVAL
);
751 rc
= verify_handle("7_sub", llh
, num_recs
+ 1);
753 CERROR("7_sub: verify handle failed: %d\n", rc
);
756 if (num_recs
< LLOG_BITMAP_SIZE(llh
->lgh_hdr
) - 1)
757 CWARN("7_sub: records are not aligned, written %d from %u\n",
758 num_recs
, LLOG_BITMAP_SIZE(llh
->lgh_hdr
) - 1);
761 rc
= llog_process(env
, llh
, test_7_print_cb
, "test 7", NULL
);
763 CERROR("7_sub: llog process failed: %d\n", rc
);
766 process_count
= plain_counter
;
767 if (process_count
!= num_recs
) {
768 CERROR("7_sub: processed %d records from %d total\n",
769 process_count
, num_recs
);
770 GOTO(out_close
, rc
= -EINVAL
);
774 rc
= llog_reverse_process(env
, llh
, test_7_cancel_cb
, "test 7", NULL
);
776 CERROR("7_sub: reverse llog process failed: %d\n", rc
);
779 if (process_count
!= plain_counter
) {
780 CERROR("7_sub: Reverse/direct processing found different"
781 "number of records: %d/%d\n",
782 plain_counter
, process_count
);
783 GOTO(out_close
, rc
= -EINVAL
);
785 if (llog_exist(llh
)) {
786 CERROR("7_sub: llog exists but should be zapped\n");
787 GOTO(out_close
, rc
= -EEXIST
);
790 rc
= verify_handle("7_sub", llh
, 1);
793 llog_destroy(env
, llh
);
794 llog_close(env
, llh
);
798 /* Test all llog records writing and processing */
799 static int llog_test_7(const struct lu_env
*env
, struct obd_device
*obd
)
801 struct llog_ctxt
*ctxt
;
804 ctxt
= llog_get_context(obd
, LLOG_TEST_ORIG_CTXT
);
806 CWARN("7a: test llog_logid_rec\n");
807 llog_records
.llr
.lid_hdr
.lrh_len
= sizeof(llog_records
.llr
);
808 llog_records
.llr
.lid_tail
.lrt_len
= sizeof(llog_records
.llr
);
809 llog_records
.llr
.lid_hdr
.lrh_type
= LLOG_LOGID_MAGIC
;
811 rc
= llog_test_7_sub(env
, ctxt
);
813 CERROR("7a: llog_logid_rec test failed\n");
817 CWARN("7b: test llog_unlink64_rec\n");
818 llog_records
.lur
.lur_hdr
.lrh_len
= sizeof(llog_records
.lur
);
819 llog_records
.lur
.lur_tail
.lrt_len
= sizeof(llog_records
.lur
);
820 llog_records
.lur
.lur_hdr
.lrh_type
= MDS_UNLINK64_REC
;
822 rc
= llog_test_7_sub(env
, ctxt
);
824 CERROR("7b: llog_unlink_rec test failed\n");
828 CWARN("7c: test llog_setattr64_rec\n");
829 llog_records
.lsr64
.lsr_hdr
.lrh_len
= sizeof(llog_records
.lsr64
);
830 llog_records
.lsr64
.lsr_tail
.lrt_len
= sizeof(llog_records
.lsr64
);
831 llog_records
.lsr64
.lsr_hdr
.lrh_type
= MDS_SETATTR64_REC
;
833 rc
= llog_test_7_sub(env
, ctxt
);
835 CERROR("7c: llog_setattr64_rec test failed\n");
839 CWARN("7d: test llog_size_change_rec\n");
840 llog_records
.lscr
.lsc_hdr
.lrh_len
= sizeof(llog_records
.lscr
);
841 llog_records
.lscr
.lsc_tail
.lrt_len
= sizeof(llog_records
.lscr
);
842 llog_records
.lscr
.lsc_hdr
.lrh_type
= OST_SZ_REC
;
844 rc
= llog_test_7_sub(env
, ctxt
);
846 CERROR("7d: llog_size_change_rec test failed\n");
850 CWARN("7e: test llog_changelog_rec\n");
851 llog_records
.lcr
.cr_hdr
.lrh_len
= sizeof(llog_records
.lcr
);
852 llog_records
.lcr
.cr_tail
.lrt_len
= sizeof(llog_records
.lcr
);
853 llog_records
.lcr
.cr_hdr
.lrh_type
= CHANGELOG_REC
;
855 rc
= llog_test_7_sub(env
, ctxt
);
857 CERROR("7e: llog_changelog_rec test failed\n");
861 CWARN("7f: test llog_changelog_user_rec\n");
862 llog_records
.lcur
.cur_hdr
.lrh_len
= sizeof(llog_records
.lcur
);
863 llog_records
.lcur
.cur_tail
.lrt_len
= sizeof(llog_records
.lcur
);
864 llog_records
.lcur
.cur_hdr
.lrh_type
= CHANGELOG_USER_REC
;
866 rc
= llog_test_7_sub(env
, ctxt
);
868 CERROR("7f: llog_changelog_user_rec test failed\n");
872 CWARN("7g: test llog_gen_rec\n");
873 llog_records
.lgr
.lgr_hdr
.lrh_len
= sizeof(llog_records
.lgr
);
874 llog_records
.lgr
.lgr_tail
.lrt_len
= sizeof(llog_records
.lgr
);
875 llog_records
.lgr
.lgr_hdr
.lrh_type
= LLOG_GEN_REC
;
877 rc
= llog_test_7_sub(env
, ctxt
);
879 CERROR("7g: llog_size_change_rec test failed\n");
887 /* -------------------------------------------------------------------------
888 * Tests above, boring obd functions below
889 * ------------------------------------------------------------------------- */
890 static int llog_run_tests(const struct lu_env
*env
, struct obd_device
*obd
)
892 struct llog_handle
*llh
= NULL
;
893 struct llog_ctxt
*ctxt
;
897 ctxt
= llog_get_context(obd
, LLOG_TEST_ORIG_CTXT
);
900 sprintf(name
, "%x", llog_test_rand
);
902 rc
= llog_test_1(env
, obd
, name
);
904 GOTO(cleanup_ctxt
, rc
);
906 rc
= llog_test_2(env
, obd
, name
, &llh
);
908 GOTO(cleanup_ctxt
, rc
);
910 rc
= llog_test_3(env
, obd
, llh
);
914 rc
= llog_test_4(env
, obd
);
918 rc
= llog_test_5(env
, obd
);
922 rc
= llog_test_6(env
, obd
, name
);
926 rc
= llog_test_7(env
, obd
);
931 err
= llog_destroy(env
, llh
);
933 CERROR("cleanup: llog_destroy failed: %d\n", err
);
934 llog_close(env
, llh
);
943 static struct lprocfs_vars lprocfs_llog_test_obd_vars
[] = { {0} };
944 static struct lprocfs_vars lprocfs_llog_test_module_vars
[] = { {0} };
945 static void lprocfs_llog_test_init_vars(struct lprocfs_static_vars
*lvars
)
947 lvars
->module_vars
= lprocfs_llog_test_module_vars
;
948 lvars
->obd_vars
= lprocfs_llog_test_obd_vars
;
952 static int llog_test_cleanup(struct obd_device
*obd
)
954 struct obd_device
*tgt
;
958 rc
= lu_env_init(&env
, LCT_LOCAL
| LCT_MG_THREAD
);
962 tgt
= obd
->obd_lvfs_ctxt
.dt
->dd_lu_dev
.ld_obd
;
963 rc
= llog_cleanup(&env
, llog_get_context(tgt
, LLOG_TEST_ORIG_CTXT
));
965 CERROR("failed to llog_test_llog_finish: %d\n", rc
);
970 static int llog_test_setup(struct obd_device
*obd
, struct lustre_cfg
*lcfg
)
972 struct obd_device
*tgt
;
973 struct llog_ctxt
*ctxt
;
976 struct lu_context test_session
;
979 if (lcfg
->lcfg_bufcount
< 2) {
980 CERROR("requires a TARGET OBD name\n");
984 if (lcfg
->lcfg_buflens
[1] < 1) {
985 CERROR("requires a TARGET OBD name\n");
990 tgt
= class_name2obd(lustre_cfg_string(lcfg
, 1));
991 if (!tgt
|| !tgt
->obd_attached
|| !tgt
->obd_set_up
) {
992 CERROR("target device not attached or not set up (%s)\n",
993 lustre_cfg_string(lcfg
, 1));
997 rc
= lu_env_init(&env
, LCT_LOCAL
| LCT_MG_THREAD
);
1001 rc
= lu_context_init(&test_session
, LCT_SESSION
);
1003 GOTO(cleanup_env
, rc
);
1004 test_session
.lc_thread
= (struct ptlrpc_thread
*)current
;
1005 lu_context_enter(&test_session
);
1006 env
.le_ses
= &test_session
;
1008 CWARN("Setup llog-test device over %s device\n",
1009 lustre_cfg_string(lcfg
, 1));
1011 OBD_SET_CTXT_MAGIC(&obd
->obd_lvfs_ctxt
);
1012 obd
->obd_lvfs_ctxt
.dt
= lu2dt_dev(tgt
->obd_lu_dev
);
1014 rc
= llog_setup(&env
, tgt
, &tgt
->obd_olg
, LLOG_TEST_ORIG_CTXT
, tgt
,
1017 GOTO(cleanup_session
, rc
);
1019 /* use MGS llog dir for tests */
1020 ctxt
= llog_get_context(tgt
, LLOG_CONFIG_ORIG_CTXT
);
1023 llog_ctxt_put(ctxt
);
1025 ctxt
= llog_get_context(tgt
, LLOG_TEST_ORIG_CTXT
);
1028 llog_ctxt_put(ctxt
);
1030 llog_test_rand
= cfs_rand();
1032 rc
= llog_run_tests(&env
, tgt
);
1034 llog_test_cleanup(obd
);
1036 lu_context_exit(&test_session
);
1037 lu_context_fini(&test_session
);
1043 static struct obd_ops llog_obd_ops
= {
1044 .o_owner
= THIS_MODULE
,
1045 .o_setup
= llog_test_setup
,
1046 .o_cleanup
= llog_test_cleanup
,
1049 static int __init
llog_test_init(void)
1051 struct lprocfs_static_vars lvars
;
1053 lprocfs_llog_test_init_vars(&lvars
);
1054 return class_register_type(&llog_obd_ops
, NULL
,
1055 lvars
.module_vars
, "llog_test", NULL
);
1058 static void __exit
llog_test_exit(void)
1060 class_unregister_type("llog_test");
1063 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
1064 MODULE_DESCRIPTION("llog test module");
1065 MODULE_LICENSE("GPL");
1067 module_init(llog_test_init
);
1068 module_exit(llog_test_exit
);