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.
31 * This file is part of Lustre, http://www.lustre.org/
32 * Lustre is a trademark of Sun Microsystems, Inc.
34 * lustre/ptlrpc/llog_net.c
36 * OST<->MDS recovery logging infrastructure.
38 * Invariants in implementation:
39 * - we do not share logs among different OST<->MDS connections, so that
40 * if an OST or MDS fails it need only look at log(s) relevant to itself
42 * Author: Andreas Dilger <adilger@clusterfs.com>
45 #define DEBUG_SUBSYSTEM S_LOG
48 #include <libcfs/libcfs.h>
50 #include <liblustre.h>
53 #include <obd_class.h>
54 #include <lustre_log.h>
55 #include <libcfs/list.h>
57 #include <lustre_fsfilt.h>
60 int llog_origin_connect(struct llog_ctxt *ctxt,
61 struct llog_logid *logid, struct llog_gen *gen,
62 struct obd_uuid *uuid)
64 struct llog_gen_rec *lgr;
65 struct ptlrpc_request *req;
66 struct llogd_conn_body *req_body;
67 struct inode* inode = ctxt->loc_handle->lgh_file->f_dentry->d_inode;
73 if (cfs_list_empty(&ctxt->loc_handle->u.chd.chd_head)) {
74 CDEBUG(D_HA, "there is no record related to ctxt %p\n", ctxt);
78 /* FIXME what value for gen->conn_cnt */
81 /* first add llog_gen_rec */
85 lgr->lgr_hdr.lrh_len = lgr->lgr_tail.lrt_len = sizeof(*lgr);
86 lgr->lgr_hdr.lrh_type = LLOG_GEN_REC;
88 handle = fsfilt_start_log(ctxt->loc_exp->exp_obd, inode,
89 FSFILT_OP_CANCEL_UNLINK, NULL, 1);
91 CERROR("fsfilt_start failed: %ld\n", PTR_ERR(handle));
92 OBD_FREE(lgr, sizeof(*lgr));
97 lgr->lgr_gen = ctxt->loc_gen;
98 rc = llog_obd_add(NULL, ctxt, &lgr->lgr_hdr, NULL, NULL, 1);
100 rc1 = fsfilt_commit(ctxt->loc_exp->exp_obd, inode, handle, 0);
101 if (rc != 1 || rc1 != 0) {
102 rc = (rc != 1) ? rc : rc1;
106 LASSERT(ctxt->loc_imp);
107 req = ptlrpc_request_alloc_pack(ctxt->loc_imp, &RQF_LLOG_ORIGIN_CONNECT,
109 LLOG_ORIGIN_CONNECT);
113 CDEBUG(D_OTHER, "%s mount_count "LPU64", connection count "LPU64"\n",
114 ctxt->loc_exp->exp_obd->obd_type->typ_name,
115 ctxt->loc_gen.mnt_cnt, ctxt->loc_gen.conn_cnt);
117 req_body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
118 req_body->lgdc_gen = ctxt->loc_gen;
119 req_body->lgdc_logid = ctxt->loc_handle->lgh_id;
120 req_body->lgdc_ctxt_idx = ctxt->loc_idx + 1;
121 ptlrpc_request_set_replen(req);
123 req->rq_no_resend = req->rq_no_delay = 1;
124 rc = ptlrpc_queue_wait(req);
125 ptlrpc_req_finished(req);
129 EXPORT_SYMBOL(llog_origin_connect);
131 int llog_handle_connect(struct ptlrpc_request *req)
133 struct obd_device *obd = req->rq_export->exp_obd;
134 struct llogd_conn_body *req_body;
135 struct llog_ctxt *ctxt;
139 req_body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
141 ctxt = llog_get_context(obd, req_body->lgdc_ctxt_idx);
142 rc = llog_connect(ctxt, &req_body->lgdc_logid,
143 &req_body->lgdc_gen, NULL);
147 CERROR("failed at llog_relp_connect\n");
151 EXPORT_SYMBOL(llog_handle_connect);
153 int llog_receptor_accept(struct llog_ctxt *ctxt, struct obd_import *imp)
158 mutex_lock(&ctxt->loc_mutex);
159 if (ctxt->loc_imp != imp) {
161 CWARN("changing the import %p - %p\n",
163 class_import_put(ctxt->loc_imp);
165 ctxt->loc_imp = class_import_get(imp);
167 mutex_unlock(&ctxt->loc_mutex);
170 EXPORT_SYMBOL(llog_receptor_accept);
172 #else /* !__KERNEL__ */
174 int llog_origin_connect(struct llog_ctxt *ctxt,
175 struct llog_logid *logid, struct llog_gen *gen,
176 struct obd_uuid *uuid)
182 int llog_initiator_connect(struct llog_ctxt *ctxt)
184 struct obd_import *new_imp;
188 new_imp = ctxt->loc_obd->u.cli.cl_import;
189 LASSERTF(ctxt->loc_imp == NULL || ctxt->loc_imp == new_imp,
190 "%p - %p\n", ctxt->loc_imp, new_imp);
191 mutex_lock(&ctxt->loc_mutex);
192 if (ctxt->loc_imp != new_imp) {
194 class_import_put(ctxt->loc_imp);
195 ctxt->loc_imp = class_import_get(new_imp);
197 mutex_unlock(&ctxt->loc_mutex);
200 EXPORT_SYMBOL(llog_initiator_connect);