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) 2011, 2012, Intel, Inc.
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;
110 CWARN("1a: create a log with name: %s\n", name);
111 ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT);
114 rc = llog_open_create(env, ctxt, &llh, NULL, name);
116 CERROR("1a: llog_create with name %s failed: %d\n", name, rc);
119 rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, &uuid);
121 CERROR("1a: can't init llog handle: %d\n", rc);
125 rc = verify_handle("1", llh, 1);
127 CWARN("1b: close newly-created log\n");
129 rc2 = llog_close(env, llh);
131 CERROR("1b: close log %s failed: %d\n", name, rc2);
140 /* Test named-log reopen; returns opened log on success */
141 static int llog_test_2(const struct lu_env *env, struct obd_device *obd,
142 char *name, struct llog_handle **llh)
144 struct llog_ctxt *ctxt;
145 struct llog_handle *loghandle;
146 struct llog_logid logid;
151 CWARN("2a: re-open a log with name: %s\n", name);
152 ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT);
155 rc = llog_open(env, ctxt, llh, NULL, name, LLOG_OPEN_EXISTS);
157 CERROR("2a: re-open log with name %s failed: %d\n", name, rc);
161 llog_init_handle(env, *llh, LLOG_F_IS_PLAIN, &uuid);
163 CERROR("2a: can't init llog handle: %d\n", rc);
164 GOTO(out_close_llh, rc);
167 rc = verify_handle("2", *llh, 1);
169 GOTO(out_close_llh, rc);
171 /* XXX: there is known issue with tests 2b, MGS is not able to create
172 * anonymous llog, exit now to allow following tests run.
173 * It is fixed in upcoming llog over OSD code */
176 CWARN("2b: create a log without specified NAME & LOGID\n");
177 rc = llog_open_create(env, ctxt, &loghandle, NULL, NULL);
179 CERROR("2b: create log failed\n");
180 GOTO(out_close_llh, rc);
182 rc = llog_init_handle(env, loghandle, LLOG_F_IS_PLAIN, &uuid);
184 CERROR("2b: can't init llog handle: %d\n", rc);
188 logid = loghandle->lgh_id;
189 llog_close(env, loghandle);
191 CWARN("2c: re-open the log by LOGID\n");
192 rc = llog_open(env, ctxt, &loghandle, &logid, NULL, LLOG_OPEN_EXISTS);
194 CERROR("2c: re-open log by LOGID failed\n");
195 GOTO(out_close_llh, rc);
198 rc = llog_init_handle(env, loghandle, LLOG_F_IS_PLAIN, &uuid);
200 CERROR("2c: can't init llog handle: %d\n", rc);
204 CWARN("2b: destroy this log\n");
205 rc = llog_destroy(env, loghandle);
207 CERROR("2d: destroy log failed\n");
209 llog_close(env, loghandle);
212 llog_close(env, *llh);
219 /* Test record writing, single and in bulk */
220 static int llog_test_3(const struct lu_env *env, struct obd_device *obd,
221 struct llog_handle *llh)
223 struct llog_gen_rec lgr;
225 int num_recs = 1; /* 1 for the header */
229 lgr.lgr_hdr.lrh_len = lgr.lgr_tail.lrt_len = sizeof(lgr);
230 lgr.lgr_hdr.lrh_type = LLOG_GEN_REC;
232 CWARN("3a: write one create_rec\n");
233 rc = llog_write(env, llh, &lgr.lgr_hdr, NULL, 0, NULL, -1);
236 CERROR("3a: write one log record failed: %d\n", rc);
240 rc = verify_handle("3a", llh, num_recs);
244 CWARN("3b: write 10 cfg log records with 8 bytes bufs\n");
245 for (i = 0; i < 10; i++) {
246 struct llog_rec_hdr hdr;
250 hdr.lrh_type = OBD_CFG_REC;
251 memset(buf, 0, sizeof buf);
252 rc = llog_write(env, llh, &hdr, NULL, 0, buf, -1);
254 CERROR("3b: write 10 records failed at #%d: %d\n",
261 rc = verify_handle("3b", llh, num_recs);
265 CWARN("3c: write 1000 more log records\n");
266 for (i = 0; i < 1000; i++) {
267 rc = llog_write(env, llh, &lgr.lgr_hdr, NULL, 0, NULL, -1);
269 CERROR("3c: write 1000 records failed at #%d: %d\n",
276 rc = verify_handle("3c", llh, num_recs);
280 CWARN("3d: write log more than BITMAP_SIZE, return -ENOSPC\n");
281 for (i = 0; i < LLOG_BITMAP_SIZE(llh->lgh_hdr) + 1; i++) {
282 struct llog_rec_hdr hdr;
286 memset(buf_odd, 0, sizeof buf_odd);
287 memset(buf_even, 0, sizeof buf_even);
290 hdr.lrh_type = OBD_CFG_REC;
291 rc = llog_write(env, llh, &hdr, NULL, 0, buf_even, -1);
294 hdr.lrh_type = OBD_CFG_REC;
295 rc = llog_write(env, llh, &hdr, NULL, 0, buf_odd, -1);
300 CERROR("3d: write recs failed at #%d: %d\n",
307 CWARN("3d: write record more than BITMAP size!\n");
310 CWARN("3d: wrote %d more records before end of llog is reached\n",
313 rc = verify_handle("3d", llh, num_recs);
318 /* Test catalogue additions */
319 static int llog_test_4(const struct lu_env *env, struct obd_device *obd)
321 struct llog_handle *cath;
323 int rc, rc2, i, buflen;
324 struct llog_mini_rec lmr;
325 struct llog_cookie cookie;
326 struct llog_ctxt *ctxt;
329 struct llog_rec_hdr rec;
333 ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT);
336 lmr.lmr_hdr.lrh_len = lmr.lmr_tail.lrt_len = LLOG_MIN_REC_SIZE;
337 lmr.lmr_hdr.lrh_type = 0xf00f00;
339 sprintf(name, "%x", llog_test_rand + 1);
340 CWARN("4a: create a catalog log with name: %s\n", name);
341 rc = llog_open_create(env, ctxt, &cath, NULL, name);
343 CERROR("4a: llog_create with name %s failed: %d\n", name, rc);
344 GOTO(ctxt_release, rc);
346 llog_init_handle(env, cath, LLOG_F_IS_CAT, &uuid);
348 CERROR("4a: can't init llog handle: %d\n", rc);
353 cat_logid = cath->lgh_id;
355 /* XXX: there is known issue with tests 4b, MGS is not able to add
356 * anonymous plain llog, si we exit now to allow following tests run.
357 * It is fixed in upcoming llog over OSD code */
360 CWARN("4b: write 1 record into the catalog\n");
361 rc = llog_cat_add(env, cath, &lmr.lmr_hdr, &cookie, NULL);
363 CERROR("4b: write 1 catalog record failed at: %d\n", rc);
367 rc = verify_handle("4b", cath, 2);
371 rc = verify_handle("4b", cath->u.chd.chd_current_log, num_recs);
375 CWARN("4c: cancel 1 log record\n");
376 rc = llog_cat_cancel_records(env, cath, 1, &cookie);
378 CERROR("4c: cancel 1 catalog based record failed: %d\n", rc);
383 rc = verify_handle("4c", cath->u.chd.chd_current_log, num_recs);
387 CWARN("4d: write %d more log records\n", LLOG_TEST_RECNUM);
388 for (i = 0; i < LLOG_TEST_RECNUM; i++) {
389 rc = llog_cat_add(env, cath, &lmr.lmr_hdr, NULL, NULL);
391 CERROR("4d: write %d records failed at #%d: %d\n",
392 LLOG_TEST_RECNUM, i + 1, rc);
398 /* make sure new plain llog appears */
399 rc = verify_handle("4d", cath, 3);
403 CWARN("4e: add 5 large records, one record per block\n");
404 buflen = LLOG_CHUNK_SIZE - sizeof(struct llog_rec_hdr) -
405 sizeof(struct llog_rec_tail);
406 OBD_ALLOC(buf, buflen);
408 GOTO(out, rc = -ENOMEM);
409 for (i = 0; i < 5; i++) {
410 rec.lrh_len = buflen;
411 rec.lrh_type = OBD_CFG_REC;
412 rc = llog_cat_add(env, cath, &rec, NULL, buf);
414 CERROR("4e: write 5 records failed at #%d: %d\n",
421 OBD_FREE(buf, buflen);
423 CWARN("4f: put newly-created catalog\n");
424 rc2 = llog_cat_close(env, cath);
426 CERROR("4: close log %s failed: %d\n", name, rc2);
435 static int cat_counter;
437 static int cat_print_cb(const struct lu_env *env, struct llog_handle *llh,
438 struct llog_rec_hdr *rec, void *data)
440 struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
442 if (rec->lrh_type != LLOG_LOGID_MAGIC) {
443 CERROR("invalid record in catalog\n");
447 CWARN("seeing record at index %d - "LPX64":%x in log "LPX64"\n",
448 rec->lrh_index, lir->lid_id.lgl_oid,
449 lir->lid_id.lgl_ogen, llh->lgh_id.lgl_oid);
456 static int plain_counter;
458 static int plain_print_cb(const struct lu_env *env, struct llog_handle *llh,
459 struct llog_rec_hdr *rec, void *data)
461 if (!(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN)) {
462 CERROR("log is not plain\n");
466 CDEBUG(D_INFO, "seeing record at index %d in log "LPX64"\n",
467 rec->lrh_index, llh->lgh_id.lgl_oid);
474 static int cancel_count;
476 static int llog_cancel_rec_cb(const struct lu_env *env,
477 struct llog_handle *llh,
478 struct llog_rec_hdr *rec, void *data)
480 struct llog_cookie cookie;
482 if (!(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN)) {
483 CERROR("log is not plain\n");
487 cookie.lgc_lgl = llh->lgh_id;
488 cookie.lgc_index = rec->lrh_index;
490 llog_cat_cancel_records(env, llh->u.phd.phd_cat_handle, 1, &cookie);
492 if (cancel_count == LLOG_TEST_RECNUM)
493 RETURN(-LLOG_EEMPTY);
497 /* Test log and catalogue processing */
498 static int llog_test_5(const struct lu_env *env, struct obd_device *obd)
500 struct llog_handle *llh = NULL;
503 struct llog_mini_rec lmr;
504 struct llog_ctxt *ctxt;
508 ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT);
511 lmr.lmr_hdr.lrh_len = lmr.lmr_tail.lrt_len = LLOG_MIN_REC_SIZE;
512 lmr.lmr_hdr.lrh_type = 0xf00f00;
514 CWARN("5a: re-open catalog by id\n");
515 rc = llog_open(env, ctxt, &llh, &cat_logid, NULL, LLOG_OPEN_EXISTS);
517 CERROR("5a: llog_create with logid failed: %d\n", rc);
521 llog_init_handle(env, llh, LLOG_F_IS_CAT, &uuid);
523 CERROR("5a: can't init llog handle: %d\n", rc);
527 /* XXX: depends on tests 4 which is not working yet */
530 CWARN("5b: print the catalog entries.. we expect 2\n");
532 rc = llog_process(env, llh, cat_print_cb, "test 5", NULL);
534 CERROR("5b: process with cat_print_cb failed: %d\n", rc);
537 if (cat_counter != 2) {
538 CERROR("5b: %d entries in catalog\n", cat_counter);
539 GOTO(out, rc = -EINVAL);
542 CWARN("5c: Cancel %d records, see one log zapped\n", LLOG_TEST_RECNUM);
544 rc = llog_cat_process(env, llh, llog_cancel_rec_cb, "foobar", 0, 0);
545 if (rc != -LLOG_EEMPTY) {
546 CERROR("5c: process with cat_cancel_cb failed: %d\n", rc);
550 CWARN("5c: print the catalog entries.. we expect 1\n");
552 rc = llog_process(env, llh, cat_print_cb, "test 5", NULL);
554 CERROR("5c: process with cat_print_cb failed: %d\n", rc);
557 if (cat_counter != 1) {
558 CERROR("5c: %d entries in catalog\n", cat_counter);
559 GOTO(out, rc = -EINVAL);
562 CWARN("5d: add 1 record to the log with many canceled empty pages\n");
563 rc = llog_cat_add(env, llh, &lmr.lmr_hdr, NULL, NULL);
565 CERROR("5d: add record to the log with many canceled empty "
570 CWARN("5e: print plain log entries.. expect 6\n");
572 rc = llog_cat_process(env, llh, plain_print_cb, "foobar", 0, 0);
574 CERROR("5e: process with plain_print_cb failed: %d\n", rc);
577 if (plain_counter != 6) {
578 CERROR("5e: found %d records\n", plain_counter);
579 GOTO(out, rc = -EINVAL);
582 CWARN("5f: print plain log entries reversely.. expect 6\n");
584 rc = llog_cat_reverse_process(env, llh, plain_print_cb, "foobar");
586 CERROR("5f: reversely process with plain_print_cb failed:"
590 if (plain_counter != 6) {
591 CERROR("5f: found %d records\n", plain_counter);
592 GOTO(out, rc = -EINVAL);
596 CWARN("5g: close re-opened catalog\n");
597 rc2 = llog_cat_close(env, llh);
599 CERROR("5g: close log %s failed: %d\n", name, rc2);
609 /* Test client api; open log by name and process */
610 static int llog_test_6(const struct lu_env *env, struct obd_device *obd,
613 struct obd_device *mgc_obd;
614 struct llog_ctxt *ctxt;
615 struct obd_uuid *mgs_uuid;
616 struct obd_export *exp;
617 struct obd_uuid uuid = { "LLOG_TEST6_UUID" };
618 struct llog_handle *llh = NULL;
619 struct llog_ctxt *nctxt;
622 ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT);
624 mgs_uuid = &ctxt->loc_exp->exp_obd->obd_uuid;
626 CWARN("6a: re-open log %s using client API\n", name);
627 mgc_obd = class_find_client_obd(mgs_uuid, LUSTRE_MGC_NAME, NULL);
628 if (mgc_obd == NULL) {
629 CERROR("6a: no MGC devices connected to %s found.\n",
631 GOTO(ctxt_release, rc = -ENOENT);
634 rc = obd_connect(NULL, &exp, mgc_obd, &uuid,
635 NULL /* obd_connect_data */, NULL);
636 if (rc != -EALREADY) {
637 CERROR("6a: connect on connected MDC (%s) failed to return"
638 " -EALREADY", mgc_obd->obd_name);
641 GOTO(ctxt_release, rc = -EINVAL);
644 nctxt = llog_get_context(mgc_obd, LLOG_CONFIG_REPL_CTXT);
645 rc = llog_open(env, nctxt, &llh, NULL, name, LLOG_OPEN_EXISTS);
647 CERROR("6a: llog_open failed %d\n", rc);
651 rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL);
653 CERROR("6a: llog_init_handle failed %d\n", rc);
657 plain_counter = 1; /* llog header is first record */
658 CWARN("6b: process log %s using client API\n", name);
659 rc = llog_process(env, llh, plain_print_cb, NULL, NULL);
661 CERROR("6b: llog_process failed %d\n", rc);
662 CWARN("6b: processed %d records\n", plain_counter);
664 rc = verify_handle("6b", llh, plain_counter);
668 plain_counter = 1; /* llog header is first record */
669 CWARN("6c: process log %s reversely using client API\n", name);
670 rc = llog_reverse_process(env, llh, plain_print_cb, NULL, NULL);
672 CERROR("6c: llog_reverse_process failed %d\n", rc);
673 CWARN("6c: processed %d records\n", plain_counter);
675 rc = verify_handle("6c", llh, plain_counter);
680 rc2 = llog_close(env, llh);
682 CERROR("6: llog_close failed: rc = %d\n", rc2);
687 llog_ctxt_put(nctxt);
694 struct llog_rec_hdr lrh; /* common header */
695 struct llog_logid_rec llr; /* LLOG_LOGID_MAGIC */
696 struct llog_unlink64_rec lur; /* MDS_UNLINK64_REC */
697 struct llog_setattr64_rec lsr64; /* MDS_SETATTR64_REC */
698 struct llog_size_change_rec lscr; /* OST_SZ_REC */
699 struct llog_changelog_rec lcr; /* CHANGELOG_REC */
700 struct llog_changelog_user_rec lcur; /* CHANGELOG_USER_REC */
701 struct llog_gen_rec lgr; /* LLOG_GEN_REC */
704 static int test_7_print_cb(const struct lu_env *env, struct llog_handle *llh,
705 struct llog_rec_hdr *rec, void *data)
709 logid_to_fid(&llh->lgh_id, &fid);
711 CDEBUG(D_OTHER, "record type %#x at index %d in log "DFID"\n",
712 rec->lrh_type, rec->lrh_index, PFID(&fid));
718 static int test_7_cancel_cb(const struct lu_env *env, struct llog_handle *llh,
719 struct llog_rec_hdr *rec, void *data)
722 /* test LLOG_DEL_RECORD is working */
723 return LLOG_DEL_RECORD;
726 static int llog_test_7_sub(const struct lu_env *env, struct llog_ctxt *ctxt)
728 struct llog_handle *llh;
729 int rc = 0, i, process_count;
734 rc = llog_open_create(env, ctxt, &llh, NULL, "llt_test7");
736 CERROR("7_sub: create log failed\n");
740 rc = llog_init_handle(env, llh,
741 LLOG_F_IS_PLAIN | LLOG_F_ZAP_WHEN_EMPTY,
744 CERROR("7_sub: can't init llog handle: %d\n", rc);
747 for (i = 0; i < LLOG_BITMAP_SIZE(llh->lgh_hdr); i++) {
748 rc = llog_write(env, llh, &llog_records.lrh, NULL, 0,
753 CERROR("7_sub: write recs failed at #%d: %d\n",
760 CWARN("7_sub: write record more than BITMAP size!\n");
761 GOTO(out_close, rc = -EINVAL);
764 rc = verify_handle("7_sub", llh, num_recs + 1);
766 CERROR("7_sub: verify handle failed: %d\n", rc);
769 if (num_recs < LLOG_BITMAP_SIZE(llh->lgh_hdr) - 1)
770 CWARN("7_sub: records are not aligned, written %d from %u\n",
771 num_recs, LLOG_BITMAP_SIZE(llh->lgh_hdr) - 1);
774 rc = llog_process(env, llh, test_7_print_cb, "test 7", NULL);
776 CERROR("7_sub: llog process failed: %d\n", rc);
779 process_count = plain_counter;
780 if (process_count != num_recs) {
781 CERROR("7_sub: processed %d records from %d total\n",
782 process_count, num_recs);
783 GOTO(out_close, rc = -EINVAL);
787 rc = llog_reverse_process(env, llh, test_7_cancel_cb, "test 7", NULL);
789 CERROR("7_sub: reverse llog process failed: %d\n", rc);
792 if (process_count != plain_counter) {
793 CERROR("7_sub: Reverse/direct processing found different"
794 "number of records: %d/%d\n",
795 plain_counter, process_count);
796 GOTO(out_close, rc = -EINVAL);
798 if (llog_exist(llh)) {
799 CERROR("7_sub: llog exists but should be zapped\n");
800 GOTO(out_close, rc = -EEXIST);
803 rc = verify_handle("7_sub", llh, 1);
806 llog_destroy(env, llh);
807 llog_close(env, llh);
811 /* Test all llog records writing and processing */
812 static int llog_test_7(const struct lu_env *env, struct obd_device *obd)
814 struct llog_ctxt *ctxt;
819 ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT);
821 CWARN("7a: test llog_logid_rec\n");
822 llog_records.llr.lid_hdr.lrh_len = sizeof(llog_records.llr);
823 llog_records.llr.lid_tail.lrt_len = sizeof(llog_records.llr);
824 llog_records.llr.lid_hdr.lrh_type = LLOG_LOGID_MAGIC;
826 rc = llog_test_7_sub(env, ctxt);
828 CERROR("7a: llog_logid_rec test failed\n");
832 CWARN("7b: test llog_unlink64_rec\n");
833 llog_records.lur.lur_hdr.lrh_len = sizeof(llog_records.lur);
834 llog_records.lur.lur_tail.lrt_len = sizeof(llog_records.lur);
835 llog_records.lur.lur_hdr.lrh_type = MDS_UNLINK64_REC;
837 rc = llog_test_7_sub(env, ctxt);
839 CERROR("7b: llog_unlink_rec test failed\n");
843 CWARN("7c: test llog_setattr64_rec\n");
844 llog_records.lsr64.lsr_hdr.lrh_len = sizeof(llog_records.lsr64);
845 llog_records.lsr64.lsr_tail.lrt_len = sizeof(llog_records.lsr64);
846 llog_records.lsr64.lsr_hdr.lrh_type = MDS_SETATTR64_REC;
848 rc = llog_test_7_sub(env, ctxt);
850 CERROR("7c: llog_setattr64_rec test failed\n");
854 CWARN("7d: test llog_size_change_rec\n");
855 llog_records.lscr.lsc_hdr.lrh_len = sizeof(llog_records.lscr);
856 llog_records.lscr.lsc_tail.lrt_len = sizeof(llog_records.lscr);
857 llog_records.lscr.lsc_hdr.lrh_type = OST_SZ_REC;
859 rc = llog_test_7_sub(env, ctxt);
861 CERROR("7d: llog_size_change_rec test failed\n");
865 CWARN("7e: test llog_changelog_rec\n");
866 llog_records.lcr.cr_hdr.lrh_len = sizeof(llog_records.lcr);
867 llog_records.lcr.cr_tail.lrt_len = sizeof(llog_records.lcr);
868 llog_records.lcr.cr_hdr.lrh_type = CHANGELOG_REC;
870 rc = llog_test_7_sub(env, ctxt);
872 CERROR("7e: llog_changelog_rec test failed\n");
876 CWARN("7f: test llog_changelog_user_rec\n");
877 llog_records.lcur.cur_hdr.lrh_len = sizeof(llog_records.lcur);
878 llog_records.lcur.cur_tail.lrt_len = sizeof(llog_records.lcur);
879 llog_records.lcur.cur_hdr.lrh_type = CHANGELOG_USER_REC;
881 rc = llog_test_7_sub(env, ctxt);
883 CERROR("7f: llog_changelog_user_rec test failed\n");
887 CWARN("7g: test llog_gen_rec\n");
888 llog_records.lgr.lgr_hdr.lrh_len = sizeof(llog_records.lgr);
889 llog_records.lgr.lgr_tail.lrt_len = sizeof(llog_records.lgr);
890 llog_records.lgr.lgr_hdr.lrh_type = LLOG_GEN_REC;
892 rc = llog_test_7_sub(env, ctxt);
894 CERROR("7g: llog_size_change_rec test failed\n");
902 /* -------------------------------------------------------------------------
903 * Tests above, boring obd functions below
904 * ------------------------------------------------------------------------- */
905 static int llog_run_tests(const struct lu_env *env, struct obd_device *obd)
907 struct llog_handle *llh = NULL;
908 struct lvfs_run_ctxt saved;
909 struct llog_ctxt *ctxt;
914 ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT);
917 sprintf(name, "%x", llog_test_rand);
918 push_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
920 rc = llog_test_1(env, obd, name);
922 GOTO(cleanup_ctxt, rc);
924 rc = llog_test_2(env, obd, name, &llh);
926 GOTO(cleanup_ctxt, rc);
928 rc = llog_test_3(env, obd, llh);
932 rc = llog_test_4(env, obd);
936 rc = llog_test_5(env, obd);
940 rc = llog_test_6(env, obd, name);
944 rc = llog_test_7(env, obd);
949 err = llog_destroy(env, llh);
951 CERROR("cleanup: llog_destroy failed: %d\n", err);
952 llog_close(env, llh);
956 pop_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
962 static struct lprocfs_vars lprocfs_llog_test_obd_vars[] = { {0} };
963 static struct lprocfs_vars lprocfs_llog_test_module_vars[] = { {0} };
964 static void lprocfs_llog_test_init_vars(struct lprocfs_static_vars *lvars)
966 lvars->module_vars = lprocfs_llog_test_module_vars;
967 lvars->obd_vars = lprocfs_llog_test_obd_vars;
971 static int llog_test_cleanup(struct obd_device *obd)
975 rc = llog_cleanup(llog_get_context(obd, LLOG_TEST_ORIG_CTXT));
977 CERROR("failed to llog_test_llog_finish: %d\n", rc);
981 static int llog_test_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
983 struct obd_device *tgt;
989 if (lcfg->lcfg_bufcount < 2) {
990 CERROR("requires a TARGET OBD name\n");
994 if (lcfg->lcfg_buflens[1] < 1) {
995 CERROR("requires a TARGET OBD name\n");
1000 tgt = class_name2obd(lustre_cfg_string(lcfg, 1));
1001 if (!tgt || !tgt->obd_attached || !tgt->obd_set_up) {
1002 CERROR("target device not attached or not set up (%s)\n",
1003 lustre_cfg_string(lcfg, 1));
1007 rc = lu_env_init(&env, LCT_LOCAL | LCT_MG_THREAD);
1011 CWARN("Setup llog-test device over %s device\n",
1012 lustre_cfg_string(lcfg, 1));
1014 rc = llog_setup(obd, &obd->obd_olg, LLOG_TEST_ORIG_CTXT, tgt, 0, NULL,
1017 GOTO(cleanup_env, rc);
1019 llog_test_rand = cfs_rand();
1021 rc = llog_run_tests(&env, obd);
1023 llog_test_cleanup(obd);
1029 static struct obd_ops llog_obd_ops = {
1030 .o_owner = THIS_MODULE,
1031 .o_setup = llog_test_setup,
1032 .o_cleanup = llog_test_cleanup,
1035 static int __init llog_test_init(void)
1037 struct lprocfs_static_vars lvars;
1039 lprocfs_llog_test_init_vars(&lvars);
1040 return class_register_type(&llog_obd_ops, NULL,
1041 lvars.module_vars, "llog_test", NULL);
1044 static void __exit llog_test_exit(void)
1046 class_unregister_type("llog_test");
1049 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
1050 MODULE_DESCRIPTION("llog test module");
1051 MODULE_LICENSE("GPL");
1053 module_init(llog_test_init);
1054 module_exit(llog_test_exit);