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, 2013, 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
46 #include <liblustre.h>
49 #include <obd_class.h>
50 #include <lu_target.h>
51 #include <lustre_log.h>
52 #include <lustre_net.h>
54 #if defined(__KERNEL__) && defined(LUSTRE_LOG_SERVER)
55 static int llog_origin_close(const struct lu_env *env, struct llog_handle *lgh)
57 if (lgh->lgh_hdr != NULL && lgh->lgh_hdr->llh_flags & LLOG_F_IS_CAT)
58 return llog_cat_close(env, lgh);
60 return llog_close(env, lgh);
63 /* Only open is supported, no new llog can be created remotely */
64 int llog_origin_handle_open(struct ptlrpc_request *req)
66 struct obd_export *exp = req->rq_export;
67 struct obd_device *obd = exp->exp_obd;
68 struct llog_handle *loghandle;
69 struct llogd_body *body;
70 struct llog_logid *logid = NULL;
71 struct llog_ctxt *ctxt;
77 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
79 RETURN(err_serious(-EFAULT));
81 rc = req_capsule_server_pack(&req->rq_pill);
83 RETURN(err_serious(-ENOMEM));
85 if (ostid_id(&body->lgd_logid.lgl_oi) > 0)
86 logid = &body->lgd_logid;
88 if (req_capsule_field_present(&req->rq_pill, &RMF_NAME, RCL_CLIENT)) {
89 name = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
92 CDEBUG(D_INFO, "%s: opening log %s\n", obd->obd_name, name);
95 ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
97 CDEBUG(D_WARNING, "%s: no ctxt. group=%p idx=%d name=%s\n",
98 obd->obd_name, &obd->obd_olg, body->lgd_ctxt_idx, name);
102 rc = llog_open(req->rq_svc_thread->t_env, ctxt, &loghandle, logid,
103 name, LLOG_OPEN_EXISTS);
107 body = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
108 body->lgd_logid = loghandle->lgh_id;
110 llog_origin_close(req->rq_svc_thread->t_env, loghandle);
116 EXPORT_SYMBOL(llog_origin_handle_open);
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 ctxt = llog_get_context(req->rq_export->exp_obd, body->lgd_ctxt_idx);
146 rc = llog_erase(req->rq_svc_thread->t_env, ctxt, logid, NULL);
150 EXPORT_SYMBOL(llog_origin_handle_destroy);
152 int llog_origin_handle_next_block(struct ptlrpc_request *req)
154 struct llog_handle *loghandle;
155 struct llogd_body *body;
156 struct llogd_body *repbody;
157 struct llog_ctxt *ctxt;
164 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
166 RETURN(err_serious(-EFAULT));
168 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_SERVER,
170 rc = req_capsule_server_pack(&req->rq_pill);
172 RETURN(err_serious(-ENOMEM));
174 ctxt = llog_get_context(req->rq_export->exp_obd, body->lgd_ctxt_idx);
178 rc = llog_open(req->rq_svc_thread->t_env, ctxt, &loghandle,
179 &body->lgd_logid, NULL, LLOG_OPEN_EXISTS);
183 flags = body->lgd_llh_flags;
184 rc = llog_init_handle(req->rq_svc_thread->t_env, loghandle, flags,
189 repbody = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
192 ptr = req_capsule_server_get(&req->rq_pill, &RMF_EADATA);
193 rc = llog_next_block(req->rq_svc_thread->t_env, loghandle,
194 &repbody->lgd_saved_index, repbody->lgd_index,
195 &repbody->lgd_cur_offset, ptr, LLOG_CHUNK_SIZE);
200 llog_origin_close(req->rq_svc_thread->t_env, loghandle);
205 EXPORT_SYMBOL(llog_origin_handle_next_block);
207 int llog_origin_handle_prev_block(struct ptlrpc_request *req)
209 struct llog_handle *loghandle;
210 struct llogd_body *body;
211 struct llogd_body *repbody;
212 struct llog_ctxt *ctxt;
219 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
221 RETURN(err_serious(-EFAULT));
223 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_SERVER,
225 rc = req_capsule_server_pack(&req->rq_pill);
227 RETURN(err_serious(-ENOMEM));
229 ctxt = llog_get_context(req->rq_export->exp_obd, body->lgd_ctxt_idx);
233 rc = llog_open(req->rq_svc_thread->t_env, ctxt, &loghandle,
234 &body->lgd_logid, NULL, LLOG_OPEN_EXISTS);
238 flags = body->lgd_llh_flags;
239 rc = llog_init_handle(req->rq_svc_thread->t_env, loghandle, flags,
244 repbody = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
247 ptr = req_capsule_server_get(&req->rq_pill, &RMF_EADATA);
248 rc = llog_prev_block(req->rq_svc_thread->t_env, loghandle,
249 body->lgd_index, ptr, LLOG_CHUNK_SIZE);
255 llog_origin_close(req->rq_svc_thread->t_env, loghandle);
260 EXPORT_SYMBOL(llog_origin_handle_prev_block);
262 int llog_origin_handle_read_header(struct ptlrpc_request *req)
264 struct llog_handle *loghandle;
265 struct llogd_body *body;
266 struct llog_log_hdr *hdr;
267 struct llog_ctxt *ctxt;
273 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
275 RETURN(err_serious(-EFAULT));
277 rc = req_capsule_server_pack(&req->rq_pill);
279 RETURN(err_serious(-ENOMEM));
281 ctxt = llog_get_context(req->rq_export->exp_obd, body->lgd_ctxt_idx);
285 rc = llog_open(req->rq_svc_thread->t_env, ctxt, &loghandle,
286 &body->lgd_logid, NULL, LLOG_OPEN_EXISTS);
291 * llog_init_handle() reads the llog header
293 flags = body->lgd_llh_flags;
294 rc = llog_init_handle(req->rq_svc_thread->t_env, loghandle, flags,
298 flags = loghandle->lgh_hdr->llh_flags;
300 hdr = req_capsule_server_get(&req->rq_pill, &RMF_LLOG_LOG_HDR);
301 *hdr = *loghandle->lgh_hdr;
304 llog_origin_close(req->rq_svc_thread->t_env, loghandle);
309 EXPORT_SYMBOL(llog_origin_handle_read_header);
311 int llog_origin_handle_close(struct ptlrpc_request *req)
317 rc = req_capsule_server_pack(&req->rq_pill);
319 RETURN(err_serious(-ENOMEM));
322 EXPORT_SYMBOL(llog_origin_handle_close);
324 #else /* !__KERNEL__ */
325 int llog_origin_handle_open(struct ptlrpc_request *req)
331 int llog_origin_handle_destroy(struct ptlrpc_request *req)
337 int llog_origin_handle_next_block(struct ptlrpc_request *req)
342 int llog_origin_handle_prev_block(struct ptlrpc_request *req)
347 int llog_origin_handle_read_header(struct ptlrpc_request *req)
352 int llog_origin_handle_close(struct ptlrpc_request *req)