- struct obd_device *mdc_obd;
- struct llog_ctxt *ctxt;
- struct obd_uuid *mds_uuid;
- struct lustre_handle exph = {0, };
- struct obd_export *exp;
- struct obd_uuid uuid = {"LLOG_TEST6_UUID"};
- struct llog_handle *llh = NULL;
- struct llog_ctxt *nctxt;
- int rc;
-
- ctxt = llog_get_context(&obd->obd_llogs, LLOG_TEST_ORIG_CTXT);
- mds_uuid = &ctxt->loc_exp->exp_obd->obd_uuid;
-
- CWARN("6a: re-open log %s using client API\n", name);
- mdc_obd = class_find_client_obd(mds_uuid, LUSTRE_MDC_NAME, NULL);
- if (mdc_obd == NULL) {
- CERROR("6: no MDC devices connected to %s found.\n",
- mds_uuid->uuid);
- RETURN(-ENOENT);
- }
-
- rc = obd_connect(&exph, mdc_obd, &uuid, 0);
- if (rc) {
- CERROR("6: failed to connect to MDC: %s\n", mdc_obd->obd_name);
- RETURN(rc);
- }
- exp = class_conn2export(&exph);
-
- nctxt = llog_get_context(&mdc_obd->obd_llogs, LLOG_CONFIG_REPL_CTXT);
- rc = llog_open(nctxt, &llh, NULL, name, 0);
- if (rc) {
- CERROR("6: llog_open failed %d\n", rc);
- RETURN(rc);
- }
+ struct llog_handle *llh = NULL;
+ char name[10];
+ int rc, rc2;
+ struct llog_mini_rec lmr;
+ struct llog_ctxt *ctxt;
+
+ ENTRY;
+
+ ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT);
+ LASSERT(ctxt);
+
+ lmr.lmr_hdr.lrh_len = lmr.lmr_tail.lrt_len = LLOG_MIN_REC_SIZE;
+ lmr.lmr_hdr.lrh_type = 0xf00f00;
+
+ CWARN("5a: re-open catalog by id\n");
+ rc = llog_open(env, ctxt, &llh, &cat_logid, NULL, LLOG_OPEN_EXISTS);
+ if (rc) {
+ CERROR("5a: llog_create with logid failed: %d\n", rc);
+ GOTO(out_put, rc);
+ }
+
+ rc = llog_init_handle(env, llh, LLOG_F_IS_CAT, &uuid);
+ if (rc) {
+ CERROR("5a: can't init llog handle: %d\n", rc);
+ GOTO(out, rc);
+ }
+
+ CWARN("5b: print the catalog entries.. we expect 2\n");
+ cat_counter = 0;
+ rc = llog_process(env, llh, cat_print_cb, "test 5", NULL);
+ if (rc) {
+ CERROR("5b: process with cat_print_cb failed: %d\n", rc);
+ GOTO(out, rc);
+ }
+ if (cat_counter != 2) {
+ CERROR("5b: %d entries in catalog\n", cat_counter);
+ GOTO(out, rc = -EINVAL);
+ }
+
+ CWARN("5c: Cancel %d records, see one log zapped\n", LLOG_TEST_RECNUM);
+ cancel_count = 0;
+ rc = llog_cat_process(env, llh, llog_cancel_rec_cb, "foobar", 0, 0);
+ if (rc != -LLOG_EEMPTY) {
+ CERROR("5c: process with cat_cancel_cb failed: %d\n", rc);
+ GOTO(out, rc);
+ }
+
+ CWARN("5c: print the catalog entries.. we expect 1\n");
+ cat_counter = 0;
+ rc = llog_process(env, llh, cat_print_cb, "test 5", NULL);
+ if (rc) {
+ CERROR("5c: process with cat_print_cb failed: %d\n", rc);
+ GOTO(out, rc);
+ }
+ if (cat_counter != 1) {
+ CERROR("5c: %d entries in catalog\n", cat_counter);
+ GOTO(out, rc = -EINVAL);
+ }
+
+ CWARN("5d: add 1 record to the log with many canceled empty pages\n");
+ rc = llog_cat_add(env, llh, &lmr.lmr_hdr, NULL, NULL);
+ if (rc) {
+ CERROR("5d: add record to the log with many canceled empty "
+ "pages failed\n");
+ GOTO(out, rc);
+ }
+
+ CWARN("5e: print plain log entries.. expect 6\n");
+ plain_counter = 0;
+ rc = llog_cat_process(env, llh, plain_print_cb, "foobar", 0, 0);
+ if (rc) {
+ CERROR("5e: process with plain_print_cb failed: %d\n", rc);
+ GOTO(out, rc);
+ }
+ if (plain_counter != 6) {
+ CERROR("5e: found %d records\n", plain_counter);
+ GOTO(out, rc = -EINVAL);
+ }
+
+ CWARN("5f: print plain log entries reversely.. expect 6\n");
+ plain_counter = 0;
+ rc = llog_cat_reverse_process(env, llh, plain_print_cb, "foobar");
+ if (rc) {
+ CERROR("5f: reversely process with plain_print_cb failed:"
+ "%d\n", rc);
+ GOTO(out, rc);
+ }
+ if (plain_counter != 6) {
+ CERROR("5f: found %d records\n", plain_counter);
+ GOTO(out, rc = -EINVAL);
+ }
+
+out:
+ CWARN("5g: close re-opened catalog\n");
+ rc2 = llog_cat_close(env, llh);
+ if (rc2) {
+ CERROR("5g: close log %s failed: %d\n", name, rc2);
+ if (rc == 0)
+ rc = rc2;
+ }
+out_put:
+ llog_ctxt_put(ctxt);
+
+ RETURN(rc);
+}