Whamcloud - gitweb
LU-1347 build: remove the vim/emacs modelines
[fs/lustre-release.git] / lustre / ptlrpc / llog_server.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, Whamcloud, Inc.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/ptlrpc/llog_server.c
37  *
38  * remote api for llog - server side
39  *
40  * Author: Andreas Dilger <adilger@clusterfs.com>
41  */
42
43 #define DEBUG_SUBSYSTEM S_LOG
44
45 #ifndef EXPORT_SYMTAB
46 #define EXPORT_SYMTAB
47 #endif
48
49 #ifndef __KERNEL__
50 #include <liblustre.h>
51 #endif
52
53 #include <obd_class.h>
54 #include <lustre_log.h>
55 #include <lustre_net.h>
56 #include <libcfs/list.h>
57 #include <lustre_fsfilt.h>
58
59 #if defined(__KERNEL__) && defined(LUSTRE_LOG_SERVER)
60
61 int llog_origin_handle_create(struct ptlrpc_request *req)
62 {
63         struct obd_export    *exp = req->rq_export;
64         struct obd_device    *obd = exp->exp_obd;
65         struct obd_device    *disk_obd;
66         struct llog_handle   *loghandle;
67         struct llogd_body    *body;
68         struct lvfs_run_ctxt  saved;
69         struct llog_logid    *logid = NULL;
70         struct llog_ctxt     *ctxt;
71         char                 *name = NULL;
72         int                   rc, rc2;
73         ENTRY;
74
75         body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
76         if (body == NULL)
77                 RETURN(-EFAULT);
78
79         if (body->lgd_logid.lgl_oid > 0)
80                 logid = &body->lgd_logid;
81
82         if (req_capsule_field_present(&req->rq_pill, &RMF_NAME, RCL_CLIENT)) {
83                 name = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
84                 if (name == NULL)
85                         RETURN(-EFAULT);
86                 CDEBUG(D_INFO, "%s: opening log %s\n", obd->obd_name, name);
87         }
88
89         ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
90         if (ctxt == NULL) {
91                 CDEBUG(D_WARNING, "%s: no ctxt. group=%p idx=%d name=%s\n",
92                        obd->obd_name, &obd->obd_olg, body->lgd_ctxt_idx, name);
93                 RETURN(-ENODEV);
94         }
95         disk_obd = ctxt->loc_exp->exp_obd;
96         push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
97
98         rc = llog_create(ctxt, &loghandle, logid, name);
99         if (rc)
100                 GOTO(out_pop, rc);
101
102         rc = req_capsule_server_pack(&req->rq_pill);
103         if (rc)
104                 GOTO(out_close, rc = -ENOMEM);
105
106         body = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
107         body->lgd_logid = loghandle->lgh_id;
108
109         GOTO(out_close, rc);
110 out_close:
111         rc2 = llog_close(loghandle);
112         if (!rc)
113                 rc = rc2;
114 out_pop:
115         pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
116         llog_ctxt_put(ctxt);
117         return rc;
118 }
119
120 int llog_origin_handle_destroy(struct ptlrpc_request *req)
121 {
122         struct obd_export    *exp = req->rq_export;
123         struct obd_device    *obd = exp->exp_obd;
124         struct obd_device    *disk_obd;
125         struct llog_handle   *loghandle;
126         struct llogd_body    *body;
127         struct lvfs_run_ctxt  saved;
128         struct llog_logid    *logid = NULL;
129         struct llog_ctxt     *ctxt;
130         int                   rc;
131         ENTRY;
132
133         body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
134         if (body == NULL)
135                 RETURN(-EFAULT);
136
137         if (body->lgd_logid.lgl_oid > 0)
138                 logid = &body->lgd_logid;
139
140         ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
141         if (ctxt == NULL)
142                 RETURN(-ENODEV);
143
144         disk_obd = ctxt->loc_exp->exp_obd;
145         push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
146
147         rc = llog_create(ctxt, &loghandle, logid, NULL);
148         if (rc)
149                 GOTO(out_pop, rc);
150
151         rc = req_capsule_server_pack(&req->rq_pill);
152         if (rc)
153                 GOTO(out_close, rc = -ENOMEM);
154
155         body = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
156         body->lgd_logid = loghandle->lgh_id;
157         rc = llog_init_handle(loghandle, LLOG_F_IS_PLAIN, NULL);
158         if (rc)
159                 GOTO(out_close, rc);
160         rc = llog_destroy(loghandle);
161         if (rc)
162                 GOTO(out_close, rc);
163         llog_free_handle(loghandle);
164         GOTO(out_close, rc);
165 out_close:
166         if (rc)
167                 llog_close(loghandle);
168 out_pop:
169         pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
170         llog_ctxt_put(ctxt);
171         return rc;
172 }
173
174 int llog_origin_handle_next_block(struct ptlrpc_request *req)
175 {
176         struct obd_export   *exp = req->rq_export;
177         struct obd_device   *obd = exp->exp_obd;
178         struct obd_device   *disk_obd;
179         struct llog_handle  *loghandle;
180         struct llogd_body   *body;
181         struct llogd_body   *repbody;
182         struct lvfs_run_ctxt saved;
183         struct llog_ctxt    *ctxt;
184         __u32                flags;
185         __u8                *buf;
186         void                *ptr;
187         int                  rc, rc2;
188         ENTRY;
189
190         body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
191         if (body == NULL)
192                 RETURN(-EFAULT);
193
194         OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
195         if (!buf)
196                 RETURN(-ENOMEM);
197
198         ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
199         if (ctxt == NULL)
200                 GOTO(out_free, rc = -ENODEV);
201         disk_obd = ctxt->loc_exp->exp_obd;
202         push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
203
204         rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL);
205         if (rc)
206                 GOTO(out_pop, rc);
207
208         flags = body->lgd_llh_flags;
209         rc = llog_init_handle(loghandle, flags, NULL);
210         if (rc)
211                 GOTO(out_close, rc);
212
213         memset(buf, 0, LLOG_CHUNK_SIZE);
214         rc = llog_next_block(loghandle, &body->lgd_saved_index,
215                              body->lgd_index,
216                              &body->lgd_cur_offset, buf, LLOG_CHUNK_SIZE);
217         if (rc)
218                 GOTO(out_close, rc);
219
220         req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_SERVER,
221                              LLOG_CHUNK_SIZE);
222         rc = req_capsule_server_pack(&req->rq_pill);
223         if (rc)
224                 GOTO(out_close, rc = -ENOMEM);
225
226         repbody = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
227         *repbody = *body;
228
229         ptr = req_capsule_server_get(&req->rq_pill, &RMF_EADATA);
230         memcpy(ptr, buf, LLOG_CHUNK_SIZE);
231         GOTO(out_close, rc);
232 out_close:
233         rc2 = llog_close(loghandle);
234         if (!rc)
235                 rc = rc2;
236 out_pop:
237         pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
238         llog_ctxt_put(ctxt);
239 out_free:
240         OBD_FREE(buf, LLOG_CHUNK_SIZE);
241         return rc;
242 }
243
244 int llog_origin_handle_prev_block(struct ptlrpc_request *req)
245 {
246         struct obd_export    *exp = req->rq_export;
247         struct obd_device    *obd = exp->exp_obd;
248         struct llog_handle   *loghandle;
249         struct llogd_body    *body;
250         struct llogd_body    *repbody;
251         struct obd_device    *disk_obd;
252         struct lvfs_run_ctxt  saved;
253         struct llog_ctxt     *ctxt;
254         __u32                 flags;
255         __u8                 *buf;
256         void                 *ptr;
257         int                   rc, rc2;
258         ENTRY;
259
260         body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
261         if (body == NULL)
262                 RETURN(-EFAULT);
263
264         OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
265         if (!buf)
266                 RETURN(-ENOMEM);
267
268         ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
269         if (ctxt == NULL)
270                 GOTO(out_free, rc = -ENODEV);
271
272         disk_obd = ctxt->loc_exp->exp_obd;
273         push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
274
275         rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL);
276         if (rc)
277                 GOTO(out_pop, rc);
278
279         flags = body->lgd_llh_flags;
280         rc = llog_init_handle(loghandle, flags, NULL);
281         if (rc)
282                 GOTO(out_close, rc);
283
284         memset(buf, 0, LLOG_CHUNK_SIZE);
285         rc = llog_prev_block(loghandle, body->lgd_index,
286                              buf, LLOG_CHUNK_SIZE);
287         if (rc)
288                 GOTO(out_close, rc);
289
290         req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_SERVER,
291                              LLOG_CHUNK_SIZE);
292         rc = req_capsule_server_pack(&req->rq_pill);
293         if (rc)
294                 GOTO(out_close, rc = -ENOMEM);
295
296         repbody = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
297         *repbody = *body;
298
299         ptr = req_capsule_server_get(&req->rq_pill, &RMF_EADATA);
300         memcpy(ptr, buf, LLOG_CHUNK_SIZE);
301         GOTO(out_close, rc);
302 out_close:
303         rc2 = llog_close(loghandle);
304         if (!rc)
305                 rc = rc2;
306
307 out_pop:
308         pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
309         llog_ctxt_put(ctxt);
310 out_free:
311         OBD_FREE(buf, LLOG_CHUNK_SIZE);
312         return rc;
313 }
314
315 int llog_origin_handle_read_header(struct ptlrpc_request *req)
316 {
317         struct obd_export    *exp = req->rq_export;
318         struct obd_device    *obd = exp->exp_obd;
319         struct obd_device    *disk_obd;
320         struct llog_handle   *loghandle;
321         struct llogd_body    *body;
322         struct llog_log_hdr  *hdr;
323         struct lvfs_run_ctxt  saved;
324         struct llog_ctxt     *ctxt;
325         __u32                 flags;
326         int                   rc, rc2;
327         ENTRY;
328
329         body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
330         if (body == NULL)
331                 RETURN(-EFAULT);
332
333         ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
334         if (ctxt == NULL)
335                 RETURN(-ENODEV);
336
337         disk_obd = ctxt->loc_exp->exp_obd;
338         push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
339
340         rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL);
341         if (rc)
342                 GOTO(out_pop, rc);
343
344         /*
345          * llog_init_handle() reads the llog header
346          */
347         flags = body->lgd_llh_flags;
348         rc = llog_init_handle(loghandle, flags, NULL);
349         if (rc)
350                 GOTO(out_close, rc);
351
352         rc = req_capsule_server_pack(&req->rq_pill);
353         if (rc)
354                 GOTO(out_close, rc = -ENOMEM);
355
356         hdr = req_capsule_server_get(&req->rq_pill, &RMF_LLOG_LOG_HDR);
357         *hdr = *loghandle->lgh_hdr;
358         GOTO(out_close, rc);
359 out_close:
360         rc2 = llog_close(loghandle);
361         if (!rc)
362                 rc = rc2;
363 out_pop:
364         pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
365         llog_ctxt_put(ctxt);
366         return rc;
367 }
368
369 int llog_origin_handle_close(struct ptlrpc_request *req)
370 {
371         ENTRY;
372         /* Nothing to do */
373         RETURN(0);
374 }
375
376 int llog_origin_handle_cancel(struct ptlrpc_request *req)
377 {
378         struct obd_device *obd = req->rq_export->exp_obd;
379         int num_cookies, rc = 0, err, i, failed = 0;
380         struct obd_device *disk_obd;
381         struct llog_cookie *logcookies;
382         struct llog_ctxt *ctxt = NULL;
383         struct lvfs_run_ctxt saved;
384         struct llog_handle *cathandle;
385         struct inode *inode;
386         void *handle;
387         ENTRY;
388
389         logcookies = req_capsule_client_get(&req->rq_pill, &RMF_LOGCOOKIES);
390         num_cookies = req_capsule_get_size(&req->rq_pill, &RMF_LOGCOOKIES,
391                                            RCL_CLIENT) / sizeof(*logcookies);
392         if (logcookies == NULL || num_cookies == 0) {
393                 DEBUG_REQ(D_HA, req, "No llog cookies sent");
394                 RETURN(-EFAULT);
395         }
396
397         ctxt = llog_get_context(obd, logcookies->lgc_subsys);
398         if (ctxt == NULL)
399                 RETURN(-ENODEV);
400
401         disk_obd = ctxt->loc_exp->exp_obd;
402         push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
403         for (i = 0; i < num_cookies; i++, logcookies++) {
404                 cathandle = ctxt->loc_handle;
405                 LASSERT(cathandle != NULL);
406                 inode = cathandle->lgh_file->f_dentry->d_inode;
407
408                 handle = fsfilt_start_log(disk_obd, inode,
409                                           FSFILT_OP_CANCEL_UNLINK, NULL, 1);
410                 if (IS_ERR(handle)) {
411                         CERROR("fsfilt_start_log() failed: %ld\n",
412                                PTR_ERR(handle));
413                         GOTO(pop_ctxt, rc = PTR_ERR(handle));
414                 }
415
416                 rc = llog_cat_cancel_records(cathandle, 1, logcookies);
417
418                 /*
419                  * Do not raise -ENOENT errors for resent rpcs. This rec already
420                  * might be killed.
421                  */
422                 if (rc == -ENOENT &&
423                     (lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT)) {
424                         /*
425                          * Do not change this message, reply-single.sh test_59b
426                          * expects to find this in log.
427                          */
428                         CDEBUG(D_RPCTRACE, "RESENT cancel req %p - ignored\n",
429                                req);
430                         rc = 0;
431                 } else if (rc == 0) {
432                         CDEBUG(D_RPCTRACE, "Canceled %d llog-records\n",
433                                num_cookies);
434                 }
435
436                 err = fsfilt_commit(disk_obd, inode, handle, 0);
437                 if (err) {
438                         CERROR("Error committing transaction: %d\n", err);
439                         if (!rc)
440                                 rc = err;
441                         failed++;
442                         GOTO(pop_ctxt, rc);
443                 } else if (rc)
444                         failed++;
445         }
446         GOTO(pop_ctxt, rc);
447 pop_ctxt:
448         pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
449         if (rc)
450                 CERROR("Cancel %d of %d llog-records failed: %d\n",
451                        failed, num_cookies, rc);
452
453         llog_ctxt_put(ctxt);
454         return rc;
455 }
456 EXPORT_SYMBOL(llog_origin_handle_cancel);
457
458 static int llog_catinfo_config(struct obd_device *obd, char *buf, int buf_len,
459                                char *client)
460 {
461         struct mds_obd       *mds = &obd->u.mds;
462         struct llog_ctxt     *ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
463         struct lvfs_run_ctxt  saved;
464         struct llog_handle   *handle = NULL;
465         char                  name[4][64];
466         int                   rc, i, l, remains = buf_len;
467         char                 *out = buf;
468         ENTRY;
469
470         if (ctxt == NULL || mds == NULL)
471                 GOTO(release_ctxt, rc = -ENODEV);
472
473         push_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
474
475         sprintf(name[0], "%s", mds->mds_profile);
476         sprintf(name[1], "%s-clean", mds->mds_profile);
477         sprintf(name[2], "%s", client);
478         sprintf(name[3], "%s-clean", client);
479
480         for (i = 0; i < 4; i++) {
481                 int index, uncanceled = 0;
482                 rc = llog_create(ctxt, &handle, NULL, name[i]);
483                 if (rc)
484                         GOTO(out_pop, rc);
485                 rc = llog_init_handle(handle, 0, NULL);
486                 if (rc) {
487                         llog_close(handle);
488                         GOTO(out_pop, rc = -ENOENT);
489                 }
490
491                 for (index = 1; index < (LLOG_BITMAP_BYTES * 8); index ++) {
492                         if (ext2_test_bit(index, handle->lgh_hdr->llh_bitmap))
493                                 uncanceled++;
494                 }
495
496                 l = snprintf(out, remains, "[Log Name]: %s\nLog Size: %llu\n"
497                              "Last Index: %d\nUncanceled Records: %d\n\n",
498                              name[i],
499                              i_size_read(handle->lgh_file->f_dentry->d_inode),
500                              handle->lgh_last_idx, uncanceled);
501                 out += l;
502                 remains -= l;
503
504                 llog_close(handle);
505                 if (remains <= 0)
506                         break;
507         }
508         GOTO(out_pop, rc);
509 out_pop:
510         pop_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
511 release_ctxt:
512         llog_ctxt_put(ctxt);
513         return rc;
514 }
515
516 struct cb_data {
517         struct llog_ctxt *ctxt;
518         char *out;
519         int  remains;
520         int  init;
521 };
522
523 static int llog_catinfo_cb(struct llog_handle *cat,
524                            struct llog_rec_hdr *rec, void *data)
525 {
526         static char *out = NULL;
527         static int remains = 0;
528         struct llog_ctxt *ctxt = NULL;
529         struct llog_handle *handle = NULL;
530         struct llog_logid *logid;
531         struct llog_logid_rec *lir;
532         int l, rc, index, count = 0;
533         struct cb_data *cbd = (struct cb_data*)data;
534         ENTRY;
535
536         if (cbd->init) {
537                 out = cbd->out;
538                 remains = cbd->remains;
539                 cbd->init = 0;
540         }
541
542         if (!(cat->lgh_hdr->llh_flags & LLOG_F_IS_CAT))
543                 RETURN(-EINVAL);
544
545         if (!cbd->ctxt)
546                 RETURN(-ENODEV);
547
548         lir = (struct llog_logid_rec *)rec;
549         logid = &lir->lid_id;
550         rc = llog_create(ctxt, &handle, logid, NULL);
551         if (rc)
552                 RETURN(-EINVAL);
553         rc = llog_init_handle(handle, 0, NULL);
554         if (rc)
555                 GOTO(out_close, rc);
556
557         for (index = 1; index < (LLOG_BITMAP_BYTES * 8); index++) {
558                 if (ext2_test_bit(index, handle->lgh_hdr->llh_bitmap))
559                         count++;
560         }
561
562         l = snprintf(out, remains, "\t[Log ID]: #"LPX64"#"LPX64"#%08x\n"
563                      "\tLog Size: %llu\n\tLast Index: %d\n"
564                      "\tUncanceled Records: %d\n",
565                      logid->lgl_oid, logid->lgl_oseq, logid->lgl_ogen,
566                      i_size_read(handle->lgh_file->f_dentry->d_inode),
567                      handle->lgh_last_idx, count);
568         out += l;
569         remains -= l;
570         cbd->out = out;
571         cbd->remains = remains;
572         if (remains <= 0) {
573                 CWARN("Not enough memory\n");
574                 rc = -ENOMEM;
575         }
576         EXIT;
577 out_close:
578         llog_close(handle);
579         return rc;
580 }
581
582 static int llog_catinfo_deletions(struct obd_device *obd, char *buf,
583                                   int buf_len)
584 {
585         struct mds_obd *mds = &obd->u.mds;
586         struct llog_handle *handle;
587         struct lvfs_run_ctxt saved;
588         int size, i, count;
589         struct llog_catid *idarray;
590         char name[32] = CATLIST;
591         struct cb_data data;
592         struct llog_ctxt *ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
593         int rc;
594         ENTRY;
595
596         if (ctxt == NULL || mds == NULL)
597                 GOTO(release_ctxt, rc = -ENODEV);
598
599         count = mds->mds_lov_desc.ld_tgt_count;
600         size = sizeof(*idarray) * count;
601
602         OBD_ALLOC_LARGE(idarray, size);
603         if (!idarray)
604                 GOTO(release_ctxt, rc = -ENOMEM);
605
606         cfs_mutex_lock(&obd->obd_olg.olg_cat_processing);
607         rc = llog_get_cat_list(obd, name, 0, count, idarray);
608         if (rc)
609                 GOTO(out_free, rc);
610
611         push_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
612
613         data.ctxt = ctxt;
614         data.out = buf;
615         data.remains = buf_len;
616         for (i = 0; i < count; i++) {
617                 int l, index, uncanceled = 0;
618
619                 rc = llog_create(ctxt, &handle, &idarray[i].lci_logid, NULL);
620                 if (rc)
621                         GOTO(out_pop, rc);
622                 rc = llog_init_handle(handle, 0, NULL);
623                 if (rc) {
624                         llog_close(handle);
625                         GOTO(out_pop, rc = -ENOENT);
626                 }
627                 for (index = 1; index < (LLOG_BITMAP_BYTES * 8); index++) {
628                         if (ext2_test_bit(index, handle->lgh_hdr->llh_bitmap))
629                                 uncanceled++;
630                 }
631                 l = snprintf(data.out, data.remains,
632                              "\n[Catlog ID]: #"LPX64"#"LPX64"#%08x  "
633                              "[Log Count]: %d\n",
634                              idarray[i].lci_logid.lgl_oid,
635                              idarray[i].lci_logid.lgl_oseq,
636                              idarray[i].lci_logid.lgl_ogen, uncanceled);
637
638                 data.out += l;
639                 data.remains -= l;
640                 data.init = 1;
641
642                 llog_process(handle, llog_catinfo_cb, &data, NULL);
643                 llog_close(handle);
644
645                 if (data.remains <= 0)
646                         break;
647         }
648         EXIT;
649 out_pop:
650         pop_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
651 out_free:
652         cfs_mutex_unlock(&obd->obd_olg.olg_cat_processing);
653         OBD_FREE_LARGE(idarray, size);
654 release_ctxt:
655         llog_ctxt_put(ctxt);
656         return rc;
657 }
658
659 int llog_catinfo(struct ptlrpc_request *req)
660 {
661         struct obd_export *exp = req->rq_export;
662         struct obd_device *obd = exp->exp_obd;
663         char              *keyword;
664         char              *buf, *reply;
665         int                rc;
666         ENTRY;
667
668         OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
669         if (buf == NULL)
670                 RETURN(-ENOMEM);
671
672         memset(buf, 0, LLOG_CHUNK_SIZE);
673
674         keyword = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
675         LASSERT(keyword);
676
677         if (strcmp(keyword, "config") == 0) {
678                 char *client = req_capsule_client_get(&req->rq_pill,
679                                                       &RMF_STRING);
680
681                 LASSERT(client);
682                 rc = llog_catinfo_config(obd, buf, LLOG_CHUNK_SIZE, client);
683         } else if (strcmp(keyword, "deletions") == 0) {
684                 rc = llog_catinfo_deletions(obd, buf, LLOG_CHUNK_SIZE);
685         } else {
686                 rc = -EOPNOTSUPP;
687         }
688
689         req_capsule_set_size(&req->rq_pill, &RMF_STRING, RCL_SERVER,
690                              LLOG_CHUNK_SIZE);
691         rc = req_capsule_server_pack(&req->rq_pill);
692         if (rc)
693                 GOTO(out_free, rc = -ENOMEM);
694
695         reply = req_capsule_server_get(&req->rq_pill, &RMF_STRING);
696         if (strlen(buf) == 0)
697                 sprintf(buf, "%s", "No log informations\n");
698         memcpy(reply, buf, LLOG_CHUNK_SIZE);
699         EXIT;
700 out_free:
701         OBD_FREE(buf, LLOG_CHUNK_SIZE);
702         return rc;
703 }
704
705 #else /* !__KERNEL__ */
706 int llog_origin_handle_create(struct ptlrpc_request *req)
707 {
708         LBUG();
709         return 0;
710 }
711
712 int llog_origin_handle_destroy(struct ptlrpc_request *req)
713 {
714         LBUG();
715         return 0;
716 }
717
718 int llog_origin_handle_next_block(struct ptlrpc_request *req)
719 {
720         LBUG();
721         return 0;
722 }
723 int llog_origin_handle_prev_block(struct ptlrpc_request *req)
724 {
725         LBUG();
726         return 0;
727 }
728 int llog_origin_handle_read_header(struct ptlrpc_request *req)
729 {
730         LBUG();
731         return 0;
732 }
733 int llog_origin_handle_close(struct ptlrpc_request *req)
734 {
735         LBUG();
736         return 0;
737 }
738 int llog_origin_handle_cancel(struct ptlrpc_request *req)
739 {
740         LBUG();
741         return 0;
742 }
743 #endif