1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2004 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 - client side
26 #define DEBUG_SUBSYSTEM S_LOG
35 #include <liblustre.h>
38 #include <linux/obd_class.h>
39 #include <linux/lustre_log.h>
40 #include <linux/lustre_net.h>
41 #include <portals/list.h>
43 /* This is a callback from the llog_* functions.
44 * Assumes caller has already pushed us into the kernel context. */
45 static int llog_client_create(struct llog_ctxt *ctxt, struct llog_handle **res,
46 struct llog_logid *logid, char *name)
48 struct obd_import *imp;
49 struct llogd_body req_body;
50 struct llogd_body *body;
51 struct llog_handle *handle;
52 struct ptlrpc_request *req = NULL;
53 int size[2] = {sizeof(req_body)};
54 char *tmp[2] = {(char*) &req_body};
56 int repsize[] = {sizeof (req_body)};
60 LASSERT(ctxt->loc_imp);
63 handle = llog_alloc_handle();
68 memset(&req_body, 0, sizeof(req_body));
70 req_body.lgd_logid = *logid;
71 req_body.lgd_ctxt_idx = ctxt->loc_idx - 1;
74 size[bufcount] = strlen(name) + 1;
79 req = ptlrpc_prep_req(imp, LLOG_ORIGIN_HANDLE_CREATE,bufcount,size,tmp);
81 GOTO(err_free, rc = -ENOMEM);
83 req->rq_replen = lustre_msg_size(1, repsize);
84 rc = ptlrpc_queue_wait(req);
88 body = lustre_swab_repbuf(req, 0, sizeof(*body),
89 lustre_swab_llogd_body);
91 CERROR ("Can't unpack llogd_body\n");
92 GOTO(err_free, rc =-EFAULT);
95 handle->lgh_id = body->lgd_logid;
96 handle->lgh_ctxt = ctxt;
100 ptlrpc_req_finished(req);
104 llog_free_handle(handle);
109 static int llog_client_next_block(struct llog_handle *loghandle,
110 int *cur_idx, int next_idx,
111 __u64 *cur_offset, void *buf, int len)
113 struct obd_import *imp = loghandle->lgh_ctxt->loc_imp;
114 struct ptlrpc_request *req = NULL;
115 struct llogd_body *body;
117 int size = sizeof(*body);
118 int repsize[2] = {sizeof (*body)};
122 req = ptlrpc_prep_req(imp, LLOG_ORIGIN_HANDLE_NEXT_BLOCK, 1,&size,NULL);
124 GOTO(out, rc = -ENOMEM);
126 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
127 body->lgd_logid = loghandle->lgh_id;
128 body->lgd_ctxt_idx = loghandle->lgh_ctxt->loc_idx - 1;
129 body->lgd_llh_flags = loghandle->lgh_hdr->llh_flags;
130 body->lgd_index = next_idx;
131 body->lgd_saved_index = *cur_idx;
133 body->lgd_cur_offset = *cur_offset;
136 req->rq_replen = lustre_msg_size(2, repsize);
137 rc = ptlrpc_queue_wait(req);
141 body = lustre_swab_repbuf(req, 0, sizeof(*body),
142 lustre_swab_llogd_body);
144 CERROR ("Can't unpack llogd_body\n");
145 GOTO(out, rc =-EFAULT);
148 ptr = lustre_msg_buf(req->rq_repmsg, 1, len);
150 CERROR ("Can't unpack bitmap\n");
151 GOTO(out, rc =-EFAULT);
154 *cur_idx = body->lgd_saved_index;
155 *cur_offset = body->lgd_cur_offset;
157 memcpy(buf, ptr, len);
161 ptlrpc_req_finished(req);
166 static int llog_client_read_header(struct llog_handle *handle)
168 struct obd_import *imp = handle->lgh_ctxt->loc_imp;
169 struct ptlrpc_request *req = NULL;
170 struct llogd_body *body;
171 struct llog_log_hdr *hdr;
172 struct llog_rec_hdr *llh_hdr;
173 int size = sizeof(*body);
174 int repsize = sizeof (*hdr);
178 req = ptlrpc_prep_req(imp, LLOG_ORIGIN_HANDLE_READ_HEADER,1,&size,NULL);
180 GOTO(out, rc = -ENOMEM);
182 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
183 body->lgd_logid = handle->lgh_id;
184 body->lgd_ctxt_idx = handle->lgh_ctxt->loc_idx - 1;
185 body->lgd_llh_flags = handle->lgh_hdr->llh_flags;
187 req->rq_replen = lustre_msg_size(1, &repsize);
188 rc = ptlrpc_queue_wait(req);
192 hdr = lustre_swab_repbuf(req, 0, sizeof(*hdr), lustre_swab_llog_hdr);
194 CERROR ("Can't unpack llog_hdr\n");
195 GOTO(out, rc =-EFAULT);
198 memcpy(handle->lgh_hdr, hdr, sizeof (*hdr));
199 handle->lgh_last_idx = handle->lgh_hdr->llh_tail.lrt_index;
202 llh_hdr = &handle->lgh_hdr->llh_hdr;
203 if (llh_hdr->lrh_type != LLOG_HDR_MAGIC) {
204 CERROR("bad log header magic: %#x (expecting %#x)\n",
205 llh_hdr->lrh_type, LLOG_HDR_MAGIC);
207 } else if (llh_hdr->lrh_len != LLOG_CHUNK_SIZE) {
208 CERROR("incorrectly sized log header: %#x "
210 llh_hdr->lrh_len, LLOG_CHUNK_SIZE);
211 CERROR("you may need to re-run lconf --write_conf.\n");
217 ptlrpc_req_finished(req);
221 static int llog_client_close(struct llog_handle *handle)
229 struct llog_operations llog_client_ops = {
230 lop_next_block: llog_client_next_block,
231 lop_read_header: llog_client_read_header,
232 lop_create: llog_client_create,
233 lop_close: llog_client_close,