1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 Cluster File Systems, Inc.
5 * Author: Andreas Dilger <adilger@clusterfs.com>
7 * This file is part of Lustre, http://www.lustre.org.
9 * Lustre is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * Lustre is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Lustre; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * remote api for llog - server side
26 #define DEBUG_SUBSYSTEM S_LOG
33 #include <linux/obd_class.h>
34 #include <linux/lustre_log.h>
35 #include <linux/lustre_net.h>
36 #include <portals/list.h>
38 int llog_origin_handle_create(struct ptlrpc_request *req)
40 struct obd_export *exp = req->rq_export;
41 struct obd_device *obd = exp->exp_obd;
42 struct obd_device *disk_obd;
43 struct llog_handle *loghandle;
44 struct llogd_body *body;
45 struct obd_run_ctxt saved;
46 struct llog_logid *logid = NULL;
47 struct llog_ctxt *ctxt;
49 int size = sizeof (*body);
53 body = lustre_swab_reqbuf(req, 0, sizeof(*body),
54 lustre_swab_llogd_body);
56 CERROR ("Can't unpack llogd_body\n");
57 GOTO(out, rc =-EFAULT);
60 if (body->lgd_logid.lgl_oid > 0)
61 logid = &body->lgd_logid;
63 if (req->rq_reqmsg->bufcount > 1) {
64 name = lustre_msg_string(req->rq_reqmsg, 1, 0);
66 CERROR("Can't unpack name\n");
67 GOTO(out, rc = -EFAULT);
71 ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
72 LASSERT(ctxt != NULL);
73 disk_obd = ctxt->loc_exp->exp_obd;
74 push_ctxt(&saved, &disk_obd->obd_ctxt, NULL);
76 rc = llog_create(ctxt, &loghandle, logid, name);
80 rc = lustre_pack_reply(req, 1, &size, NULL);
82 GOTO(out_close, rc = -ENOMEM);
84 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*body));
85 body->lgd_logid = loghandle->lgh_id;
88 rc2 = llog_close(loghandle);
92 pop_ctxt(&saved, &disk_obd->obd_ctxt, NULL);
97 int llog_origin_handle_next_block(struct ptlrpc_request *req)
99 struct obd_export *exp = req->rq_export;
100 struct obd_device *obd = exp->exp_obd;
101 struct obd_device *disk_obd;
102 struct llog_handle *loghandle;
103 struct llogd_body *body;
104 struct obd_run_ctxt saved;
105 struct llog_ctxt *ctxt;
109 int size[] = {sizeof (*body),
114 body = lustre_swab_reqbuf(req, 0, sizeof(*body),
115 lustre_swab_llogd_body);
117 CERROR ("Can't unpack llogd_body\n");
118 GOTO(out, rc =-EFAULT);
121 OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
123 GOTO(out, rc = -ENOMEM);
125 ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
126 LASSERT(ctxt != NULL);
127 disk_obd = ctxt->loc_exp->exp_obd;
128 push_ctxt(&saved, &disk_obd->obd_ctxt, NULL);
130 rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL);
134 flags = body->lgd_llh_flags;
135 rc = llog_init_handle(loghandle, flags, NULL);
139 memset(buf, 0, LLOG_CHUNK_SIZE);
140 rc = llog_next_block(loghandle, &body->lgd_saved_index,
142 &body->lgd_cur_offset, buf, LLOG_CHUNK_SIZE);
147 rc = lustre_pack_reply(req, 2, size, NULL);
149 GOTO(out_close, rc = -ENOMEM);
151 ptr = lustre_msg_buf(req->rq_repmsg, 0, sizeof (body));
152 memcpy(ptr, body, sizeof(*body));
154 ptr = lustre_msg_buf(req->rq_repmsg, 1, LLOG_CHUNK_SIZE);
155 memcpy(ptr, buf, LLOG_CHUNK_SIZE);
158 rc2 = llog_close(loghandle);
163 pop_ctxt(&saved, &disk_obd->obd_ctxt, NULL);
164 OBD_FREE(buf, LLOG_CHUNK_SIZE);
169 int llog_origin_handle_read_header(struct ptlrpc_request *req)
171 struct obd_export *exp = req->rq_export;
172 struct obd_device *obd = exp->exp_obd;
173 struct obd_device *disk_obd;
174 struct llog_handle *loghandle;
175 struct llogd_body *body;
176 struct llog_log_hdr *hdr;
177 struct obd_run_ctxt saved;
178 struct llog_ctxt *ctxt;
181 int size[] = {sizeof (*hdr)};
185 body = lustre_swab_reqbuf(req, 0, sizeof(*body),
186 lustre_swab_llogd_body);
188 CERROR ("Can't unpack llogd_body\n");
189 GOTO(out, rc =-EFAULT);
192 OBD_ALLOC(buf, LLOG_CHUNK_SIZE);
194 GOTO(out, rc = -ENOMEM);
196 ctxt = llog_get_context(obd, body->lgd_ctxt_idx);
197 LASSERT(ctxt != NULL);
198 disk_obd = ctxt->loc_exp->exp_obd;
199 push_ctxt(&saved, &disk_obd->obd_ctxt, NULL);
201 rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL);
205 /* init_handle reads the header */
206 flags = body->lgd_llh_flags;
207 rc = llog_init_handle(loghandle, flags, NULL);
212 rc = lustre_pack_reply(req, 1, size, NULL);
214 GOTO(out_close, rc = -ENOMEM);
216 hdr = lustre_msg_buf(req->rq_repmsg, 0, sizeof (*hdr));
217 memcpy(hdr, loghandle->lgh_hdr, sizeof(*hdr));
220 rc2 = llog_close(loghandle);
225 pop_ctxt(&saved, &disk_obd->obd_ctxt, NULL);
226 OBD_FREE(buf, LLOG_CHUNK_SIZE);
232 int llog_origin_handle_close(struct ptlrpc_request *req)
241 #ifdef ENABLE_ORPHANS
242 int llog_origin_handle_cancel(struct ptlrpc_request *req)
244 struct obd_device *obd = req->rq_export->exp_obd;
245 struct obd_device *disk_obd;
246 struct llog_cookie *logcookies;
247 struct llog_ctxt *ctxt;
248 int num_cookies, rc = 0;
249 struct obd_run_ctxt saved;
250 struct llog_handle *cathandle;
253 logcookies = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*logcookies));
254 num_cookies = req->rq_reqmsg->buflens[0]/sizeof(*logcookies);
255 if (logcookies == NULL || num_cookies == 0) {
256 DEBUG_REQ(D_HA, req, "no cookies sent");
260 ctxt = llog_get_context(obd, logcookies->lgc_subsys);
262 CWARN("llog subsys not setup or already cleanup\n");
265 down(&ctxt->loc_sem);
266 disk_obd = ctxt->loc_exp->exp_obd;
267 cathandle = ctxt->loc_handle;
270 push_ctxt(&saved, &disk_obd->obd_ctxt, NULL);
271 rc = llog_cat_cancel_records(cathandle, num_cookies, logcookies);
273 CERROR("cancel %d llog-records failed: %d\n", num_cookies, rc);
275 CWARN("cancel %d llog-records\n", num_cookies);
277 pop_ctxt(&saved, &disk_obd->obd_ctxt, NULL);
282 EXPORT_SYMBOL(llog_origin_handle_cancel);