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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2015, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lustre/ptlrpc/llog_server.c
34 * remote api for llog - server side
36 * Author: Andreas Dilger <adilger@clusterfs.com>
39 #define DEBUG_SUBSYSTEM S_LOG
41 #include <obd_class.h>
42 #include <lu_target.h>
43 #include <lustre_log.h>
44 #include <lustre_net.h>
46 static int llog_origin_close(const struct lu_env *env, struct llog_handle *lgh)
48 if (lgh->lgh_hdr != NULL && lgh->lgh_hdr->llh_flags & LLOG_F_IS_CAT)
49 return llog_cat_close(env, lgh);
51 return llog_close(env, lgh);
54 /* Only open is supported, no new llog can be created remotely */
55 int llog_origin_handle_open(struct ptlrpc_request *req)
57 struct obd_export *exp = req->rq_export;
58 struct obd_device *obd = exp->exp_obd;
59 struct llog_handle *loghandle;
60 struct llogd_body *body;
61 struct llog_logid *logid = NULL;
62 struct llog_ctxt *ctxt;
68 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
70 RETURN(err_serious(-EFAULT));
72 rc = req_capsule_server_pack(&req->rq_pill);
74 RETURN(err_serious(-ENOMEM));
76 if (ostid_id(&body->lgd_logid.lgl_oi) > 0)
77 logid = &body->lgd_logid;
79 if (req_capsule_field_present(&req->rq_pill, &RMF_NAME, RCL_CLIENT)) {
80 name = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
83 CDEBUG(D_INFO, "%s: opening log %s\n", obd->obd_name, name);
86 if (body->lgd_ctxt_idx >= LLOG_MAX_CTXTS) {
87 CDEBUG(D_WARNING, "%s: bad ctxt ID: idx=%d name=%s\n",
88 obd->obd_name, body->lgd_ctxt_idx, name);
92 ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
94 CDEBUG(D_WARNING, "%s: no ctxt. group=%p idx=%d name=%s\n",
95 obd->obd_name, &obd->obd_olg, body->lgd_ctxt_idx, name);
99 rc = llog_open(req->rq_svc_thread->t_env, ctxt, &loghandle, logid,
100 name, LLOG_OPEN_EXISTS);
104 body = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
105 body->lgd_logid = loghandle->lgh_id;
107 llog_origin_close(req->rq_svc_thread->t_env, loghandle);
114 int llog_origin_handle_next_block(struct ptlrpc_request *req)
116 struct llog_handle *loghandle;
117 struct llogd_body *body;
118 struct llogd_body *repbody;
119 struct llog_ctxt *ctxt;
126 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
128 RETURN(err_serious(-EFAULT));
130 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_SERVER,
131 LLOG_MIN_CHUNK_SIZE);
132 rc = req_capsule_server_pack(&req->rq_pill);
134 RETURN(err_serious(-ENOMEM));
136 if (body->lgd_ctxt_idx >= LLOG_MAX_CTXTS) {
137 CDEBUG(D_WARNING, "%s: bad ctxt ID: idx=%d\n",
138 req->rq_export->exp_obd->obd_name, body->lgd_ctxt_idx);
142 ctxt = llog_get_context(req->rq_export->exp_obd, body->lgd_ctxt_idx);
146 rc = llog_open(req->rq_svc_thread->t_env, ctxt, &loghandle,
147 &body->lgd_logid, NULL, LLOG_OPEN_EXISTS);
151 flags = body->lgd_llh_flags;
152 rc = llog_init_handle(req->rq_svc_thread->t_env, loghandle, flags,
157 repbody = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
160 ptr = req_capsule_server_get(&req->rq_pill, &RMF_EADATA);
161 rc = llog_next_block(req->rq_svc_thread->t_env, loghandle,
162 &repbody->lgd_saved_index, repbody->lgd_index,
163 &repbody->lgd_cur_offset, ptr,
164 LLOG_MIN_CHUNK_SIZE);
169 llog_origin_close(req->rq_svc_thread->t_env, loghandle);
175 int llog_origin_handle_prev_block(struct ptlrpc_request *req)
177 struct llog_handle *loghandle;
178 struct llogd_body *body;
179 struct llogd_body *repbody;
180 struct llog_ctxt *ctxt;
187 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
189 RETURN(err_serious(-EFAULT));
191 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_SERVER,
192 LLOG_MIN_CHUNK_SIZE);
193 rc = req_capsule_server_pack(&req->rq_pill);
195 RETURN(err_serious(-ENOMEM));
197 if (body->lgd_ctxt_idx >= LLOG_MAX_CTXTS) {
198 CDEBUG(D_WARNING, "%s: bad ctxt ID: idx=%d\n",
199 req->rq_export->exp_obd->obd_name, body->lgd_ctxt_idx);
203 ctxt = llog_get_context(req->rq_export->exp_obd, body->lgd_ctxt_idx);
207 rc = llog_open(req->rq_svc_thread->t_env, ctxt, &loghandle,
208 &body->lgd_logid, NULL, LLOG_OPEN_EXISTS);
212 flags = body->lgd_llh_flags;
213 rc = llog_init_handle(req->rq_svc_thread->t_env, loghandle, flags,
218 repbody = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
221 ptr = req_capsule_server_get(&req->rq_pill, &RMF_EADATA);
222 rc = llog_prev_block(req->rq_svc_thread->t_env, loghandle,
223 body->lgd_index, ptr, LLOG_MIN_CHUNK_SIZE);
229 llog_origin_close(req->rq_svc_thread->t_env, loghandle);
235 int llog_origin_handle_read_header(struct ptlrpc_request *req)
237 struct llog_handle *loghandle;
238 struct llogd_body *body;
239 struct llog_log_hdr *hdr;
240 struct llog_ctxt *ctxt;
246 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
248 RETURN(err_serious(-EFAULT));
250 rc = req_capsule_server_pack(&req->rq_pill);
252 RETURN(err_serious(-ENOMEM));
254 if (body->lgd_ctxt_idx >= LLOG_MAX_CTXTS) {
255 CDEBUG(D_WARNING, "%s: bad ctxt ID: idx=%d\n",
256 req->rq_export->exp_obd->obd_name, body->lgd_ctxt_idx);
260 ctxt = llog_get_context(req->rq_export->exp_obd, body->lgd_ctxt_idx);
264 rc = llog_open(req->rq_svc_thread->t_env, ctxt, &loghandle,
265 &body->lgd_logid, NULL, LLOG_OPEN_EXISTS);
270 * llog_init_handle() reads the llog header
272 flags = body->lgd_llh_flags;
273 rc = llog_init_handle(req->rq_svc_thread->t_env, loghandle, flags,
277 flags = loghandle->lgh_hdr->llh_flags;
279 hdr = req_capsule_server_get(&req->rq_pill, &RMF_LLOG_LOG_HDR);
280 *hdr = *loghandle->lgh_hdr;
283 llog_origin_close(req->rq_svc_thread->t_env, loghandle);