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 if (body->lgd_ctxt_idx >= LLOG_MAX_CTXTS) {
96 CDEBUG(D_WARNING, "%s: bad ctxt ID: idx=%d name=%s\n",
97 obd->obd_name, body->lgd_ctxt_idx, name);
101 ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
103 CDEBUG(D_WARNING, "%s: no ctxt. group=%p idx=%d name=%s\n",
104 obd->obd_name, &obd->obd_olg, body->lgd_ctxt_idx, name);
108 rc = llog_open(req->rq_svc_thread->t_env, ctxt, &loghandle, logid,
109 name, LLOG_OPEN_EXISTS);
113 body = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
114 body->lgd_logid = loghandle->lgh_id;
116 llog_origin_close(req->rq_svc_thread->t_env, loghandle);
122 EXPORT_SYMBOL(llog_origin_handle_open);
124 int llog_origin_handle_destroy(struct ptlrpc_request *req)
126 struct llogd_body *body;
127 struct llog_logid *logid = NULL;
128 struct llog_ctxt *ctxt;
133 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
135 RETURN(err_serious(-EFAULT));
137 rc = req_capsule_server_pack(&req->rq_pill);
139 RETURN(err_serious(-ENOMEM));
141 if (ostid_id(&body->lgd_logid.lgl_oi) > 0)
142 logid = &body->lgd_logid;
144 if (!(body->lgd_llh_flags & LLOG_F_IS_PLAIN))
145 CERROR("%s: wrong llog flags %x\n",
146 req->rq_export->exp_obd->obd_name, body->lgd_llh_flags);
148 if (body->lgd_ctxt_idx >= LLOG_MAX_CTXTS) {
149 CDEBUG(D_WARNING, "%s: bad ctxt ID: idx=%d\n",
150 req->rq_export->exp_obd->obd_name, body->lgd_ctxt_idx);
154 ctxt = llog_get_context(req->rq_export->exp_obd, body->lgd_ctxt_idx);
158 rc = llog_erase(req->rq_svc_thread->t_env, ctxt, logid, NULL);
162 EXPORT_SYMBOL(llog_origin_handle_destroy);
164 int llog_origin_handle_next_block(struct ptlrpc_request *req)
166 struct llog_handle *loghandle;
167 struct llogd_body *body;
168 struct llogd_body *repbody;
169 struct llog_ctxt *ctxt;
176 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
178 RETURN(err_serious(-EFAULT));
180 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_SERVER,
182 rc = req_capsule_server_pack(&req->rq_pill);
184 RETURN(err_serious(-ENOMEM));
186 if (body->lgd_ctxt_idx >= LLOG_MAX_CTXTS) {
187 CDEBUG(D_WARNING, "%s: bad ctxt ID: idx=%d\n",
188 req->rq_export->exp_obd->obd_name, body->lgd_ctxt_idx);
192 ctxt = llog_get_context(req->rq_export->exp_obd, body->lgd_ctxt_idx);
196 rc = llog_open(req->rq_svc_thread->t_env, ctxt, &loghandle,
197 &body->lgd_logid, NULL, LLOG_OPEN_EXISTS);
201 flags = body->lgd_llh_flags;
202 rc = llog_init_handle(req->rq_svc_thread->t_env, loghandle, flags,
207 repbody = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
210 ptr = req_capsule_server_get(&req->rq_pill, &RMF_EADATA);
211 rc = llog_next_block(req->rq_svc_thread->t_env, loghandle,
212 &repbody->lgd_saved_index, repbody->lgd_index,
213 &repbody->lgd_cur_offset, ptr, LLOG_CHUNK_SIZE);
218 llog_origin_close(req->rq_svc_thread->t_env, loghandle);
223 EXPORT_SYMBOL(llog_origin_handle_next_block);
225 int llog_origin_handle_prev_block(struct ptlrpc_request *req)
227 struct llog_handle *loghandle;
228 struct llogd_body *body;
229 struct llogd_body *repbody;
230 struct llog_ctxt *ctxt;
237 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
239 RETURN(err_serious(-EFAULT));
241 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_SERVER,
243 rc = req_capsule_server_pack(&req->rq_pill);
245 RETURN(err_serious(-ENOMEM));
247 if (body->lgd_ctxt_idx >= LLOG_MAX_CTXTS) {
248 CDEBUG(D_WARNING, "%s: bad ctxt ID: idx=%d\n",
249 req->rq_export->exp_obd->obd_name, body->lgd_ctxt_idx);
253 ctxt = llog_get_context(req->rq_export->exp_obd, body->lgd_ctxt_idx);
257 rc = llog_open(req->rq_svc_thread->t_env, ctxt, &loghandle,
258 &body->lgd_logid, NULL, LLOG_OPEN_EXISTS);
262 flags = body->lgd_llh_flags;
263 rc = llog_init_handle(req->rq_svc_thread->t_env, loghandle, flags,
268 repbody = req_capsule_server_get(&req->rq_pill, &RMF_LLOGD_BODY);
271 ptr = req_capsule_server_get(&req->rq_pill, &RMF_EADATA);
272 rc = llog_prev_block(req->rq_svc_thread->t_env, loghandle,
273 body->lgd_index, ptr, LLOG_CHUNK_SIZE);
279 llog_origin_close(req->rq_svc_thread->t_env, loghandle);
284 EXPORT_SYMBOL(llog_origin_handle_prev_block);
286 int llog_origin_handle_read_header(struct ptlrpc_request *req)
288 struct llog_handle *loghandle;
289 struct llogd_body *body;
290 struct llog_log_hdr *hdr;
291 struct llog_ctxt *ctxt;
297 body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_BODY);
299 RETURN(err_serious(-EFAULT));
301 rc = req_capsule_server_pack(&req->rq_pill);
303 RETURN(err_serious(-ENOMEM));
305 if (body->lgd_ctxt_idx >= LLOG_MAX_CTXTS) {
306 CDEBUG(D_WARNING, "%s: bad ctxt ID: idx=%d\n",
307 req->rq_export->exp_obd->obd_name, body->lgd_ctxt_idx);
311 ctxt = llog_get_context(req->rq_export->exp_obd, body->lgd_ctxt_idx);
315 rc = llog_open(req->rq_svc_thread->t_env, ctxt, &loghandle,
316 &body->lgd_logid, NULL, LLOG_OPEN_EXISTS);
321 * llog_init_handle() reads the llog header
323 flags = body->lgd_llh_flags;
324 rc = llog_init_handle(req->rq_svc_thread->t_env, loghandle, flags,
328 flags = loghandle->lgh_hdr->llh_flags;
330 hdr = req_capsule_server_get(&req->rq_pill, &RMF_LLOG_LOG_HDR);
331 *hdr = *loghandle->lgh_hdr;
334 llog_origin_close(req->rq_svc_thread->t_env, loghandle);
339 EXPORT_SYMBOL(llog_origin_handle_read_header);
341 int llog_origin_handle_close(struct ptlrpc_request *req)
347 rc = req_capsule_server_pack(&req->rq_pill);
349 RETURN(err_serious(-ENOMEM));
352 EXPORT_SYMBOL(llog_origin_handle_close);
354 #else /* !__KERNEL__ */
355 int llog_origin_handle_open(struct ptlrpc_request *req)
361 int llog_origin_handle_destroy(struct ptlrpc_request *req)
367 int llog_origin_handle_next_block(struct ptlrpc_request *req)
372 int llog_origin_handle_prev_block(struct ptlrpc_request *req)
377 int llog_origin_handle_read_header(struct ptlrpc_request *req)
382 int llog_origin_handle_close(struct ptlrpc_request *req)