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 the Lustre file system, http://www.lustre.org
8 * Lustre is a trademark of Cluster File Systems, Inc.
10 * You may have signed or agreed to another license before downloading
11 * this software. If so, you are bound by the terms and conditions
12 * of that agreement, and the following does not apply to you. See the
13 * LICENSE file included with this distribution for more information.
15 * If you did not agree to a different license, then this copy of Lustre
16 * is open source software; you can redistribute it and/or modify it
17 * under the terms of version 2 of the GNU General Public License as
18 * published by the Free Software Foundation.
20 * In either case, Lustre is distributed in the hope that it will be
21 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
22 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * license text for more details.
25 * remote api for llog - client side
29 #define DEBUG_SUBSYSTEM S_LOG
38 #include <liblustre.h>
41 #include <linux/obd_class.h>
42 #include <linux/lustre_log.h>
43 #include <linux/lustre_net.h>
44 #include <libcfs/list.h>
46 /* This is a callback from the llog_* functions.
47 * Assumes caller has already pushed us into the kernel context. */
48 static int llog_client_create(struct llog_ctxt *ctxt, struct llog_handle **res,
49 struct llog_logid *logid, char *name)
51 struct obd_import *imp;
52 struct llogd_body req_body;
53 struct llogd_body *body;
54 struct llog_handle *handle;
55 struct ptlrpc_request *req = NULL;
56 int size[2] = {sizeof(req_body)};
57 char *tmp[2] = {(char*) &req_body};
59 int repsize[] = {sizeof (req_body)};
63 if (ctxt->loc_imp == NULL) {
64 /* This used to be an assert; bug 6200 */
65 CERROR("ctxt->loc_imp == NULL for context idx %d. Unable to "
66 "complete MDS/OSS recovery, but I'll try again next "
67 "time. Not fatal.\n", ctxt->loc_idx);
72 handle = llog_alloc_handle();
77 memset(&req_body, 0, sizeof(req_body));
79 req_body.lgd_logid = *logid;
80 req_body.lgd_ctxt_idx = ctxt->loc_idx - 1;
83 size[bufcount] = strlen(name) + 1;
88 req = ptlrpc_prep_req(imp, LLOG_ORIGIN_HANDLE_CREATE,
91 GOTO(err_free, rc = -ENOMEM);
93 req->rq_replen = lustre_msg_size(1, repsize);
94 rc = ptlrpc_queue_wait(req);
98 body = lustre_swab_repbuf(req, 0, sizeof(*body),
99 lustre_swab_llogd_body);
101 CERROR ("Can't unpack llogd_body\n");
102 GOTO(err_free, rc =-EFAULT);
105 handle->lgh_id = body->lgd_logid;
106 handle->lgh_ctxt = ctxt;
110 ptlrpc_req_finished(req);
114 llog_free_handle(handle);
119 static int llog_client_next_block(struct llog_handle *loghandle,
120 int *cur_idx, int next_idx,
121 __u64 *cur_offset, void *buf, int len)
123 struct obd_import *imp = loghandle->lgh_ctxt->loc_imp;
124 struct ptlrpc_request *req = NULL;
125 struct llogd_body *body;
127 int size = sizeof(*body);
128 int repsize[2] = {sizeof (*body)};
132 req = ptlrpc_prep_req(imp, LLOG_ORIGIN_HANDLE_NEXT_BLOCK, 1,&size,NULL);
134 GOTO(out, rc = -ENOMEM);
136 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
137 body->lgd_logid = loghandle->lgh_id;
138 body->lgd_ctxt_idx = loghandle->lgh_ctxt->loc_idx - 1;
139 body->lgd_llh_flags = loghandle->lgh_hdr->llh_flags;
140 body->lgd_index = next_idx;
141 body->lgd_saved_index = *cur_idx;
143 body->lgd_cur_offset = *cur_offset;
146 req->rq_replen = lustre_msg_size(2, repsize);
147 rc = ptlrpc_queue_wait(req);
151 body = lustre_swab_repbuf(req, 0, sizeof(*body),
152 lustre_swab_llogd_body);
154 CERROR ("Can't unpack llogd_body\n");
155 GOTO(out, rc =-EFAULT);
158 /* The log records are swabbed as they are processed */
159 ptr = lustre_msg_buf(req->rq_repmsg, 1, len);
161 CERROR ("Can't unpack bitmap\n");
162 GOTO(out, rc =-EFAULT);
165 *cur_idx = body->lgd_saved_index;
166 *cur_offset = body->lgd_cur_offset;
168 memcpy(buf, ptr, len);
172 ptlrpc_req_finished(req);
177 static int llog_client_read_header(struct llog_handle *handle)
179 struct obd_import *imp = handle->lgh_ctxt->loc_imp;
180 struct ptlrpc_request *req = NULL;
181 struct llogd_body *body;
182 struct llog_log_hdr *hdr;
183 struct llog_rec_hdr *llh_hdr;
184 int size = sizeof(*body);
185 int repsize = sizeof (*hdr);
189 req = ptlrpc_prep_req(imp, LLOG_ORIGIN_HANDLE_READ_HEADER,
192 GOTO(out, rc = -ENOMEM);
194 body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
195 body->lgd_logid = handle->lgh_id;
196 body->lgd_ctxt_idx = handle->lgh_ctxt->loc_idx - 1;
197 body->lgd_llh_flags = handle->lgh_hdr->llh_flags;
199 req->rq_replen = lustre_msg_size(1, &repsize);
200 rc = ptlrpc_queue_wait(req);
204 hdr = lustre_swab_repbuf(req, 0, sizeof(*hdr), lustre_swab_llog_hdr);
206 CERROR ("Can't unpack llog_hdr\n");
207 GOTO(out, rc =-EFAULT);
210 memcpy(handle->lgh_hdr, hdr, sizeof (*hdr));
211 handle->lgh_last_idx = handle->lgh_hdr->llh_tail.lrt_index;
214 llh_hdr = &handle->lgh_hdr->llh_hdr;
215 if (llh_hdr->lrh_type != LLOG_HDR_MAGIC) {
216 CERROR("bad log header magic: %#x (expecting %#x)\n",
217 llh_hdr->lrh_type, LLOG_HDR_MAGIC);
219 } else if (llh_hdr->lrh_len != LLOG_CHUNK_SIZE) {
220 CERROR("incorrectly sized log header: %#x "
222 llh_hdr->lrh_len, LLOG_CHUNK_SIZE);
223 CERROR("you may need to re-run lconf --write_conf.\n");
229 ptlrpc_req_finished(req);
233 static int llog_client_close(struct llog_handle *handle)
236 /* this doesn't call LLOG_ORIGIN_HANDLE_CLOSE because
237 the servers all close the file at the end of every
243 struct llog_operations llog_client_ops = {
244 lop_next_block: llog_client_next_block,
245 lop_read_header: llog_client_read_header,
246 lop_create: llog_client_create,
247 lop_close: llog_client_close,