1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 Cluster File Systems, Inc.
5 * Author: Andreas Dilger <adilger@clusterfs.com>
7 * This file is part of Lustre, http://www.lustre.org.
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.
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.
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.
22 * remote api for llog - server side
26 #define DEBUG_SUBSYSTEM S_LOG
33 #include <linux/obd_class.h>
34 #include <linux/lustre_log.h>
35 #include <linux/lustre_net.h>
36 #include <portals/list.h>
38 int llog_origin_handle_create(struct ptlrpc_request *req)
40 struct obd_export *exp = req->rq_export;
41 struct obd_device *obd = exp->exp_obd;
42 struct obd_device *disk_obd;
43 struct llog_handle *loghandle;
44 struct llogd_body *body;
45 struct obd_run_ctxt saved;
46 struct llog_logid *logid = NULL;
47 struct llog_ctxt *ctxt;
49 int size = sizeof (*body);
53 body = lustre_swab_reqbuf(req, 0, sizeof(*body),
54 lustre_swab_llogd_body);
56 CERROR ("Can't unpack llogd_body\n");
57 GOTO(out, rc =-EFAULT);
60 if (body->lgd_logid.lgl_oid > 0)
61 logid = &body->lgd_logid;
63 if (req->rq_reqmsg->bufcount > 1) {
64 name = lustre_msg_string(req->rq_reqmsg, 1, 0);
66 CERROR("Can't unpack name\n");
67 GOTO(out, rc = -EFAULT);
71 ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
72 LASSERT(ctxt != NULL);
73 disk_obd = ctxt->loc_exp->exp_obd;
74 push_ctxt(&saved, &disk_obd->obd_ctxt, NULL);
76 rc = llog_create(ctxt, &loghandle, logid, name);
80 rc = lustre_pack_reply(req, 1, &size, NULL);
82 GOTO(out_close, rc = -ENOMEM);
84 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*body));
85 body->lgd_logid = loghandle->lgh_id;
88 rc2 = llog_close(loghandle);
92 pop_ctxt(&saved, &disk_obd->obd_ctxt, NULL);
97 int llog_origin_handle_next_block(struct ptlrpc_request *req)
99 struct obd_export *exp = req->rq_export;
100 struct obd_device *obd = exp->exp_obd;
101 struct obd_device *disk_obd;
102 struct llog_handle *loghandle;
103 struct llogd_body *body;
104 struct obd_run_ctxt saved;
105 struct llog_ctxt *ctxt;
109 int size[] = {sizeof (*body),
114 body = lustre_swab_reqbuf(req, 0, sizeof(*body),
115 lustre_swab_llogd_body);
117 CERROR ("Can't unpack llogd_body\n");
118 GOTO(out, rc =-EFAULT);
121 OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
123 GOTO(out, rc = -ENOMEM);
125 ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
126 LASSERT(ctxt != NULL);
127 disk_obd = ctxt->loc_exp->exp_obd;
128 push_ctxt(&saved, &disk_obd->obd_ctxt, NULL);
130 rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL);
134 flags = body->lgd_llh_flags;
135 rc = llog_init_handle(loghandle, flags, NULL);
139 memset(buf, 0, LLOG_CHUNK_SIZE);
140 rc = llog_next_block(loghandle, &body->lgd_saved_index,
142 &body->lgd_cur_offset, buf, LLOG_CHUNK_SIZE);
147 rc = lustre_pack_reply(req, 2, size, NULL);
149 GOTO(out_close, rc = -ENOMEM);
151 ptr = lustre_msg_buf(req->rq_repmsg, 0, sizeof (body));
152 memcpy(ptr, body, sizeof(*body));
154 ptr = lustre_msg_buf(req->rq_repmsg, 1, LLOG_CHUNK_SIZE);
155 memcpy(ptr, buf, LLOG_CHUNK_SIZE);
158 rc2 = llog_close(loghandle);
163 pop_ctxt(&saved, &disk_obd->obd_ctxt, NULL);
164 OBD_FREE(buf, LLOG_CHUNK_SIZE);
169 int llog_origin_handle_read_header(struct ptlrpc_request *req)
171 struct obd_export *exp = req->rq_export;
172 struct obd_device *obd = exp->exp_obd;
173 struct obd_device *disk_obd;
174 struct llog_handle *loghandle;
175 struct llogd_body *body;
176 struct llog_log_hdr *hdr;
177 struct obd_run_ctxt saved;
178 struct llog_ctxt *ctxt;
181 int size[] = {sizeof (*hdr)};
185 body = lustre_swab_reqbuf(req, 0, sizeof(*body),
186 lustre_swab_llogd_body);
188 CERROR ("Can't unpack llogd_body\n");
189 GOTO(out, rc =-EFAULT);
192 OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
194 GOTO(out, rc = -ENOMEM);
196 ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
197 LASSERT(ctxt != NULL);
198 disk_obd = ctxt->loc_exp->exp_obd;
199 push_ctxt(&saved, &disk_obd->obd_ctxt, NULL);
201 rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL);
205 /* init_handle reads the header */
206 flags = body->lgd_llh_flags;
207 rc = llog_init_handle(loghandle, flags, NULL);
212 rc = lustre_pack_reply(req, 1, size, NULL);
214 GOTO(out_close, rc = -ENOMEM);
216 hdr = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*hdr));
217 memcpy(hdr, loghandle->lgh_hdr, sizeof(*hdr));
220 rc2 = llog_close(loghandle);
225 pop_ctxt(&saved, &disk_obd->obd_ctxt, NULL);
226 OBD_FREE(buf, LLOG_CHUNK_SIZE);
232 int llog_origin_handle_close(struct ptlrpc_request *req)
241 #ifdef ENABLE_ORPHANS
242 int llog_origin_handle_cancel(struct ptlrpc_request *req)
244 struct obd_device *obd = req->rq_export->exp_obd;
245 struct obd_device *disk_obd;
246 struct llog_cookie *logcookies;
247 struct llog_ctxt *ctxt;
248 int num_cookies, rc = 0;
249 struct obd_run_ctxt saved;
250 struct llog_handle *cathandle;
253 logcookies = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*logcookies));
254 num_cookies = req->rq_reqmsg->buflens[0]/sizeof(*logcookies);
255 if (logcookies == NULL || num_cookies == 0) {
256 DEBUG_REQ(D_HA, req, "no cookies sent");
260 ctxt = llog_get_context(obd, logcookies->lgc_subsys);
262 CWARN("llog subsys not setup or already cleanup\n");
265 down(&ctxt->loc_sem);
266 disk_obd = ctxt->loc_exp->exp_obd;
267 cathandle = ctxt->loc_handle;
270 push_ctxt(&saved, &disk_obd->obd_ctxt, NULL);
271 rc = llog_cat_cancel_records(cathandle, num_cookies, logcookies);
273 CERROR("cancel %d llog-records failed: %d\n", num_cookies, rc);
275 CWARN("cancel %d llog-records\n", num_cookies);
277 pop_ctxt(&saved, &disk_obd->obd_ctxt, NULL);
282 EXPORT_SYMBOL(llog_origin_handle_cancel);
285 static int llog_catinfo_config(struct obd_device *obd, char *buf, int buf_len,
288 struct mds_obd *mds = &obd->u.mds;
289 struct llog_ctxt *ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
290 struct obd_run_ctxt saved;
291 struct llog_handle *handle = NULL;
293 int rc, i, l, remains = buf_len;
296 if (ctxt == NULL || mds == NULL)
299 push_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_ctxt, NULL);
301 sprintf(name[0], "%s", mds->mds_profile);
302 sprintf(name[1], "%s-clean", mds->mds_profile);
303 sprintf(name[2], "%s", client);
304 sprintf(name[3], "%s-clean", client);
306 for (i = 0; i < 4; i++) {
307 int index, uncanceled = 0;
308 rc = llog_create(ctxt, &handle, NULL, name[i]);
311 rc = llog_init_handle(handle, 0, NULL);
314 GOTO(out_pop, rc = -ENOENT);
317 for (index = 1; index < (LLOG_BITMAP_BYTES * 8); index ++) {
318 if (ext2_test_bit(index, handle->lgh_hdr->llh_bitmap))
322 l = snprintf(out, remains, "[Log Name]: %s\nLog Size: "LPD64"\n"
323 "Last Index: %d\nUncanceled Records: %d\n\n",
325 handle->lgh_file->f_dentry->d_inode->i_size,
326 handle->lgh_last_idx,
336 pop_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_ctxt, NULL);
341 struct llog_ctxt *ctxt;
347 static int llog_catinfo_cb(struct llog_handle *cat,
348 struct llog_rec_hdr *rec, void *data)
350 static char *out = NULL;
351 static int remains = 0;
352 struct llog_ctxt *ctxt;
353 struct llog_handle *handle;
354 struct llog_logid *logid;
355 struct llog_logid_rec *lir;
356 int l, rc, index, count = 0;
357 struct cb_data *cbd = (struct cb_data*)data;
361 remains = cbd->remains;
366 if (!(cat->lgh_hdr->llh_flags & cpu_to_le32(LLOG_F_IS_CAT)))
369 lir = (struct llog_logid_rec *)rec;
370 logid = &lir->lid_id;
371 rc = llog_create(ctxt, &handle, logid, NULL);
374 rc = llog_init_handle(handle, 0, NULL);
378 for (index = 1; index < (LLOG_BITMAP_BYTES * 8); index++) {
379 if (ext2_test_bit(index, handle->lgh_hdr->llh_bitmap))
383 l = snprintf(out, remains, "\t[Log ID]: #"LPX64"#"LPX64"#%08x\n"
384 "\tLog Size: "LPD64"\n\tLast Index: %d\n"
385 "\tUncanceled Records: %d\n",
386 logid->lgl_oid, logid->lgl_ogr, logid->lgl_ogen,
387 handle->lgh_file->f_dentry->d_inode->i_size,
388 handle->lgh_last_idx, count);
392 cbd->remains = remains;
394 CWARN("Not enough memory\n");
403 static int llog_catinfo_deletions(struct obd_device *obd, char *buf,
406 struct mds_obd *mds = &obd->u.mds;
407 struct llog_handle *handle;
408 struct obd_run_ctxt saved;
410 struct llog_logid *idarray, *id;
411 char name[32] = "CATLIST";
414 struct llog_ctxt *ctxt = llog_get_context(obd, LLOG_CONFIG_ORIG_CTXT);
416 if (ctxt == NULL || mds == NULL)
419 count = mds->mds_lov_desc.ld_tgt_count;
420 size = sizeof(*idarray) * count;
422 OBD_ALLOC(idarray, size);
425 memset(idarray, 0, size);
427 rc = llog_get_cat_list(obd, obd, name, count, idarray);
431 push_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_ctxt, NULL);
436 data.remains = buf_len;
437 for (i = 0; i < count; i++) {
438 int l, index, uncanceled = 0;
439 rc = llog_create(ctxt, &handle, id, NULL);
442 rc = llog_init_handle(handle, 0, NULL);
445 GOTO(out_pop, rc = -ENOENT);
447 for (index = 1; index < (LLOG_BITMAP_BYTES * 8); index++) {
448 if (ext2_test_bit(index, handle->lgh_hdr->llh_bitmap))
451 l = snprintf(data.out, data.remains,
452 "\n[Catlog ID]: #"LPX64"#"LPX64"#%08x "
454 id->lgl_oid, id->lgl_ogr, id->lgl_ogen,
461 llog_process(handle, llog_catinfo_cb, &data);
464 if (data.remains <= 0)
468 pop_ctxt(&saved, &ctxt->loc_exp->exp_obd->obd_ctxt, NULL);
470 OBD_FREE(idarray, size);
474 int llog_catinfo(struct ptlrpc_request *req)
476 struct obd_export *exp = req->rq_export;
477 struct obd_device *obd = exp->exp_obd;
480 int rc, buf_len = LLOG_CHUNK_SIZE;
482 OBD_ALLOC(buf, buf_len);
485 memset(buf, 0, buf_len);
487 keyword = lustre_msg_string(req->rq_reqmsg, 0, 0);
489 if (strcmp(keyword, "config") == 0) {
490 char *client = lustre_msg_string(req->rq_reqmsg, 1, 0);
491 rc = llog_catinfo_config(obd, buf, buf_len, client);
492 } else if (strcmp(keyword, "deletions") == 0) {
493 rc = llog_catinfo_deletions(obd, buf, buf_len);
498 rc = lustre_pack_reply(req, 1, &buf_len, NULL);
500 GOTO(out_free, rc = -ENOMEM);
502 reply = lustre_msg_buf(req->rq_repmsg, 0, buf_len);
503 if (strlen(buf) == 0)
504 sprintf(buf, "%s", "No log informations\n");
505 memcpy(reply, buf, buf_len);
508 OBD_FREE(buf, buf_len);