+static int llog_test_7_sub(const struct lu_env *env, struct llog_ctxt *ctxt)
+{
+ struct llog_handle *llh;
+ int rc = 0, i, process_count;
+ int num_recs = 0;
+
+ ENTRY;
+
+ rc = llog_open_create(env, ctxt, &llh, NULL, NULL);
+ if (rc) {
+ CERROR("7_sub: create log failed\n");
+ RETURN(rc);
+ }
+
+ rc = llog_init_handle(env, llh,
+ LLOG_F_IS_PLAIN | LLOG_F_ZAP_WHEN_EMPTY,
+ &uuid);
+ if (rc) {
+ CERROR("7_sub: can't init llog handle: %d\n", rc);
+ GOTO(out_close, rc);
+ }
+ for (i = 0; i < LLOG_BITMAP_SIZE(llh->lgh_hdr); i++) {
+ rc = llog_write(env, llh, &llog_records.lrh, NULL, 0,
+ NULL, -1);
+ if (rc == -ENOSPC) {
+ break;
+ } else if (rc < 0) {
+ CERROR("7_sub: write recs failed at #%d: %d\n",
+ i + 1, rc);
+ GOTO(out_close, rc);
+ }
+ num_recs++;
+ }
+ if (rc != -ENOSPC) {
+ CWARN("7_sub: write record more than BITMAP size!\n");
+ GOTO(out_close, rc = -EINVAL);
+ }
+
+ rc = verify_handle("7_sub", llh, num_recs + 1);
+ if (rc) {
+ CERROR("7_sub: verify handle failed: %d\n", rc);
+ GOTO(out_close, rc);
+ }
+ if (num_recs < LLOG_BITMAP_SIZE(llh->lgh_hdr) - 1)
+ CWARN("7_sub: records are not aligned, written %d from %u\n",
+ num_recs, LLOG_BITMAP_SIZE(llh->lgh_hdr) - 1);
+
+ plain_counter = 0;
+ rc = llog_process(env, llh, test_7_print_cb, "test 7", NULL);
+ if (rc) {
+ CERROR("7_sub: llog process failed: %d\n", rc);
+ GOTO(out_close, rc);
+ }
+ process_count = plain_counter;
+ if (process_count != num_recs) {
+ CERROR("7_sub: processed %d records from %d total\n",
+ process_count, num_recs);
+ GOTO(out_close, rc = -EINVAL);
+ }
+
+ plain_counter = 0;
+ rc = llog_reverse_process(env, llh, test_7_cancel_cb, "test 7", NULL);
+ if (rc) {
+ CERROR("7_sub: reverse llog process failed: %d\n", rc);
+ GOTO(out_close, rc);
+ }
+ if (process_count != plain_counter) {
+ CERROR("7_sub: Reverse/direct processing found different"
+ "number of records: %d/%d\n",
+ plain_counter, process_count);
+ GOTO(out_close, rc = -EINVAL);
+ }
+ if (llog_exist(llh)) {
+ CERROR("7_sub: llog exists but should be zapped\n");
+ GOTO(out_close, rc = -EEXIST);
+ }
+
+ rc = verify_handle("7_sub", llh, 1);
+out_close:
+ if (rc)
+ llog_destroy(env, llh);
+ llog_close(env, llh);
+ RETURN(rc);
+}
+
+/* Test all llog records writing and processing */
+static int llog_test_7(const struct lu_env *env, struct obd_device *obd)
+{
+ struct llog_ctxt *ctxt;
+ int rc;
+
+ ENTRY;
+
+ ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT);
+
+ CWARN("7a: test llog_logid_rec\n");
+ llog_records.llr.lid_hdr.lrh_len = sizeof(llog_records.llr);
+ llog_records.llr.lid_tail.lrt_len = sizeof(llog_records.llr);
+ llog_records.llr.lid_hdr.lrh_type = LLOG_LOGID_MAGIC;
+
+ rc = llog_test_7_sub(env, ctxt);
+ if (rc) {
+ CERROR("7a: llog_logid_rec test failed\n");
+ GOTO(out, rc);
+ }
+
+ CWARN("7b: test llog_unlink64_rec\n");
+ llog_records.lur.lur_hdr.lrh_len = sizeof(llog_records.lur);
+ llog_records.lur.lur_tail.lrt_len = sizeof(llog_records.lur);
+ llog_records.lur.lur_hdr.lrh_type = MDS_UNLINK64_REC;
+
+ rc = llog_test_7_sub(env, ctxt);
+ if (rc) {
+ CERROR("7b: llog_unlink_rec test failed\n");
+ GOTO(out, rc);
+ }
+
+ CWARN("7c: test llog_setattr64_rec\n");
+ llog_records.lsr64.lsr_hdr.lrh_len = sizeof(llog_records.lsr64);
+ llog_records.lsr64.lsr_tail.lrt_len = sizeof(llog_records.lsr64);
+ llog_records.lsr64.lsr_hdr.lrh_type = MDS_SETATTR64_REC;
+
+ rc = llog_test_7_sub(env, ctxt);
+ if (rc) {
+ CERROR("7c: llog_setattr64_rec test failed\n");
+ GOTO(out, rc);
+ }
+
+ CWARN("7d: test llog_size_change_rec\n");
+ llog_records.lscr.lsc_hdr.lrh_len = sizeof(llog_records.lscr);
+ llog_records.lscr.lsc_tail.lrt_len = sizeof(llog_records.lscr);
+ llog_records.lscr.lsc_hdr.lrh_type = OST_SZ_REC;
+
+ rc = llog_test_7_sub(env, ctxt);
+ if (rc) {
+ CERROR("7d: llog_size_change_rec test failed\n");
+ GOTO(out, rc);
+ }
+
+ CWARN("7e: test llog_changelog_rec\n");
+ llog_records.lcr.cr_hdr.lrh_len = sizeof(llog_records.lcr);
+ llog_records.lcr.cr_tail.lrt_len = sizeof(llog_records.lcr);
+ llog_records.lcr.cr_hdr.lrh_type = CHANGELOG_REC;
+
+ rc = llog_test_7_sub(env, ctxt);
+ if (rc) {
+ CERROR("7e: llog_changelog_rec test failed\n");
+ GOTO(out, rc);
+ }
+
+ CWARN("7f: test llog_changelog_user_rec\n");
+ llog_records.lcur.cur_hdr.lrh_len = sizeof(llog_records.lcur);
+ llog_records.lcur.cur_tail.lrt_len = sizeof(llog_records.lcur);
+ llog_records.lcur.cur_hdr.lrh_type = CHANGELOG_USER_REC;
+
+ rc = llog_test_7_sub(env, ctxt);
+ if (rc) {
+ CERROR("7f: llog_changelog_user_rec test failed\n");
+ GOTO(out, rc);
+ }
+
+ CWARN("7g: test llog_gen_rec\n");
+ llog_records.lgr.lgr_hdr.lrh_len = sizeof(llog_records.lgr);
+ llog_records.lgr.lgr_tail.lrt_len = sizeof(llog_records.lgr);
+ llog_records.lgr.lgr_hdr.lrh_type = LLOG_GEN_REC;
+
+ rc = llog_test_7_sub(env, ctxt);
+ if (rc) {
+ CERROR("7g: llog_size_change_rec test failed\n");
+ GOTO(out, rc);
+ }
+out:
+ llog_ctxt_put(ctxt);
+ RETURN(rc);