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
52 #include <libcfs/libcfs.h>
54 #include <liblustre.h>
57 #include <obd_class.h>
58 #include <lustre_log.h>
59 #include <libcfs/list.h>
61 #include <lustre_fsfilt.h>
64 int llog_origin_connect(struct llog_ctxt *ctxt,
65 struct llog_logid *logid, struct llog_gen *gen,
66 struct obd_uuid *uuid)
68 struct llog_gen_rec *lgr;
69 struct ptlrpc_request *req;
70 struct llogd_conn_body *req_body;
71 struct inode* inode = ctxt->loc_handle->lgh_file->f_dentry->d_inode;
77 if (cfs_list_empty(&ctxt->loc_handle->u.chd.chd_head)) {
78 CDEBUG(D_HA, "there is no record related to ctxt %p\n", ctxt);
82 /* FIXME what value for gen->conn_cnt */
85 /* first add llog_gen_rec */
89 lgr->lgr_hdr.lrh_len = lgr->lgr_tail.lrt_len = sizeof(*lgr);
90 lgr->lgr_hdr.lrh_type = LLOG_GEN_REC;
92 handle = fsfilt_start_log(ctxt->loc_exp->exp_obd, inode,
93 FSFILT_OP_CANCEL_UNLINK, NULL, 1);
95 CERROR("fsfilt_start failed: %ld\n", PTR_ERR(handle));
96 OBD_FREE(lgr, sizeof(*lgr));
101 lgr->lgr_gen = ctxt->loc_gen;
102 rc = llog_add(ctxt, &lgr->lgr_hdr, NULL, NULL, 1);
104 rc1 = fsfilt_commit(ctxt->loc_exp->exp_obd, inode, handle, 0);
105 if (rc != 1 || rc1 != 0) {
106 rc = (rc != 1) ? rc : rc1;
110 LASSERT(ctxt->loc_imp);
111 req = ptlrpc_request_alloc_pack(ctxt->loc_imp, &RQF_LLOG_ORIGIN_CONNECT,
113 LLOG_ORIGIN_CONNECT);
117 CDEBUG(D_OTHER, "%s mount_count "LPU64", connection count "LPU64"\n",
118 ctxt->loc_exp->exp_obd->obd_type->typ_name,
119 ctxt->loc_gen.mnt_cnt, ctxt->loc_gen.conn_cnt);
121 req_body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
122 req_body->lgdc_gen = ctxt->loc_gen;
123 req_body->lgdc_logid = ctxt->loc_handle->lgh_id;
124 req_body->lgdc_ctxt_idx = ctxt->loc_idx + 1;
125 ptlrpc_request_set_replen(req);
127 req->rq_no_resend = req->rq_no_delay = 1;
128 rc = ptlrpc_queue_wait(req);
129 ptlrpc_req_finished(req);
133 EXPORT_SYMBOL(llog_origin_connect);
135 int llog_handle_connect(struct ptlrpc_request *req)
137 struct obd_device *obd = req->rq_export->exp_obd;
138 struct llogd_conn_body *req_body;
139 struct llog_ctxt *ctxt;
143 req_body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
145 ctxt = llog_get_context(obd, req_body->lgdc_ctxt_idx);
146 rc = llog_connect(ctxt, &req_body->lgdc_logid,
147 &req_body->lgdc_gen, NULL);
151 CERROR("failed at llog_relp_connect\n");
155 EXPORT_SYMBOL(llog_handle_connect);
157 int llog_receptor_accept(struct llog_ctxt *ctxt, struct obd_import *imp)
162 cfs_mutex_lock(&ctxt->loc_mutex);
163 if (ctxt->loc_imp != imp) {
165 CWARN("changing the import %p - %p\n",
167 class_import_put(ctxt->loc_imp);
169 ctxt->loc_imp = class_import_get(imp);
171 cfs_mutex_unlock(&ctxt->loc_mutex);
174 EXPORT_SYMBOL(llog_receptor_accept);
176 #else /* !__KERNEL__ */
178 int llog_origin_connect(struct llog_ctxt *ctxt,
179 struct llog_logid *logid, struct llog_gen *gen,
180 struct obd_uuid *uuid)
186 int llog_initiator_connect(struct llog_ctxt *ctxt)
188 struct obd_import *new_imp;
192 new_imp = ctxt->loc_obd->u.cli.cl_import;
193 LASSERTF(ctxt->loc_imp == NULL || ctxt->loc_imp == new_imp,
194 "%p - %p\n", ctxt->loc_imp, new_imp);
195 cfs_mutex_lock(&ctxt->loc_mutex);
196 if (ctxt->loc_imp != new_imp) {
198 class_import_put(ctxt->loc_imp);
199 ctxt->loc_imp = class_import_get(new_imp);
201 cfs_mutex_unlock(&ctxt->loc_mutex);
204 EXPORT_SYMBOL(llog_initiator_connect);