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, 2014, Intel Corporation.
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
45 #include <obd_class.h>
46 #include <lu_target.h>
47 #include <lustre_log.h>
48 #include <lustre_net.h>
50 static int llog_origin_close(const struct lu_env *env, struct llog_handle *lgh)
52 if (lgh->lgh_hdr != NULL && lgh->lgh_hdr->llh_flags & LLOG_F_IS_CAT)
53 return llog_cat_close(env, lgh);
55 return llog_close(env, lgh);
58 /* Only open is supported, no new llog can be created remotely */
59 int llog_origin_handle_open(struct ptlrpc_request *req)
61 struct obd_export *exp = req->rq_export;
62 struct obd_device *obd = exp->exp_obd;
63 struct llog_handle *loghandle;
64 struct llogd_body *body;
65 struct llog_logid *logid = NULL;
66 struct llog_ctxt *ctxt;
72 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
74 RETURN(err_serious(-EFAULT));
76 rc = req_capsule_server_pack(&req->rq_pill);
78 RETURN(err_serious(-ENOMEM));
80 if (ostid_id(&body->lgd_logid.lgl_oi) > 0)
81 logid = &body->lgd_logid;
83 if (req_capsule_field_present(&req->rq_pill, &RMF_NAME, RCL_CLIENT)) {
84 name = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
87 CDEBUG(D_INFO, "%s: opening log %s\n", obd->obd_name, name);
90 if (body->lgd_ctxt_idx >= LLOG_MAX_CTXTS) {
91 CDEBUG(D_WARNING, "%s: bad ctxt ID: idx=%d name=%s\n",
92 obd->obd_name, body->lgd_ctxt_idx, name);
96 ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
98 CDEBUG(D_WARNING, "%s: no ctxt. group=%p idx=%d name=%s\n",
99 obd->obd_name, &obd->obd_olg, body->lgd_ctxt_idx, name);
103 rc = llog_open(req->rq_svc_thread->t_env, ctxt, &loghandle, logid,
104 name, LLOG_OPEN_EXISTS);
108 body = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
109 body->lgd_logid = loghandle->lgh_id;
111 llog_origin_close(req->rq_svc_thread->t_env, loghandle);
118 int llog_origin_handle_destroy(struct ptlrpc_request *req)
120 struct llogd_body *body;
121 struct llog_logid *logid = NULL;
122 struct llog_ctxt *ctxt;
127 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
129 RETURN(err_serious(-EFAULT));
131 rc = req_capsule_server_pack(&req->rq_pill);
133 RETURN(err_serious(-ENOMEM));
135 if (ostid_id(&body->lgd_logid.lgl_oi) > 0)
136 logid = &body->lgd_logid;
138 if (!(body->lgd_llh_flags & LLOG_F_IS_PLAIN))
139 CERROR("%s: wrong llog flags %x\n",
140 req->rq_export->exp_obd->obd_name, body->lgd_llh_flags);
142 if (body->lgd_ctxt_idx >= LLOG_MAX_CTXTS) {
143 CDEBUG(D_WARNING, "%s: bad ctxt ID: idx=%d\n",
144 req->rq_export->exp_obd->obd_name, body->lgd_ctxt_idx);
148 ctxt = llog_get_context(req->rq_export->exp_obd, body->lgd_ctxt_idx);
152 rc = llog_erase(req->rq_svc_thread->t_env, ctxt, logid, NULL);
157 int llog_origin_handle_next_block(struct ptlrpc_request *req)
159 struct llog_handle *loghandle;
160 struct llogd_body *body;
161 struct llogd_body *repbody;
162 struct llog_ctxt *ctxt;
169 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
171 RETURN(err_serious(-EFAULT));
173 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_SERVER,
175 rc = req_capsule_server_pack(&req->rq_pill);
177 RETURN(err_serious(-ENOMEM));
179 if (body->lgd_ctxt_idx >= LLOG_MAX_CTXTS) {
180 CDEBUG(D_WARNING, "%s: bad ctxt ID: idx=%d\n",
181 req->rq_export->exp_obd->obd_name, body->lgd_ctxt_idx);
185 ctxt = llog_get_context(req->rq_export->exp_obd, body->lgd_ctxt_idx);
189 rc = llog_open(req->rq_svc_thread->t_env, ctxt, &loghandle,
190 &body->lgd_logid, NULL, LLOG_OPEN_EXISTS);
194 flags = body->lgd_llh_flags;
195 rc = llog_init_handle(req->rq_svc_thread->t_env, loghandle, flags,
200 repbody = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
203 ptr = req_capsule_server_get(&req->rq_pill, &RMF_EADATA);
204 rc = llog_next_block(req->rq_svc_thread->t_env, loghandle,
205 &repbody->lgd_saved_index, repbody->lgd_index,
206 &repbody->lgd_cur_offset, ptr, LLOG_CHUNK_SIZE);
211 llog_origin_close(req->rq_svc_thread->t_env, loghandle);
217 int llog_origin_handle_prev_block(struct ptlrpc_request *req)
219 struct llog_handle *loghandle;
220 struct llogd_body *body;
221 struct llogd_body *repbody;
222 struct llog_ctxt *ctxt;
229 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
231 RETURN(err_serious(-EFAULT));
233 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_SERVER,
235 rc = req_capsule_server_pack(&req->rq_pill);
237 RETURN(err_serious(-ENOMEM));
239 if (body->lgd_ctxt_idx >= LLOG_MAX_CTXTS) {
240 CDEBUG(D_WARNING, "%s: bad ctxt ID: idx=%d\n",
241 req->rq_export->exp_obd->obd_name, body->lgd_ctxt_idx);
245 ctxt = llog_get_context(req->rq_export->exp_obd, body->lgd_ctxt_idx);
249 rc = llog_open(req->rq_svc_thread->t_env, ctxt, &loghandle,
250 &body->lgd_logid, NULL, LLOG_OPEN_EXISTS);
254 flags = body->lgd_llh_flags;
255 rc = llog_init_handle(req->rq_svc_thread->t_env, loghandle, flags,
260 repbody = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
263 ptr = req_capsule_server_get(&req->rq_pill, &RMF_EADATA);
264 rc = llog_prev_block(req->rq_svc_thread->t_env, loghandle,
265 body->lgd_index, ptr, LLOG_CHUNK_SIZE);
271 llog_origin_close(req->rq_svc_thread->t_env, loghandle);
277 int llog_origin_handle_read_header(struct ptlrpc_request *req)
279 struct llog_handle *loghandle;
280 struct llogd_body *body;
281 struct llog_log_hdr *hdr;
282 struct llog_ctxt *ctxt;
288 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
290 RETURN(err_serious(-EFAULT));
292 rc = req_capsule_server_pack(&req->rq_pill);
294 RETURN(err_serious(-ENOMEM));
296 if (body->lgd_ctxt_idx >= LLOG_MAX_CTXTS) {
297 CDEBUG(D_WARNING, "%s: bad ctxt ID: idx=%d\n",
298 req->rq_export->exp_obd->obd_name, body->lgd_ctxt_idx);
302 ctxt = llog_get_context(req->rq_export->exp_obd, body->lgd_ctxt_idx);
306 rc = llog_open(req->rq_svc_thread->t_env, ctxt, &loghandle,
307 &body->lgd_logid, NULL, LLOG_OPEN_EXISTS);
312 * llog_init_handle() reads the llog header
314 flags = body->lgd_llh_flags;
315 rc = llog_init_handle(req->rq_svc_thread->t_env, loghandle, flags,
319 flags = loghandle->lgh_hdr->llh_flags;
321 hdr = req_capsule_server_get(&req->rq_pill, &RMF_LLOG_LOG_HDR);
322 *hdr = *loghandle->lgh_hdr;
325 llog_origin_close(req->rq_svc_thread->t_env, loghandle);
331 int llog_origin_handle_close(struct ptlrpc_request *req)
337 rc = req_capsule_server_pack(&req->rq_pill);
339 RETURN(err_serious(-ENOMEM));