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);
116 int llog_origin_handle_destroy(struct ptlrpc_request *req)
118 struct obd_export *exp = req->rq_export;
119 struct obd_device *obd = exp->exp_obd;
120 struct obd_device *disk_obd;
121 struct llog_handle *loghandle;
122 struct llogd_body *body;
123 struct lvfs_run_ctxt saved;
124 struct llog_logid *logid = NULL;
125 struct llog_ctxt *ctxt;
129 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
133 if (body->lgd_logid.lgl_oid > 0)
134 logid = &body->lgd_logid;
136 ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
140 disk_obd = ctxt->loc_exp->exp_obd;
141 push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
143 rc = llog_create(ctxt, &loghandle, logid, NULL);
147 rc = req_capsule_server_pack(&req->rq_pill);
149 GOTO(out_close, rc = -ENOMEM);
151 body = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
152 body->lgd_logid = loghandle->lgh_id;
153 rc = llog_init_handle(loghandle, LLOG_F_IS_PLAIN, NULL);
156 rc = llog_destroy(loghandle);
159 llog_free_handle(loghandle);
163 llog_close(loghandle);
165 pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
170 int llog_origin_handle_next_block(struct ptlrpc_request *req)
172 struct obd_export *exp = req->rq_export;
173 struct obd_device *obd = exp->exp_obd;
174 struct obd_device *disk_obd;
175 struct llog_handle *loghandle;
176 struct llogd_body *body;
177 struct llogd_body *repbody;
178 struct lvfs_run_ctxt saved;
179 struct llog_ctxt *ctxt;
186 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
190 OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
194 ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
196 GOTO(out_free, rc = -ENODEV);
197 disk_obd = ctxt->loc_exp->exp_obd;
198 push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
200 rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL);
204 flags = body->lgd_llh_flags;
205 rc = llog_init_handle(loghandle, flags, NULL);
209 memset(buf, 0, LLOG_CHUNK_SIZE);
210 rc = llog_next_block(loghandle, &body->lgd_saved_index,
212 &body->lgd_cur_offset, buf, LLOG_CHUNK_SIZE);
216 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_SERVER,
218 rc = req_capsule_server_pack(&req->rq_pill);
220 GOTO(out_close, rc = -ENOMEM);
222 repbody = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
225 ptr = req_capsule_server_get(&req->rq_pill, &RMF_EADATA);
226 memcpy(ptr, buf, LLOG_CHUNK_SIZE);
229 rc2 = llog_close(loghandle);
233 pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
236 OBD_FREE(buf, LLOG_CHUNK_SIZE);
240 int llog_origin_handle_prev_block(struct ptlrpc_request *req)
242 struct obd_export *exp = req->rq_export;
243 struct obd_device *obd = exp->exp_obd;
244 struct llog_handle *loghandle;
245 struct llogd_body *body;
246 struct llogd_body *repbody;
247 struct obd_device *disk_obd;
248 struct lvfs_run_ctxt saved;
249 struct llog_ctxt *ctxt;
256 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
260 OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
264 ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
266 GOTO(out_free, rc = -ENODEV);
268 disk_obd = ctxt->loc_exp->exp_obd;
269 push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
271 rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL);
275 flags = body->lgd_llh_flags;
276 rc = llog_init_handle(loghandle, flags, NULL);
280 memset(buf, 0, LLOG_CHUNK_SIZE);
281 rc = llog_prev_block(loghandle, body->lgd_index,
282 buf, LLOG_CHUNK_SIZE);
286 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_SERVER,
288 rc = req_capsule_server_pack(&req->rq_pill);
290 GOTO(out_close, rc = -ENOMEM);
292 repbody = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
295 ptr = req_capsule_server_get(&req->rq_pill, &RMF_EADATA);
296 memcpy(ptr, buf, LLOG_CHUNK_SIZE);
299 rc2 = llog_close(loghandle);
304 pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
307 OBD_FREE(buf, LLOG_CHUNK_SIZE);
311 int llog_origin_handle_read_header(struct ptlrpc_request *req)
313 struct obd_export *exp = req->rq_export;
314 struct obd_device *obd = exp->exp_obd;
315 struct obd_device *disk_obd;
316 struct llog_handle *loghandle;
317 struct llogd_body *body;
318 struct llog_log_hdr *hdr;
319 struct lvfs_run_ctxt saved;
320 struct llog_ctxt *ctxt;
325 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
329 ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
333 disk_obd = ctxt->loc_exp->exp_obd;
334 push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
336 rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL);
341 * llog_init_handle() reads the llog header
343 flags = body->lgd_llh_flags;
344 rc = llog_init_handle(loghandle, flags, NULL);
348 rc = req_capsule_server_pack(&req->rq_pill);
350 GOTO(out_close, rc = -ENOMEM);
352 hdr = req_capsule_server_get(&req->rq_pill, &RMF_LLOG_LOG_HDR);
353 *hdr = *loghandle->lgh_hdr;
356 rc2 = llog_close(loghandle);
360 pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
365 int llog_origin_handle_close(struct ptlrpc_request *req)
372 int llog_origin_handle_cancel(struct ptlrpc_request *req)
374 struct obd_device *obd = req->rq_export->exp_obd;
375 int num_cookies, rc = 0, err, i, failed = 0;
376 struct obd_device *disk_obd;
377 struct llog_cookie *logcookies;
378 struct llog_ctxt *ctxt = NULL;
379 struct lvfs_run_ctxt saved;
380 struct llog_handle *cathandle;
385 logcookies = req_capsule_client_get(&req->rq_pill, &RMF_LOGCOOKIES);
386 num_cookies = req_capsule_get_size(&req->rq_pill, &RMF_LOGCOOKIES,
387 RCL_CLIENT) / sizeof(*logcookies);
388 if (logcookies == NULL || num_cookies == 0) {
389 DEBUG_REQ(D_HA, req, "No llog cookies sent");
393 ctxt = llog_get_context(obd, logcookies->lgc_subsys);
397 disk_obd = ctxt->loc_exp->exp_obd;
398 push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
399 for (i = 0; i < num_cookies; i++, logcookies++) {
400 cathandle = ctxt->loc_handle;
401 LASSERT(cathandle != NULL);
402 inode = cathandle->lgh_file->f_dentry->d_inode;
404 handle = fsfilt_start_log(disk_obd, inode,
405 FSFILT_OP_CANCEL_UNLINK, NULL, 1);
406 if (IS_ERR(handle)) {
407 CERROR("fsfilt_start_log() failed: %ld\n",
409 GOTO(pop_ctxt, rc = PTR_ERR(handle));
412 rc = llog_cat_cancel_records(cathandle, 1, logcookies);
415 * Do not raise -ENOENT errors for resent rpcs. This rec already
419 (lustre_msg_get_flags(req->rq_reqmsg) & MSG_RESENT)) {
421 * Do not change this message, reply-single.sh test_59b
422 * expects to find this in log.
424 CDEBUG(D_RPCTRACE, "RESENT cancel req %p - ignored\n",
427 } else if (rc == 0) {
428 CDEBUG(D_RPCTRACE, "Canceled %d llog-records\n",
432 err = fsfilt_commit(disk_obd, inode, handle, 0);
434 CERROR("Error committing transaction: %d\n", err);
444 pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
446 CERROR("Cancel %d of %d llog-records failed: %d\n",
447 failed, num_cookies, rc);
452 EXPORT_SYMBOL(llog_origin_handle_cancel);
454 #else /* !__KERNEL__ */
455 int llog_origin_handle_create(struct ptlrpc_request *req)
461 int llog_origin_handle_destroy(struct ptlrpc_request *req)
467 int llog_origin_handle_next_block(struct ptlrpc_request *req)
472 int llog_origin_handle_prev_block(struct ptlrpc_request *req)
477 int llog_origin_handle_read_header(struct ptlrpc_request *req)
482 int llog_origin_handle_close(struct ptlrpc_request *req)
487 int llog_origin_handle_cancel(struct ptlrpc_request *req)