Whamcloud - gitweb
Branch b1_8
[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                 /* Do not raise -ENOENT errors for resent rpcs. This rec already
443                  * might be killed. */
444                 if (rc == -ENOENT && 
445                     (lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT)) {
446                         /* Do not change this message, reply-single.sh test_59b
447                          * expects to find this in dmesg. */
448                         CDEBUG(D_RPCTRACE, "RESENT cancel req %p - ignored\n",
449                                req);
450                         rc = 0;
451                 } else if (rc == 0) {
452                         CDEBUG(D_RPCTRACE, "Canceled %d llog-records\n", 
453                                num_cookies);
454                 }
455
456                 err = fsfilt_commit(disk_obd, inode, handle, 0);
457                 if (err) {
458                         CERROR("Error committing transaction: %d\n", err);
459                         if (!rc)
460                                 rc = err;
461                         failed++;
462                         GOTO(pop_ctxt, rc);
463                 } else if (rc)
464                         failed++;
465         }
466         EXIT;
467 pop_ctxt:
468         pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
469         if (rc)
470                 CERROR("Cancel %d of %d llog-records failed: %d\n", 
471                        failed, num_cookies, rc);
472
473         llog_ctxt_put(ctxt);
474         return rc;
475 }
476 EXPORT_SYMBOL(llog_origin_handle_cancel);
477
478 static int llog_catinfo_config(struct obd_device *obd, char *buf, int buf_len,
479                                char *client)
480 {
481         struct mds_obd *mds = &obd->u.mds;
482         struct llog_ctxt *ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
483         struct lvfs_run_ctxt saved;
484         struct llog_handle *handle = NULL;
485         char name[4][64];
486         int rc, i, l, remains = buf_len;
487         char *out = buf;
488         ENTRY;
489
490         if (ctxt == NULL || mds == NULL)
491                 GOTO(release_ctxt, rc = -ENODEV);
492
493         push_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
494
495         sprintf(name[0], "%s", mds->mds_profile);
496         sprintf(name[1], "%s-clean", mds->mds_profile);
497         sprintf(name[2], "%s", client);
498         sprintf(name[3], "%s-clean", client);
499
500         for (i = 0; i < 4; i++) {
501                 int index, uncanceled = 0;
502                 rc = llog_create(ctxt, &handle, NULL, name[i]);
503                 if (rc)
504                         GOTO(out_pop, rc);
505                 rc = llog_init_handle(handle, 0, NULL);
506                 if (rc) {
507                         llog_close(handle);
508                         GOTO(out_pop, rc = -ENOENT);
509                 }
510
511                 for (index = 1; index < (LLOG_BITMAP_BYTES * 8); index ++) {
512                         if (ext2_test_bit(index, handle->lgh_hdr->llh_bitmap))
513                                 uncanceled++;
514                 }
515
516                 l = snprintf(out, remains, "[Log Name]: %s\nLog Size: %llu\n"
517                              "Last Index: %d\nUncanceled Records: %d\n\n",
518                              name[i],
519                              i_size_read(handle->lgh_file->f_dentry->d_inode),
520                              handle->lgh_last_idx, uncanceled);
521                 out += l;
522                 remains -= l;
523
524                 llog_close(handle);
525                 if (remains <= 0)
526                         break;
527         }
528         GOTO(out_pop, rc);
529 out_pop:
530         pop_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
531 release_ctxt:
532         llog_ctxt_put(ctxt);
533         return rc;
534 }
535
536 struct cb_data {
537         struct llog_ctxt *ctxt;
538         char *out;
539         int  remains;
540         int  init;
541 };
542
543 static int llog_catinfo_cb(struct llog_handle *cat,
544                            struct llog_rec_hdr *rec, void *data)
545 {
546         static char *out = NULL;
547         static int remains = 0;
548         struct llog_ctxt *ctxt = NULL;
549         struct llog_handle *handle;
550         struct llog_logid *logid;
551         struct llog_logid_rec *lir;
552         int l, rc, index, count = 0;
553         struct cb_data *cbd = (struct cb_data*)data;
554         ENTRY;
555
556         if (cbd->init) {
557                 out = cbd->out;
558                 remains = cbd->remains;
559                 cbd->init = 0;
560         }
561
562         if (!(cat->lgh_hdr->llh_flags & LLOG_F_IS_CAT)) 
563                 RETURN(-EINVAL);
564
565         if (!cbd->ctxt)
566                 RETURN(-ENODEV);
567         
568         lir = (struct llog_logid_rec *)rec;
569         logid = &lir->lid_id;
570         rc = llog_create(ctxt, &handle, logid, NULL);
571         if (rc)
572                 RETURN(-EINVAL);
573
574         rc = llog_init_handle(handle, 0, NULL);
575         if (rc)
576                 GOTO(out_close, rc);
577
578         for (index = 1; index < (LLOG_BITMAP_BYTES * 8); index++) {
579                 if (ext2_test_bit(index, handle->lgh_hdr->llh_bitmap))
580                         count++;
581         }
582
583         l = snprintf(out, remains, "\t[Log ID]: #"LPX64"#"LPX64"#%08x\n"
584                      "\tLog Size: %llu\n\tLast Index: %d\n"
585                      "\tUncanceled Records: %d\n",
586                      logid->lgl_oid, logid->lgl_ogr, logid->lgl_ogen,
587                      i_size_read(handle->lgh_file->f_dentry->d_inode),
588                      handle->lgh_last_idx, count);
589         out += l;
590         remains -= l;
591         cbd->out = out;
592         cbd->remains = remains;
593         if (remains <= 0) {
594                 CWARN("Not enough memory\n");
595                 rc = -ENOMEM;
596         }
597         GOTO(out_close, rc);
598 out_close:
599         llog_close(handle);
600         return rc;
601 }
602
603 static int llog_catinfo_deletions(struct obd_device *obd, char *buf,
604                                   int buf_len)
605 {
606         struct mds_obd *mds = &obd->u.mds;
607         struct llog_handle *handle;
608         struct lvfs_run_ctxt saved;
609         int size, i, count;
610         struct llog_catid *idarray;
611         char name[32] = CATLIST;
612         int rc;
613         struct cb_data data;
614         struct llog_ctxt *ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
615         ENTRY;
616
617         if (ctxt == NULL || mds == NULL)
618                 GOTO(release_ctxt, rc = -ENODEV);
619        
620         count = mds->mds_lov_desc.ld_tgt_count;
621         size = sizeof(*idarray) * count;
622
623         OBD_VMALLOC(idarray, size);
624         if (!idarray)
625                 GOTO(release_ctxt, rc = -ENOMEM);
626
627         mutex_down(&obd->obd_llog_cat_process);
628         rc = llog_get_cat_list(obd, obd, name, 0, count, idarray);
629         if (rc)
630                 GOTO(out_free, rc);
631
632         push_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
633
634         data.ctxt = ctxt;
635         data.out = buf;
636         data.remains = buf_len;
637         for (i = 0; i < count; i++) {
638                 int l, index, uncanceled = 0;
639
640                 rc = llog_create(ctxt, &handle, &idarray[i].lci_logid, NULL);
641                 if (rc)
642                         GOTO(out_pop, rc);
643                 rc = llog_init_handle(handle, 0, NULL);
644                 if (rc) {
645                         llog_close(handle);
646                         GOTO(out_pop, rc = -ENOENT);
647                 }
648                 for (index = 1; index < (LLOG_BITMAP_BYTES * 8); index++) {
649                         if (ext2_test_bit(index, handle->lgh_hdr->llh_bitmap))
650                                 uncanceled++;
651                 }
652                 l = snprintf(data.out, data.remains,
653                              "\n[Catlog ID]: #"LPX64"#"LPX64"#%08x  "
654                              "[Log Count]: %d\n",
655                              idarray[i].lci_logid.lgl_oid,
656                              idarray[i].lci_logid.lgl_ogr,
657                              idarray[i].lci_logid.lgl_ogen, uncanceled);
658
659                 data.out += l;
660                 data.remains -= l;
661                 data.init = 1;
662
663                 llog_process(handle, llog_catinfo_cb, &data, NULL);
664                 llog_close(handle);
665
666                 if (data.remains <= 0)
667                         break;
668         }
669         GOTO(out_pop, rc);
670 out_pop:
671         pop_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_lvfs_ctxt, NULL);
672 out_free:
673         mutex_up(&obd->obd_llog_cat_process);
674         OBD_VFREE(idarray, size);
675 release_ctxt:
676         llog_ctxt_put(ctxt);
677         return rc;
678 }
679
680 int llog_catinfo(struct ptlrpc_request *req)
681 {
682         struct obd_export *exp = req->rq_export;
683         struct obd_device *obd = exp->exp_obd;
684         char *keyword;
685         char *buf, *reply;
686         int rc, buf_len = LLOG_CHUNK_SIZE;
687         int size[2] = { sizeof(struct ptlrpc_body), buf_len };
688         ENTRY;
689
690         OBD_ALLOC(buf, buf_len);
691         if (buf == NULL)
692                 RETURN(-ENOMEM);
693
694         keyword = lustre_msg_string(req->rq_reqmsg, REQ_REC_OFF, 0);
695
696         if (strcmp(keyword, "config") == 0) {
697                 char *client = lustre_msg_string(req->rq_reqmsg,
698                                                  REQ_REC_OFF + 1, 0);
699                 rc = llog_catinfo_config(obd, buf, buf_len, client);
700         } else if (strcmp(keyword, "deletions") == 0) {
701                 rc = llog_catinfo_deletions(obd, buf, buf_len);
702         } else {
703                 rc = -EOPNOTSUPP;
704         }
705
706         rc = lustre_pack_reply(req, 2, size, NULL);
707         if (rc)
708                 GOTO(out_free, rc = -ENOMEM);
709
710         reply = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, buf_len);
711         if (strlen(buf) == 0)
712                 sprintf(buf, "%s", "No log informations\n");
713         memcpy(reply, buf, buf_len);
714         GOTO(out_free, rc);
715 out_free:
716         OBD_FREE(buf, buf_len);
717         return rc;
718 }
719
720 #else /* !__KERNEL__ */
721 int llog_origin_handle_create(struct ptlrpc_request *req)
722 {
723         LBUG();
724         return 0;
725 }
726
727 int llog_origin_handle_destroy(struct ptlrpc_request *req)
728 {
729         LBUG();
730         return 0;
731 }
732
733 int llog_origin_handle_next_block(struct ptlrpc_request *req)
734 {
735         LBUG();
736         return 0;
737 }
738 int llog_origin_handle_prev_block(struct ptlrpc_request *req)
739 {
740         LBUG();
741         return 0;
742 }
743 int llog_origin_handle_read_header(struct ptlrpc_request *req)
744 {
745         LBUG();
746         return 0;
747 }
748 int llog_origin_handle_close(struct ptlrpc_request *req)
749 {
750         LBUG();
751         return 0;
752 }
753 int llog_origin_handle_cancel(struct ptlrpc_request *req)
754 {
755         LBUG();
756         return 0;
757 }
758 #endif