Whamcloud - gitweb
b=21563 Metadata performance has degraded for some operations between 1.6.5 and 1.8.1
[fs/lustre-release.git] / lustre / ptlrpc / llog_server.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
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 size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };
73         int rc, rc2;
74         ENTRY;
75
76         body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
77                                  lustre_swab_llogd_body);
78         if (body == NULL) {
79                 CERROR("Can't unpack llogd_body\n");
80                 RETURN(-EFAULT);
81         }
82
83         if (body->lgd_logid.lgl_oid > 0)
84                 logid = &body->lgd_logid;
85
86         if (lustre_msg_bufcount(req->rq_reqmsg) > 2) {
87                 name = lustre_msg_string(req->rq_reqmsg, REQ_REC_OFF + 1, 0);
88                 if (name == NULL) {
89                         CERROR("Can't unpack name\n");
90                         RETURN(-EFAULT);
91                 }
92                 CDEBUG(D_INFO, "Opening log %s\n", name);
93         }
94
95         ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
96         if (ctxt == NULL)
97                 RETURN(-ENODEV);
98
99         disk_obd = ctxt->loc_exp->exp_obd;
100         push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
101
102         rc = llog_create(ctxt, &loghandle, logid, name);
103         if (rc)
104                 GOTO(out_pop, rc);
105
106         rc = lustre_pack_reply(req, 2, size, NULL);
107         if (rc)
108                 GOTO(out_close, rc = -ENOMEM);
109
110         body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*body));
111         body->lgd_logid = loghandle->lgh_id;
112         EXIT;
113 out_close:
114         rc2 = llog_close(loghandle);
115         if (!rc)
116                 rc = rc2;
117 out_pop:
118         pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
119         llog_ctxt_put(ctxt);
120         return rc;
121 }
122
123 int llog_origin_handle_destroy(struct ptlrpc_request *req)
124 {
125         struct obd_export *exp = req->rq_export;
126         struct obd_device *obd = exp->exp_obd;
127         struct obd_device *disk_obd;
128         struct llog_handle  *loghandle;
129         struct llogd_body *body;
130         struct lvfs_run_ctxt saved;
131         struct llog_logid *logid = NULL;
132         struct llog_ctxt *ctxt;
133         int size[] = { sizeof(struct ptlrpc_body), sizeof(*body) };
134         int rc;
135         __u32 flags;
136         ENTRY;
137
138         body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
139                                  lustre_swab_llogd_body);
140         if (body == NULL) {
141                 CERROR ("Can't unpack llogd_body\n");
142                 RETURN(-EFAULT);
143         }
144
145         if (body->lgd_logid.lgl_oid > 0)
146                 logid = &body->lgd_logid;
147
148         ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
149         if (ctxt == NULL)
150                 RETURN(-ENODEV);
151
152         disk_obd = ctxt->loc_exp->exp_obd;
153         push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
154
155         rc = llog_create(ctxt, &loghandle, logid, NULL);
156         if (rc) {
157                 /* This might already be killed. Let's check if this is
158                  * resent case. */
159                 if (rc == -ENOENT &&
160                     (lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT))
161                         rc = 0;
162                 GOTO(out_pop, rc);
163         }
164
165         rc = lustre_pack_reply(req, 2, size, NULL);
166         if (rc)
167                 GOTO(out_close, rc = -ENOMEM);
168
169         body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof (*body));
170         body->lgd_logid = loghandle->lgh_id;
171         flags = body->lgd_llh_flags;
172         rc = llog_init_handle(loghandle, LLOG_F_IS_PLAIN, NULL);
173         if (rc)
174                 GOTO(out_close, rc);
175         rc = llog_destroy(loghandle);
176         if (rc)
177                 /* Do not check for resent as this is already done above after
178                  * llog_create(). */
179                 GOTO(out_close, rc);
180         llog_free_handle(loghandle);
181         EXIT;
182 out_close:
183         if (rc)
184                 llog_close(loghandle);
185 out_pop:
186         pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
187         llog_ctxt_put(ctxt);
188         return rc;
189 }
190
191 int llog_origin_handle_next_block(struct ptlrpc_request *req)
192 {
193         struct obd_export *exp = req->rq_export;
194         struct obd_device *obd = exp->exp_obd;
195         struct obd_device *disk_obd;
196         struct llog_handle  *loghandle;
197         struct llogd_body *body;
198         struct lvfs_run_ctxt saved;
199         struct llog_ctxt *ctxt;
200         __u32 flags;
201         __u8 *buf;
202         void * ptr;
203         int size[3] = { sizeof(struct ptlrpc_body),
204                         sizeof(*body),
205                         LLOG_CHUNK_SIZE };
206         int rc, rc2;
207         ENTRY;
208
209         body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
210                                   lustre_swab_llogd_body);
211         if (body == NULL) {
212                 CERROR ("Can't unpack llogd_body\n");
213                 RETURN(-EFAULT);
214         }
215
216         OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
217         if (!buf)
218                 RETURN(-ENOMEM);
219
220         ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
221         if (ctxt == NULL)
222                 GOTO(out_free, rc = -ENODEV);
223
224         disk_obd = ctxt->loc_exp->exp_obd;
225         push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
226
227         rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL);
228         if (rc)
229                 GOTO(out_pop, rc);
230
231         flags = body->lgd_llh_flags;
232         rc = llog_init_handle(loghandle, flags, NULL);
233         if (rc)
234                 GOTO(out_close, rc);
235
236         memset(buf, 0, LLOG_CHUNK_SIZE);
237         rc = llog_next_block(loghandle, &body->lgd_saved_index,
238                              body->lgd_index,
239                              &body->lgd_cur_offset, buf, LLOG_CHUNK_SIZE);
240         if (rc)
241                 GOTO(out_close, rc);
242
243         rc = lustre_pack_reply(req, 3, size, NULL);
244         if (rc)
245                 GOTO(out_close, rc = -ENOMEM);
246
247         ptr = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof (body));
248         memcpy(ptr, body, sizeof(*body));
249
250         ptr = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF+1, LLOG_CHUNK_SIZE);
251         memcpy(ptr, buf, LLOG_CHUNK_SIZE);
252         EXIT;
253 out_close:
254         rc2 = llog_close(loghandle);
255         if (!rc)
256                 rc = rc2;
257 out_pop:
258         pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
259         llog_ctxt_put(ctxt);
260 out_free:
261         OBD_FREE(buf, LLOG_CHUNK_SIZE);
262         return rc;
263 }
264
265 int llog_origin_handle_prev_block(struct ptlrpc_request *req)
266 {
267         struct obd_export *exp = req->rq_export;
268         struct obd_device *obd = exp->exp_obd;
269         struct llog_handle  *loghandle;
270         struct llogd_body *body;
271         struct obd_device *disk_obd;
272         struct lvfs_run_ctxt saved;
273         struct llog_ctxt *ctxt;
274         __u32 flags;
275         __u8 *buf;
276         void * ptr;
277         int size[] = { sizeof(struct ptlrpc_body),
278                        sizeof(*body),
279                        LLOG_CHUNK_SIZE };
280         int rc, rc2;
281         ENTRY;
282
283         body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
284                                   lustre_swab_llogd_body);
285         if (body == NULL) {
286                 CERROR ("Can't unpack llogd_body\n");
287                 RETURN(-EFAULT);
288         }
289
290         OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
291         if (!buf)
292                 RETURN(-ENOMEM);
293
294         ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
295         if (ctxt == NULL)
296                 GOTO(out_free, rc = -ENODEV);
297
298         disk_obd = ctxt->loc_exp->exp_obd;
299         push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
300
301         rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL);
302         if (rc)
303                 GOTO(out_pop, rc);
304
305         flags = body->lgd_llh_flags;
306         rc = llog_init_handle(loghandle, flags, NULL);
307         if (rc)
308                 GOTO(out_close, rc);
309
310         memset(buf, 0, LLOG_CHUNK_SIZE);
311         rc = llog_prev_block(loghandle, body->lgd_index,
312                              buf, LLOG_CHUNK_SIZE);
313         if (rc)
314                 GOTO(out_close, rc);
315
316         rc = lustre_pack_reply(req, 3, size, NULL);
317         if (rc)
318                 GOTO(out_close, rc = -ENOMEM);
319
320         ptr = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(body));
321         memcpy(ptr, body, sizeof(*body));
322
323         ptr = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF+1, LLOG_CHUNK_SIZE);
324         memcpy(ptr, buf, LLOG_CHUNK_SIZE);
325         EXIT;
326 out_close:
327         rc2 = llog_close(loghandle);
328         if (!rc)
329                 rc = rc2;
330 out_pop:
331         pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
332         llog_ctxt_put(ctxt);
333 out_free:
334         OBD_FREE(buf, LLOG_CHUNK_SIZE);
335         return rc;
336 }
337
338 int llog_origin_handle_read_header(struct ptlrpc_request *req)
339 {
340         struct obd_export *exp = req->rq_export;
341         struct obd_device *obd = exp->exp_obd;
342         struct obd_device *disk_obd;
343         struct llog_handle  *loghandle;
344         struct llogd_body *body;
345         struct llog_log_hdr *hdr;
346         struct lvfs_run_ctxt saved;
347         struct llog_ctxt *ctxt;
348         __u32 flags;
349         int size[2] = { sizeof(struct ptlrpc_body), sizeof(*hdr) };
350         int rc, rc2;
351         ENTRY;
352
353         body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),
354                                   lustre_swab_llogd_body);
355         if (body == NULL) {
356                 CERROR ("Can't unpack llogd_body\n");
357                 RETURN(-EFAULT);
358         }
359
360         ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
361         if (ctxt == NULL)
362                 RETURN(-ENODEV);
363
364         disk_obd = ctxt->loc_exp->exp_obd;
365         push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
366         rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL);
367         if (rc)
368                 GOTO(out_pop, rc);
369
370         /* llog_init_handle() reads the header */
371         flags = body->lgd_llh_flags;
372         rc = llog_init_handle(loghandle, flags, NULL);
373         if (rc)
374                 GOTO(out_close, rc);
375
376         rc = lustre_pack_reply(req, 2, size, NULL);
377         if (rc)
378                 GOTO(out_close, rc = -ENOMEM);
379
380         hdr = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*hdr));
381         memcpy(hdr, loghandle->lgh_hdr, sizeof(*hdr));
382         EXIT;
383 out_close:
384         rc2 = llog_close(loghandle);
385         if (!rc)
386                 rc = rc2;
387 out_pop:
388         pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
389         llog_ctxt_put(ctxt);
390         return rc;
391 }
392
393 int llog_origin_handle_close(struct ptlrpc_request *req)
394 {
395         ENTRY;
396         RETURN(0);
397 }
398
399 int llog_origin_handle_cancel(struct ptlrpc_request *req)
400 {
401         struct obd_device *obd = req->rq_export->exp_obd;
402         int num_cookies, rc = 0, err, i, failed = 0;
403         struct obd_device *disk_obd;
404         struct llog_cookie *logcookies;
405         struct llog_ctxt *ctxt = NULL;
406         struct lvfs_run_ctxt saved;
407         struct llog_handle *cathandle;
408         struct inode *inode;
409         void *handle;
410         ENTRY;
411
412         logcookies = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF,
413                                     sizeof(*logcookies));
414         num_cookies = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF) /
415                       sizeof(*logcookies);
416         if (logcookies == NULL || num_cookies == 0) {
417                 DEBUG_REQ(D_HA, req, "No llog cookies sent");
418                 RETURN(-EFAULT);
419         }
420
421         ctxt = llog_get_context(obd, logcookies->lgc_subsys);
422         if (ctxt == NULL)
423                 RETURN(-ENODEV);
424
425         disk_obd = ctxt->loc_exp->exp_obd;
426         push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
427         for (i = 0; i < num_cookies; i++, logcookies++) {
428                 cathandle = ctxt->loc_handle;
429                 LASSERT(cathandle != NULL);
430                 inode = cathandle->lgh_file->f_dentry->d_inode;
431
432                 handle = fsfilt_start_log(disk_obd, inode,
433                                           FSFILT_OP_CANCEL_UNLINK, NULL, 1);
434                 if (IS_ERR(handle)) {
435                         CERROR("fsfilt_start_log() failed: %ld\n", 
436                                PTR_ERR(handle));
437                         GOTO(pop_ctxt, rc = PTR_ERR(handle));
438                 }
439
440                 rc = llog_cat_cancel_records(cathandle, 1, logcookies);
441
442                 err = fsfilt_commit(disk_obd, inode, handle, 0);
443
444                 /* Do not raise -ENOENT errors for resent rpcs. This rec already
445                  * might be killed. */
446                 if (rc == -ENOENT && 
447                     (lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT)) {
448                         CDEBUG(D_INFO, "RESENT cancel req %p - ignored\n", req);
449                         rc = 0;
450                 }
451
452                 if (err) {
453                         CERROR("Error committing transaction: %d\n", err);
454                         if (!rc)
455                                 rc = err;
456                         failed++;
457                         GOTO(pop_ctxt, rc);
458                 } else if (rc)
459                         failed++;
460         }
461         EXIT;
462 pop_ctxt:
463         pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
464         if (rc)
465                 CERROR("Cancel %d of %d llog-records failed: %d\n", 
466                        failed, num_cookies, rc);
467         else
468                 CDEBUG(D_RPCTRACE, "Canceled %d llog-records\n", 
469                        num_cookies);
470
471         llog_ctxt_put(ctxt);
472         return rc;
473 }
474 EXPORT_SYMBOL(llog_origin_handle_cancel);
475
476 static int llog_catinfo_config(struct obd_device *obd, char *buf, int buf_len,
477                                char *client)
478 {
479         struct mds_obd *mds = &obd->u.mds;
480         struct llog_ctxt *ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
481         struct lvfs_run_ctxt saved;
482         struct llog_handle *handle = NULL;
483         char name[4][64];
484         int rc, i, l, remains = buf_len;
485         char *out = buf;
486         ENTRY;
487
488         if (ctxt == NULL || mds == NULL)
489                 GOTO(release_ctxt, rc = -ENODEV);
490
491         push_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
492
493         sprintf(name[0], "%s", mds->mds_profile);
494         sprintf(name[1], "%s-clean", mds->mds_profile);
495         sprintf(name[2], "%s", client);
496         sprintf(name[3], "%s-clean", client);
497
498         for (i = 0; i < 4; i++) {
499                 int index, uncanceled = 0;
500                 rc = llog_create(ctxt, &handle, NULL, name[i]);
501                 if (rc)
502                         GOTO(out_pop, rc);
503                 rc = llog_init_handle(handle, 0, NULL);
504                 if (rc) {
505                         llog_close(handle);
506                         GOTO(out_pop, rc = -ENOENT);
507                 }
508
509                 for (index = 1; index < (LLOG_BITMAP_BYTES * 8); index ++) {
510                         if (ext2_test_bit(index, handle->lgh_hdr->llh_bitmap))
511                                 uncanceled++;
512                 }
513
514                 l = snprintf(out, remains, "[Log Name]: %s\nLog Size: %llu\n"
515                              "Last Index: %d\nUncanceled Records: %d\n\n",
516                              name[i],
517                              i_size_read(handle->lgh_file->f_dentry->d_inode),
518                              handle->lgh_last_idx, uncanceled);
519                 out += l;
520                 remains -= l;
521
522                 llog_close(handle);
523                 if (remains <= 0)
524                         break;
525         }
526         GOTO(out_pop, rc);
527 out_pop:
528         pop_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
529 release_ctxt:
530         llog_ctxt_put(ctxt);
531         return rc;
532 }
533
534 struct cb_data {
535         struct llog_ctxt *ctxt;
536         char *out;
537         int  remains;
538         int  init;
539 };
540
541 static int llog_catinfo_cb(struct llog_handle *cat,
542                            struct llog_rec_hdr *rec, void *data)
543 {
544         static char *out = NULL;
545         static int remains = 0;
546         struct llog_ctxt *ctxt = NULL;
547         struct llog_handle *handle;
548         struct llog_logid *logid;
549         struct llog_logid_rec *lir;
550         int l, rc, index, count = 0;
551         struct cb_data *cbd = (struct cb_data*)data;
552         ENTRY;
553
554         if (cbd->init) {
555                 out = cbd->out;
556                 remains = cbd->remains;
557                 cbd->init = 0;
558         }
559
560         if (!(cat->lgh_hdr->llh_flags & LLOG_F_IS_CAT)) 
561                 RETURN(-EINVAL);
562
563         if (!cbd->ctxt)
564                 RETURN(-ENODEV);
565         
566         lir = (struct llog_logid_rec *)rec;
567         logid = &lir->lid_id;
568         rc = llog_create(ctxt, &handle, logid, NULL);
569         if (rc)
570                 RETURN(-EINVAL);
571
572         rc = llog_init_handle(handle, 0, NULL);
573         if (rc)
574                 GOTO(out_close, rc);
575
576         for (index = 1; index < (LLOG_BITMAP_BYTES * 8); index++) {
577                 if (ext2_test_bit(index, handle->lgh_hdr->llh_bitmap))
578                         count++;
579         }
580
581         l = snprintf(out, remains, "\t[Log ID]: #"LPX64"#"LPX64"#%08x\n"
582                      "\tLog Size: %llu\n\tLast Index: %d\n"
583                      "\tUncanceled Records: %d\n",
584                      logid->lgl_oid, logid->lgl_ogr, logid->lgl_ogen,
585                      i_size_read(handle->lgh_file->f_dentry->d_inode),
586                      handle->lgh_last_idx, count);
587         out += l;
588         remains -= l;
589         cbd->out = out;
590         cbd->remains = remains;
591         if (remains <= 0) {
592                 CWARN("Not enough memory\n");
593                 rc = -ENOMEM;
594         }
595         GOTO(out_close, rc);
596 out_close:
597         llog_close(handle);
598         return rc;
599 }
600
601 static int llog_catinfo_deletions(struct obd_device *obd, char *buf,
602                                   int buf_len)
603 {
604         struct mds_obd *mds = &obd->u.mds;
605         struct llog_handle *handle;
606         struct lvfs_run_ctxt saved;
607         int size, i, count;
608         struct llog_catid *idarray;
609         char name[32] = CATLIST;
610         int rc;
611         struct cb_data data;
612         struct llog_ctxt *ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
613         ENTRY;
614
615         if (ctxt == NULL || mds == NULL)
616                 GOTO(release_ctxt, rc = -ENODEV);
617        
618         count = mds->mds_lov_desc.ld_tgt_count;
619         size = sizeof(*idarray) * count;
620
621         OBD_VMALLOC(idarray, size);
622         if (!idarray)
623                 GOTO(release_ctxt, rc = -ENOMEM);
624
625         mutex_down(&obd->obd_llog_cat_process);
626         rc = llog_get_cat_list(obd, obd, name, 0, count, idarray);
627         if (rc)
628                 GOTO(out_free, rc);
629
630         push_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
631
632         data.ctxt = ctxt;
633         data.out = buf;
634         data.remains = buf_len;
635         for (i = 0; i < count; i++) {
636                 int l, index, uncanceled = 0;
637
638                 rc = llog_create(ctxt, &handle, &idarray[i].lci_logid, NULL);
639                 if (rc)
640                         GOTO(out_pop, rc);
641                 rc = llog_init_handle(handle, 0, NULL);
642                 if (rc) {
643                         llog_close(handle);
644                         GOTO(out_pop, rc = -ENOENT);
645                 }
646                 for (index = 1; index < (LLOG_BITMAP_BYTES * 8); index++) {
647                         if (ext2_test_bit(index, handle->lgh_hdr->llh_bitmap))
648                                 uncanceled++;
649                 }
650                 l = snprintf(data.out, data.remains,
651                              "\n[Catlog ID]: #"LPX64"#"LPX64"#%08x  "
652                              "[Log Count]: %d\n",
653                              idarray[i].lci_logid.lgl_oid,
654                              idarray[i].lci_logid.lgl_ogr,
655                              idarray[i].lci_logid.lgl_ogen, uncanceled);
656
657                 data.out += l;
658                 data.remains -= l;
659                 data.init = 1;
660
661                 llog_process(handle, llog_catinfo_cb, &data, NULL);
662                 llog_close(handle);
663
664                 if (data.remains <= 0)
665                         break;
666         }
667         GOTO(out_pop, rc);
668 out_pop:
669         pop_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
670 out_free:
671         mutex_up(&obd->obd_llog_cat_process);
672         OBD_VFREE(idarray, size);
673 release_ctxt:
674         llog_ctxt_put(ctxt);
675         return rc;
676 }
677
678 int llog_catinfo(struct ptlrpc_request *req)
679 {
680         struct obd_export *exp = req->rq_export;
681         struct obd_device *obd = exp->exp_obd;
682         char *keyword;
683         char *buf, *reply;
684         int rc, buf_len = LLOG_CHUNK_SIZE;
685         int size[2] = { sizeof(struct ptlrpc_body), buf_len };
686         ENTRY;
687
688         OBD_ALLOC(buf, buf_len);
689         if (buf == NULL)
690                 RETURN(-ENOMEM);
691
692         keyword = lustre_msg_string(req->rq_reqmsg, REQ_REC_OFF, 0);
693
694         if (strcmp(keyword, "config") == 0) {
695                 char *client = lustre_msg_string(req->rq_reqmsg,
696                                                  REQ_REC_OFF + 1, 0);
697                 rc = llog_catinfo_config(obd, buf, buf_len, client);
698         } else if (strcmp(keyword, "deletions") == 0) {
699                 rc = llog_catinfo_deletions(obd, buf, buf_len);
700         } else {
701                 rc = -EOPNOTSUPP;
702         }
703
704         rc = lustre_pack_reply(req, 2, size, NULL);
705         if (rc)
706                 GOTO(out_free, rc = -ENOMEM);
707
708         reply = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, buf_len);
709         if (strlen(buf) == 0)
710                 sprintf(buf, "%s", "No log informations\n");
711         memcpy(reply, buf, buf_len);
712         GOTO(out_free, rc);
713 out_free:
714         OBD_FREE(buf, buf_len);
715         return rc;
716 }
717
718 #else /* !__KERNEL__ */
719 int llog_origin_handle_create(struct ptlrpc_request *req)
720 {
721         LBUG();
722         return 0;
723 }
724
725 int llog_origin_handle_destroy(struct ptlrpc_request *req)
726 {
727         LBUG();
728         return 0;
729 }
730
731 int llog_origin_handle_next_block(struct ptlrpc_request *req)
732 {
733         LBUG();
734         return 0;
735 }
736 int llog_origin_handle_prev_block(struct ptlrpc_request *req)
737 {
738         LBUG();
739         return 0;
740 }
741 int llog_origin_handle_read_header(struct ptlrpc_request *req)
742 {
743         LBUG();
744         return 0;
745 }
746 int llog_origin_handle_close(struct ptlrpc_request *req)
747 {
748         LBUG();
749         return 0;
750 }
751 int llog_origin_handle_cancel(struct ptlrpc_request *req)
752 {
753         LBUG();
754         return 0;
755 }
756 #endif