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