4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
27 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, Whamcloud, Inc.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/ptlrpc/llog_server.c
38 * remote api for llog - server side
40 * Author: Andreas Dilger <adilger@clusterfs.com>
43 #define DEBUG_SUBSYSTEM S_LOG
46 #include <liblustre.h>
49 #include <obd_class.h>
50 #include <lustre_log.h>
51 #include <lustre_net.h>
52 #include <libcfs/list.h>
53 #include <lustre_fsfilt.h>
55 #if defined(__KERNEL__) && defined(LUSTRE_LOG_SERVER)
57 int llog_origin_handle_create(struct ptlrpc_request *req)
59 struct obd_export *exp = req->rq_export;
60 struct obd_device *obd = exp->exp_obd;
61 struct obd_device *disk_obd;
62 struct llog_handle *loghandle;
63 struct llogd_body *body;
64 struct lvfs_run_ctxt saved;
65 struct llog_logid *logid = NULL;
66 struct llog_ctxt *ctxt;
71 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
75 if (body->lgd_logid.lgl_oid > 0)
76 logid = &body->lgd_logid;
78 if (req_capsule_field_present(&req->rq_pill, &RMF_NAME, RCL_CLIENT)) {
79 name = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
82 CDEBUG(D_INFO, "%s: opening log %s\n", obd->obd_name, name);
85 ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
87 CDEBUG(D_WARNING, "%s: no ctxt. group=%p idx=%d name=%s\n",
88 obd->obd_name, &obd->obd_olg, body->lgd_ctxt_idx, name);
91 disk_obd = ctxt->loc_exp->exp_obd;
92 push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
94 rc = llog_create(ctxt, &loghandle, logid, name);
98 rc = req_capsule_server_pack(&req->rq_pill);
100 GOTO(out_close, rc = -ENOMEM);
102 body = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
103 body->lgd_logid = loghandle->lgh_id;
107 rc2 = llog_close(loghandle);
111 pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
115 EXPORT_SYMBOL(llog_origin_handle_create);
117 int llog_origin_handle_destroy(struct ptlrpc_request *req)
119 struct obd_export *exp = req->rq_export;
120 struct obd_device *obd = exp->exp_obd;
121 struct obd_device *disk_obd;
122 struct llog_handle *loghandle;
123 struct llogd_body *body;
124 struct lvfs_run_ctxt saved;
125 struct llog_logid *logid = NULL;
126 struct llog_ctxt *ctxt;
130 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
134 if (body->lgd_logid.lgl_oid > 0)
135 logid = &body->lgd_logid;
137 ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
141 disk_obd = ctxt->loc_exp->exp_obd;
142 push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
144 rc = llog_create(ctxt, &loghandle, logid, NULL);
148 rc = req_capsule_server_pack(&req->rq_pill);
150 GOTO(out_close, rc = -ENOMEM);
152 body = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
153 body->lgd_logid = loghandle->lgh_id;
154 rc = llog_init_handle(loghandle, LLOG_F_IS_PLAIN, NULL);
157 rc = llog_destroy(loghandle);
160 llog_free_handle(loghandle);
164 llog_close(loghandle);
166 pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
170 EXPORT_SYMBOL(llog_origin_handle_destroy);
172 int llog_origin_handle_next_block(struct ptlrpc_request *req)
174 struct obd_export *exp = req->rq_export;
175 struct obd_device *obd = exp->exp_obd;
176 struct obd_device *disk_obd;
177 struct llog_handle *loghandle;
178 struct llogd_body *body;
179 struct llogd_body *repbody;
180 struct lvfs_run_ctxt saved;
181 struct llog_ctxt *ctxt;
188 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
192 OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
196 ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
198 GOTO(out_free, rc = -ENODEV);
199 disk_obd = ctxt->loc_exp->exp_obd;
200 push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
202 rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL);
206 flags = body->lgd_llh_flags;
207 rc = llog_init_handle(loghandle, flags, NULL);
211 memset(buf, 0, LLOG_CHUNK_SIZE);
212 rc = llog_next_block(loghandle, &body->lgd_saved_index,
214 &body->lgd_cur_offset, buf, LLOG_CHUNK_SIZE);
218 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_SERVER,
220 rc = req_capsule_server_pack(&req->rq_pill);
222 GOTO(out_close, rc = -ENOMEM);
224 repbody = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
227 ptr = req_capsule_server_get(&req->rq_pill, &RMF_EADATA);
228 memcpy(ptr, buf, LLOG_CHUNK_SIZE);
231 rc2 = llog_close(loghandle);
235 pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
238 OBD_FREE(buf, LLOG_CHUNK_SIZE);
241 EXPORT_SYMBOL(llog_origin_handle_next_block);
243 int llog_origin_handle_prev_block(struct ptlrpc_request *req)
245 struct obd_export *exp = req->rq_export;
246 struct obd_device *obd = exp->exp_obd;
247 struct llog_handle *loghandle;
248 struct llogd_body *body;
249 struct llogd_body *repbody;
250 struct obd_device *disk_obd;
251 struct lvfs_run_ctxt saved;
252 struct llog_ctxt *ctxt;
259 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
263 OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
267 ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
269 GOTO(out_free, rc = -ENODEV);
271 disk_obd = ctxt->loc_exp->exp_obd;
272 push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
274 rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL);
278 flags = body->lgd_llh_flags;
279 rc = llog_init_handle(loghandle, flags, NULL);
283 memset(buf, 0, LLOG_CHUNK_SIZE);
284 rc = llog_prev_block(loghandle, body->lgd_index,
285 buf, LLOG_CHUNK_SIZE);
289 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_SERVER,
291 rc = req_capsule_server_pack(&req->rq_pill);
293 GOTO(out_close, rc = -ENOMEM);
295 repbody = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
298 ptr = req_capsule_server_get(&req->rq_pill, &RMF_EADATA);
299 memcpy(ptr, buf, LLOG_CHUNK_SIZE);
302 rc2 = llog_close(loghandle);
307 pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
310 OBD_FREE(buf, LLOG_CHUNK_SIZE);
313 EXPORT_SYMBOL(llog_origin_handle_prev_block);
315 int llog_origin_handle_read_header(struct ptlrpc_request *req)
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;
329 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
333 ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
337 disk_obd = ctxt->loc_exp->exp_obd;
338 push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
340 rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL);
345 * llog_init_handle() reads the llog header
347 flags = body->lgd_llh_flags;
348 rc = llog_init_handle(loghandle, flags, NULL);
352 rc = req_capsule_server_pack(&req->rq_pill);
354 GOTO(out_close, rc = -ENOMEM);
356 hdr = req_capsule_server_get(&req->rq_pill, &RMF_LLOG_LOG_HDR);
357 *hdr = *loghandle->lgh_hdr;
360 rc2 = llog_close(loghandle);
364 pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
368 EXPORT_SYMBOL(llog_origin_handle_read_header);
370 int llog_origin_handle_close(struct ptlrpc_request *req)
376 EXPORT_SYMBOL(llog_origin_handle_close);
378 int llog_origin_handle_cancel(struct ptlrpc_request *req)
380 struct obd_device *obd = req->rq_export->exp_obd;
381 int num_cookies, rc = 0, err, i, failed = 0;
382 struct obd_device *disk_obd;
383 struct llog_cookie *logcookies;
384 struct llog_ctxt *ctxt = NULL;
385 struct lvfs_run_ctxt saved;
386 struct llog_handle *cathandle;
391 logcookies = req_capsule_client_get(&req->rq_pill, &RMF_LOGCOOKIES);
392 num_cookies = req_capsule_get_size(&req->rq_pill, &RMF_LOGCOOKIES,
393 RCL_CLIENT) / sizeof(*logcookies);
394 if (logcookies == NULL || num_cookies == 0) {
395 DEBUG_REQ(D_HA, req, "No llog cookies sent");
399 ctxt = llog_get_context(obd, logcookies->lgc_subsys);
403 disk_obd = ctxt->loc_exp->exp_obd;
404 push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
405 for (i = 0; i < num_cookies; i++, logcookies++) {
406 cathandle = ctxt->loc_handle;
407 LASSERT(cathandle != NULL);
408 inode = cathandle->lgh_file->f_dentry->d_inode;
410 handle = fsfilt_start_log(disk_obd, inode,
411 FSFILT_OP_CANCEL_UNLINK, NULL, 1);
412 if (IS_ERR(handle)) {
413 CERROR("fsfilt_start_log() failed: %ld\n",
415 GOTO(pop_ctxt, rc = PTR_ERR(handle));
418 rc = llog_cat_cancel_records(cathandle, 1, logcookies);
421 * Do not raise -ENOENT errors for resent rpcs. This rec already
425 (lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT)) {
427 * Do not change this message, reply-single.sh test_59b
428 * expects to find this in log.
430 CDEBUG(D_RPCTRACE, "RESENT cancel req %p - ignored\n",
433 } else if (rc == 0) {
434 CDEBUG(D_RPCTRACE, "Canceled %d llog-records\n",
438 err = fsfilt_commit(disk_obd, inode, handle, 0);
440 CERROR("Error committing transaction: %d\n", err);
450 pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
452 CERROR("Cancel %d of %d llog-records failed: %d\n",
453 failed, num_cookies, rc);
458 EXPORT_SYMBOL(llog_origin_handle_cancel);
460 #else /* !__KERNEL__ */
461 int llog_origin_handle_create(struct ptlrpc_request *req)
467 int llog_origin_handle_destroy(struct ptlrpc_request *req)
473 int llog_origin_handle_next_block(struct ptlrpc_request *req)
478 int llog_origin_handle_prev_block(struct ptlrpc_request *req)
483 int llog_origin_handle_read_header(struct ptlrpc_request *req)
488 int llog_origin_handle_close(struct ptlrpc_request *req)
493 int llog_origin_handle_cancel(struct ptlrpc_request *req)