Whamcloud - gitweb
b=11089
[fs/lustre-release.git] / lustre / obdclass / llog_test.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  Copyright (C) 2003 Cluster File Systems, Inc.
5  *   Author: Phil Schwan <phil@clusterfs.com>
6  *
7  *   This file is part of the Lustre file system, http://www.lustre.org
8  *   Lustre is a trademark of Cluster File Systems, Inc.
9  *
10  *   You may have signed or agreed to another license before downloading
11  *   this software.  If so, you are bound by the terms and conditions
12  *   of that agreement, and the following does not apply to you.  See the
13  *   LICENSE file included with this distribution for more information.
14  *
15  *   If you did not agree to a different license, then this copy of Lustre
16  *   is open source software; you can redistribute it and/or modify it
17  *   under the terms of version 2 of the GNU General Public License as
18  *   published by the Free Software Foundation.
19  *
20  *   In either case, Lustre is distributed in the hope that it will be
21  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
22  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  *   license text for more details.
24  *
25  * A kernel module which tests the llog API from the OBD setup function.
26  */
27
28 #ifndef EXPORT_SYMTAB
29 # define EXPORT_SYMTAB
30 #endif
31 #define DEBUG_SUBSYSTEM S_CLASS
32
33 #include <linux/module.h>
34 #include <linux/init.h>
35
36 #include <obd_class.h>
37 #include <lustre_log.h>
38
39 static int llog_test_rand;
40 static struct obd_uuid uuid = { .uuid = "test_uuid" };
41 static struct llog_logid cat_logid;
42
43 struct llog_mini_rec {
44         struct llog_rec_hdr     lmr_hdr;
45         struct llog_rec_tail    lmr_tail;
46 } __attribute__((packed));
47
48 static int verify_handle(char *test, struct llog_handle *llh, int num_recs)
49 {
50         int i;
51         int last_idx = 0;
52         int active_recs = 0;
53
54         for (i = 0; i < LLOG_BITMAP_BYTES * 8; i++) {
55                 if (ext2_test_bit(i, llh->lgh_hdr->llh_bitmap)) {
56                         last_idx = i;
57                         active_recs++;
58                 }
59         }
60
61         if (active_recs != num_recs) {
62                 CERROR("%s: expected %d active recs after write, found %d\n",
63                        test, num_recs, active_recs);
64                 RETURN(-ERANGE);
65         }
66
67         if (llh->lgh_hdr->llh_count != num_recs) {
68                 CERROR("%s: handle->count is %d, expected %d after write\n",
69                        test, llh->lgh_hdr->llh_count, num_recs);
70                 RETURN(-ERANGE);
71         }
72
73         if (llh->lgh_last_idx < last_idx) {
74                 CERROR("%s: handle->last_idx is %d, expected %d after write\n",
75                        test, llh->lgh_last_idx, last_idx);
76                 RETURN(-ERANGE);
77         }
78
79         RETURN(0);
80 }
81
82 /* Test named-log create/open, close */
83 static int llog_test_1(struct obd_device *obd, char *name)
84 {
85         struct llog_handle *llh;
86         struct llog_ctxt *ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT);
87         int rc;
88         int rc2;
89         ENTRY;
90
91         CWARN("1a: create a log with name: %s\n", name);
92         LASSERT(ctxt);
93
94         rc = llog_create(ctxt, &llh, NULL, name);
95         if (rc) {
96                 CERROR("1a: llog_create with name %s failed: %d\n", name, rc);
97                 llog_ctxt_put(ctxt);
98                 RETURN(rc);
99         }
100         llog_init_handle(llh, LLOG_F_IS_PLAIN, &uuid);
101
102         if ((rc = verify_handle("1", llh, 1)))
103                 GOTO(out, rc);
104
105  out:
106         CWARN("1b: close newly-created log\n");
107         rc2 = llog_close(llh);
108         llog_ctxt_put(ctxt);
109         if (rc2) {
110                 CERROR("1b: close log %s failed: %d\n", name, rc2);
111                 if (rc == 0)
112                         rc = rc2;
113         }
114         RETURN(rc);
115 }
116
117 /* Test named-log reopen; returns opened log on success */
118 static int llog_test_2(struct obd_device *obd, char *name,
119                        struct llog_handle **llh)
120 {
121         struct llog_handle *loghandle;
122         struct llog_logid logid;
123         int rc;
124         struct llog_ctxt *ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT);
125         ENTRY;
126
127         CWARN("2a: re-open a log with name: %s\n", name);
128         rc = llog_create(ctxt, llh, NULL, name);
129         if (rc) {
130                 CERROR("2a: re-open log with name %s failed: %d\n", name, rc);
131                 GOTO(out, rc);
132         }
133         llog_init_handle(*llh, LLOG_F_IS_PLAIN, &uuid);
134
135         if ((rc = verify_handle("2", *llh, 1)))
136                 GOTO(out, rc);
137
138         CWARN("2b: create a log without specified NAME & LOGID\n");
139         rc = llog_create(ctxt, &loghandle, NULL, NULL);
140         if (rc) {
141                 CERROR("2b: create log failed\n");
142                 GOTO(out, rc);
143         }
144         llog_init_handle(loghandle, LLOG_F_IS_PLAIN, &uuid);
145         logid = loghandle->lgh_id;
146         llog_close(loghandle);
147
148         CWARN("2b: re-open the log by LOGID\n");
149         rc = llog_create(ctxt, &loghandle, &logid, NULL);
150         if (rc) {
151                 CERROR("2b: re-open log by LOGID failed\n");
152                 GOTO(out, rc);
153         }
154         llog_init_handle(loghandle, LLOG_F_IS_PLAIN, &uuid);
155
156         CWARN("2b: destroy this log\n");
157         rc = llog_destroy(loghandle);
158         if (rc) {
159                 CERROR("2b: destroy log failed\n");
160                 GOTO(out, rc);
161         }
162         llog_free_handle(loghandle);
163 out:
164         llog_ctxt_put(ctxt);
165
166         RETURN(rc);
167 }
168
169 /* Test record writing, single and in bulk */
170 static int llog_test_3(struct obd_device *obd, struct llog_handle *llh)
171 {
172         struct llog_create_rec lcr;
173         int rc, i;
174         int num_recs = 1;       /* 1 for the header */
175         ENTRY;
176
177         lcr.lcr_hdr.lrh_len = lcr.lcr_tail.lrt_len = sizeof(lcr);
178         lcr.lcr_hdr.lrh_type = OST_SZ_REC;
179
180         CWARN("3a: write one create_rec\n");
181         rc = llog_write_rec(llh,  &lcr.lcr_hdr, NULL, 0, NULL, -1);
182         num_recs++;
183         if (rc) {
184                 CERROR("3a: write one log record failed: %d\n", rc);
185                 RETURN(rc);
186         }
187
188         if ((rc = verify_handle("3a", llh, num_recs)))
189                 RETURN(rc);
190
191         CWARN("3b: write 10 cfg log records with 8 bytes bufs\n");
192         for (i = 0; i < 10; i++) {
193                 struct llog_rec_hdr hdr;
194                 char buf[8];
195                 hdr.lrh_len = 8;
196                 hdr.lrh_type = OBD_CFG_REC;
197                 memset(buf, 0, sizeof buf);
198                 rc = llog_write_rec(llh, &hdr, NULL, 0, buf, -1);
199                 if (rc) {
200                         CERROR("3b: write 10 records failed at #%d: %d\n",
201                                i + 1, rc);
202                         RETURN(rc);
203                 }
204                 num_recs++;
205                 if ((rc = verify_handle("3c", llh, num_recs)))
206                         RETURN(rc);
207         }
208
209         if ((rc = verify_handle("3b", llh, num_recs)))
210                 RETURN(rc);
211
212         CWARN("3c: write 1000 more log records\n");
213         for (i = 0; i < 1000; i++) {
214                 rc = llog_write_rec(llh, &lcr.lcr_hdr, NULL, 0, NULL, -1);
215                 if (rc) {
216                         CERROR("3c: write 1000 records failed at #%d: %d\n",
217                                i + 1, rc);
218                         RETURN(rc);
219                 }
220                 num_recs++;
221                 if ((rc = verify_handle("3b", llh, num_recs)))
222                         RETURN(rc);
223         }
224
225         if ((rc = verify_handle("3c", llh, num_recs)))
226                 RETURN(rc);
227
228         RETURN(rc);
229 }
230
231 /* Test catalogue additions */
232 static int llog_test_4(struct obd_device *obd)
233 {
234         struct llog_handle *cath;
235         char name[10];
236         int rc, i, buflen;
237         struct llog_mini_rec lmr;
238         struct llog_cookie cookie;
239         struct llog_ctxt *ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT);
240         int num_recs = 0;
241         char *buf;
242         struct llog_rec_hdr rec;
243
244         ENTRY;
245
246         lmr.lmr_hdr.lrh_len = lmr.lmr_tail.lrt_len = LLOG_MIN_REC_SIZE;
247         lmr.lmr_hdr.lrh_type = 0xf00f00;
248
249         sprintf(name, "%x", llog_test_rand+1);
250         CWARN("4a: create a catalog log with name: %s\n", name);
251         rc = llog_create(ctxt, &cath, NULL, name);
252         if (rc) {
253                 CERROR("1a: llog_create with name %s failed: %d\n", name, rc);
254                 GOTO(out, rc);
255         }
256         llog_init_handle(cath, LLOG_F_IS_CAT, &uuid);
257         num_recs++;
258         cat_logid = cath->lgh_id;
259
260         CWARN("4b: write 1 record into the catalog\n");
261         rc = llog_cat_add_rec(cath, &lmr.lmr_hdr, &cookie, NULL);
262         if (rc != 1) {
263                 CERROR("4b: write 1 catalog record failed at: %d\n", rc);
264                 GOTO(out, rc);
265         }
266         num_recs++;
267         if ((rc = verify_handle("4b", cath, 2)))
268                 GOTO(ctxt_release, rc);
269
270         if ((rc = verify_handle("4b", cath->u.chd.chd_current_log, num_recs)))
271                 GOTO(ctxt_release, rc);
272
273         CWARN("4c: cancel 1 log record\n");
274         rc = llog_cat_cancel_records(cath, 1, &cookie);
275         if (rc) {
276                 CERROR("4c: cancel 1 catalog based record failed: %d\n", rc);
277                 GOTO(out, rc);
278         }
279         num_recs--;
280
281         if ((rc = verify_handle("4c", cath->u.chd.chd_current_log, num_recs)))
282                 GOTO(ctxt_release, rc);
283
284         CWARN("4d: write 40,000 more log records\n");
285         for (i = 0; i < 40000; i++) {
286                 rc = llog_cat_add_rec(cath, &lmr.lmr_hdr, NULL, NULL);
287                 if (rc) {
288                         CERROR("4d: write 40000 records failed at #%d: %d\n",
289                                i + 1, rc);
290                         GOTO(out, rc);
291                 }
292                 num_recs++;
293         }
294
295         CWARN("4e: add 5 large records, one record per block\n");
296         buflen = LLOG_CHUNK_SIZE - sizeof(struct llog_rec_hdr)
297                         - sizeof(struct llog_rec_tail);
298         OBD_ALLOC(buf, buflen);
299         if (buf == NULL)
300                 GOTO(out, rc = -ENOMEM);
301         for (i = 0; i < 5; i++) {
302                 rec.lrh_len = buflen;
303                 rec.lrh_type = OBD_CFG_REC;
304                 rc = llog_cat_add_rec(cath, &rec, NULL, buf);
305                 if (rc) {
306                         CERROR("4e: write 5 records failed at #%d: %d\n",
307                                i + 1, rc);
308                         OBD_FREE(buf, buflen);
309                         GOTO(out, rc);
310                 }
311                 num_recs++;
312         }
313         OBD_FREE(buf, buflen);
314
315  out:
316         CWARN("4f: put newly-created catalog\n");
317         rc = llog_cat_put(cath);
318 ctxt_release:
319         llog_ctxt_put(ctxt);
320         if (rc)
321                 CERROR("1b: close log %s failed: %d\n", name, rc);
322         RETURN(rc);
323 }
324
325 static int cat_print_cb(struct llog_handle *llh, struct llog_rec_hdr *rec,
326                         void *data)
327 {
328         struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
329
330         if (rec->lrh_type != LLOG_LOGID_MAGIC) {
331                 CERROR("invalid record in catalog\n");
332                 RETURN(-EINVAL);
333         }
334
335         CWARN("seeing record at index %d - "LPX64":%x in log "LPX64"\n",
336                rec->lrh_index, lir->lid_id.lgl_oid,
337                lir->lid_id.lgl_ogen, llh->lgh_id.lgl_oid);
338         RETURN(0);
339 }
340
341 static int plain_print_cb(struct llog_handle *llh, struct llog_rec_hdr *rec,
342                           void *data)
343 {
344         if (!(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN)) {
345                 CERROR("log is not plain\n");
346                 RETURN(-EINVAL);
347         }
348
349         CWARN("seeing record at index %d in log "LPX64"\n",
350                rec->lrh_index, llh->lgh_id.lgl_oid);
351         RETURN(0);
352 }
353
354 static int llog_cancel_rec_cb(struct llog_handle *llh, struct llog_rec_hdr *rec,
355                               void *data)
356 {
357         struct llog_cookie cookie;
358         static int i = 0;
359
360         if (!(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN)) {
361                 CERROR("log is not plain\n");
362                 RETURN(-EINVAL);
363         }
364
365         cookie.lgc_lgl = llh->lgh_id;
366         cookie.lgc_index = rec->lrh_index;
367
368         llog_cat_cancel_records(llh->u.phd.phd_cat_handle, 1, &cookie);
369         i++;
370         if (i == 40000)
371                 RETURN(-4711);
372         RETURN(0);
373 }
374
375 /* Test log and catalogue processing */
376 static int llog_test_5(struct obd_device *obd)
377 {
378         struct llog_handle *llh = NULL;
379         char name[10];
380         int rc;
381         struct llog_mini_rec lmr;
382         struct llog_ctxt *ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT);
383
384         ENTRY;
385
386         lmr.lmr_hdr.lrh_len = lmr.lmr_tail.lrt_len = LLOG_MIN_REC_SIZE;
387         lmr.lmr_hdr.lrh_type = 0xf00f00;
388
389         CWARN("5a: re-open catalog by id\n");
390         rc = llog_create(ctxt, &llh, &cat_logid, NULL);
391         if (rc) {
392                 CERROR("5a: llog_create with logid failed: %d\n", rc);
393                 GOTO(out, rc);
394         }
395         llog_init_handle(llh, LLOG_F_IS_CAT, &uuid);
396
397         CWARN("5b: print the catalog entries.. we expect 2\n");
398         rc = llog_process(llh, cat_print_cb, "test 5", NULL);
399         if (rc) {
400                 CERROR("5b: process with cat_print_cb failed: %d\n", rc);
401                 GOTO(out, rc);
402         }
403
404         CWARN("5c: Cancel 40000 records, see one log zapped\n");
405         rc = llog_cat_process(llh, llog_cancel_rec_cb, "foobar");
406         if (rc != -4711) {
407                 CERROR("5c: process with cat_cancel_cb failed: %d\n", rc);
408                 GOTO(out, rc);
409         }
410
411         CWARN("5d: add 1 record to the log with many canceled empty pages\n");
412         rc = llog_cat_add_rec(llh, &lmr.lmr_hdr, NULL, NULL);
413         if (rc) {
414                 CERROR("5d: add record to the log with many canceled empty\
415                        pages failed\n");
416                 GOTO(out, rc);
417         }
418
419         CWARN("5b: print the catalog entries.. we expect 1\n");
420         rc = llog_process(llh, cat_print_cb, "test 5", NULL);
421         if (rc) {
422                 CERROR("5b: process with cat_print_cb failed: %d\n", rc);
423                 GOTO(out, rc);
424         }
425
426         CWARN("5e: print plain log entries.. expect 6\n");
427         rc = llog_cat_process(llh, plain_print_cb, "foobar");
428         if (rc) {
429                 CERROR("5e: process with plain_print_cb failed: %d\n", rc);
430                 GOTO(out, rc);
431         }
432
433         CWARN("5f: print plain log entries reversely.. expect 6\n");
434         rc = llog_cat_reverse_process(llh, plain_print_cb, "foobar");
435         if (rc) {
436                 CERROR("5f: reversely process with plain_print_cb failed: %d\n", rc);
437                 GOTO(out, rc);
438         }
439
440  out:
441         CWARN("5: close re-opened catalog\n");
442         if (llh)
443                 rc = llog_cat_put(llh);
444         if (rc)
445                 CERROR("1b: close log %s failed: %d\n", name, rc);
446         llog_ctxt_put(ctxt);
447
448         RETURN(rc);
449 }
450
451 /* Test client api; open log by name and process */
452 static int llog_test_6(struct obd_device *obd, char *name)
453 {
454         struct obd_device *mdc_obd;
455         struct llog_ctxt *ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT);
456         struct obd_uuid *mds_uuid = &ctxt->loc_exp->exp_obd->obd_uuid;
457         struct lustre_handle exph = {0, };
458         struct obd_export *exp;
459         struct obd_uuid uuid = {"LLOG_TEST6_UUID"};
460         struct llog_handle *llh = NULL;
461         struct llog_ctxt *nctxt;
462         int rc;
463
464         CWARN("6a: re-open log %s using client API\n", name);
465         mdc_obd = class_find_client_obd(mds_uuid, LUSTRE_MDC_NAME, NULL);
466         if (mdc_obd == NULL) {
467                 CERROR("6: no MDC devices connected to %s found.\n",
468                        mds_uuid->uuid);
469                 GOTO(ctxt_release, rc = -ENOENT);
470         }
471
472         rc = obd_connect(NULL, &exph, mdc_obd, &uuid,
473                          NULL /* obd_connect_data */, NULL);
474         if (rc) {
475                 CERROR("6: failed to connect to MDC: %s\n", mdc_obd->obd_name);
476                 GOTO(ctxt_release, rc);
477         }
478         exp = class_conn2export(&exph);
479
480         nctxt = llog_get_context(mdc_obd, LLOG_CONFIG_REPL_CTXT);
481         rc = llog_create(nctxt, &llh, NULL, name);
482         if (rc) {
483                 CERROR("6: llog_create failed %d\n", rc);
484                 llog_ctxt_put(nctxt);
485                 GOTO(ctxt_release, rc);
486         }
487
488         rc = llog_init_handle(llh, LLOG_F_IS_PLAIN, NULL);
489         if (rc) {
490                 CERROR("6: llog_init_handle failed %d\n", rc);
491                 GOTO(parse_out, rc);
492         }
493
494         rc = llog_process(llh, plain_print_cb, NULL, NULL);
495         if (rc)
496                 CERROR("6: llog_process failed %d\n", rc);
497
498         rc = llog_reverse_process(llh, plain_print_cb, NULL, NULL);
499         if (rc)
500                 CERROR("6: llog_reverse_process failed %d\n", rc);
501
502 parse_out:
503         rc = llog_close(llh);
504         llog_ctxt_put(nctxt);
505         if (rc) {
506                 CERROR("6: llog_close failed: rc = %d\n", rc);
507         }
508         rc = obd_disconnect(exp);
509 ctxt_release:
510         llog_ctxt_put(ctxt);
511         RETURN(rc);
512 }
513
514 static int llog_test_7(struct obd_device *obd)
515 {
516         struct llog_ctxt *ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT);
517         struct llog_handle *llh;
518         struct llog_create_rec lcr;
519         char name[10];
520         int rc;
521         ENTRY;
522
523         sprintf(name, "%x", llog_test_rand+2);
524         CWARN("7: create a log with name: %s\n", name);
525         LASSERT(ctxt);
526
527         rc = llog_create(ctxt, &llh, NULL, name);
528         if (rc) {
529                 CERROR("7: llog_create with name %s failed: %d\n", name, rc);
530                 GOTO(ctxt_release, rc);
531         }
532         llog_init_handle(llh, LLOG_F_IS_PLAIN, &uuid);
533
534         lcr.lcr_hdr.lrh_len = lcr.lcr_tail.lrt_len = sizeof(lcr);
535         lcr.lcr_hdr.lrh_type = OST_SZ_REC;
536         rc = llog_write_rec(llh,  &lcr.lcr_hdr, NULL, 0, NULL, -1);
537         if (rc) {
538                 CERROR("7: write one log record failed: %d\n", rc);
539                 GOTO(ctxt_release, rc);
540         }
541
542         rc = llog_destroy(llh);
543         if (rc)
544                 CERROR("7: llog_destroy failed: %d\n", rc);
545         else
546                 llog_free_handle(llh);
547 ctxt_release:
548         llog_ctxt_put(ctxt);
549         RETURN(rc);
550 }
551
552 /* -------------------------------------------------------------------------
553  * Tests above, boring obd functions below
554  * ------------------------------------------------------------------------- */
555 static int llog_run_tests(struct obd_device *obd)
556 {
557         struct llog_handle *llh;
558         struct lvfs_run_ctxt saved;
559         struct llog_ctxt *ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT);
560         int rc, err, cleanup_phase = 0;
561         char name[10];
562         ENTRY;
563
564         sprintf(name, "%x", llog_test_rand);
565         push_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
566
567         rc = llog_test_1(obd, name);
568         if (rc)
569                 GOTO(cleanup, rc);
570
571         rc = llog_test_2(obd, name, &llh);
572         if (rc)
573                 GOTO(cleanup, rc);
574         cleanup_phase = 1; /* close llh */
575
576         rc = llog_test_3(obd, llh);
577         if (rc)
578                 GOTO(cleanup, rc);
579
580         rc = llog_test_4(obd);
581         if (rc)
582                 GOTO(cleanup, rc);
583
584         rc = llog_test_5(obd);
585         if (rc)
586                 GOTO(cleanup, rc);
587
588         rc = llog_test_6(obd, name);
589         if (rc)
590                 GOTO(cleanup, rc);
591
592         rc = llog_test_7(obd);
593         if (rc)
594                 GOTO(cleanup, rc);
595
596  cleanup:
597         switch (cleanup_phase) {
598         case 1:
599                 err = llog_close(llh);
600                 if (err)
601                         CERROR("cleanup: llog_close failed: %d\n", err);
602                 if (!rc)
603                         rc = err;
604         case 0:
605                 pop_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
606         }
607         llog_ctxt_put(ctxt);
608         return rc;
609 }
610
611
612 static int llog_test_llog_init(struct obd_device *obd, int group,
613                                struct obd_device *tgt, int count, 
614                                struct llog_catid *logid, struct obd_uuid *uuid)
615 {
616         int rc;
617         ENTRY;
618
619         rc = llog_setup(obd, &obd->obd_olg, LLOG_TEST_ORIG_CTXT, tgt, 0, NULL, 
620                         &llog_lvfs_ops);
621         RETURN(rc);
622 }
623
624 static int llog_test_llog_finish(struct obd_device *obd, int count)
625 {
626         int rc;
627         ENTRY;
628
629         rc = llog_cleanup(llog_get_context(obd, LLOG_TEST_ORIG_CTXT));
630         RETURN(rc);
631 }
632 #ifdef LPROCFS
633 static struct lprocfs_vars lprocfs_llog_test_obd_vars[] = { {0} };
634 static struct lprocfs_vars lprocfs_llog_test_module_vars[] = { {0} };
635 static void lprocfs_llog_test_init_vars(struct lprocfs_static_vars *lvars)
636 {
637     lvars->module_vars  = lprocfs_llog_test_module_vars;
638     lvars->obd_vars     = lprocfs_llog_test_obd_vars;
639 }
640 #endif
641
642 static int llog_test_cleanup(struct obd_device *obd)
643 {
644         int rc = obd_llog_finish(obd, 0);
645         if (rc)
646                 CERROR("failed to llog_test_llog_finish: %d\n", rc);
647
648         lprocfs_obd_cleanup(obd);
649
650         return rc;
651 }
652
653 static int llog_test_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
654 {
655         struct lprocfs_static_vars lvars;
656         struct obd_device *tgt;
657         int rc;
658         ENTRY;
659
660         if (lcfg->lcfg_bufcount < 2) {
661                 CERROR("requires a TARGET OBD name\n");
662                 RETURN(-EINVAL);
663         }
664
665         if (lcfg->lcfg_buflens[1] < 1) {
666                 CERROR("requires a TARGET OBD name\n");
667                 RETURN(-EINVAL);
668         }
669
670         tgt = class_name2obd(lustre_cfg_string(lcfg, 1));
671         if (!tgt || !tgt->obd_attached || !tgt->obd_set_up) {
672                 CERROR("target device not attached or not set up (%s)\n",
673                        lustre_cfg_string(lcfg, 1));
674                 RETURN(-EINVAL);
675         }
676
677         rc = obd_llog_init(obd, OBD_LLOG_GROUP, tgt, 0, NULL, NULL);
678         if (rc)
679                 RETURN(rc);
680
681         llog_test_rand = ll_rand();
682
683         rc = llog_run_tests(obd);
684         if (rc)
685                 llog_test_cleanup(obd);
686
687         lprocfs_llog_test_init_vars(&lvars);
688         lprocfs_obd_setup(obd, lvars.obd_vars);
689
690         RETURN(rc);
691 }
692
693 static struct obd_ops llog_obd_ops = {
694         .o_owner       = THIS_MODULE,
695         .o_setup       = llog_test_setup,
696         .o_cleanup     = llog_test_cleanup,
697         .o_llog_init   = llog_test_llog_init,
698         .o_llog_finish = llog_test_llog_finish,
699 };
700
701 static int __init llog_test_init(void)
702 {
703         struct lprocfs_static_vars lvars;
704
705         lprocfs_llog_test_init_vars(&lvars);
706         return class_register_type(&llog_obd_ops, NULL,
707                                    lvars.module_vars,"llog_test", NULL);
708 }
709
710 static void __exit llog_test_exit(void)
711 {
712         class_unregister_type("llog_test");
713 }
714
715 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
716 MODULE_DESCRIPTION("llog test module");
717 MODULE_LICENSE("GPL");
718
719 module_init(llog_test_init);
720 module_exit(llog_test_exit);