Whamcloud - gitweb
b=16098
[fs/lustre-release.git] / lustre / ptlrpc / llog_net.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see [sun.com URL with a
20  * copy of GPLv2].
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright  2008 Sun Microsystems, Inc. All rights reserved
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/ptlrpc/llog_net.c
37  *
38  * OST<->MDS recovery logging infrastructure.
39  *
40  * Invariants in implementation:
41  * - we do not share logs among different OST<->MDS connections, so that
42  *   if an OST or MDS fails it need only look at log(s) relevant to itself
43  *
44  * Author: Andreas Dilger <adilger@clusterfs.com>
45  */
46
47 #define DEBUG_SUBSYSTEM S_LOG
48
49 #ifndef EXPORT_SYMTAB
50 #define EXPORT_SYMTAB
51 #endif
52
53 #ifdef __KERNEL__
54 #include <libcfs/libcfs.h>
55 #else
56 #include <liblustre.h>
57 #endif
58
59 #include <obd_class.h>
60 #include <lustre_log.h>
61 #include <libcfs/list.h>
62 #include <lvfs.h>
63
64 #ifdef __KERNEL__
65 int llog_origin_connect(struct llog_ctxt *ctxt, int count,
66                         struct llog_logid *logid, struct llog_gen *gen,
67                         struct obd_uuid *uuid)
68 {
69         struct llog_gen_rec    *lgr;
70         struct ptlrpc_request  *req;
71         struct llogd_conn_body *req_body;
72         int                     rc;
73         ENTRY;
74
75         if (list_empty(&ctxt->loc_handle->u.chd.chd_head)) {
76                 CDEBUG(D_HA, "there is no record related to ctxt %p\n", ctxt);
77                 RETURN(0);
78         }
79
80         /* FIXME what value for gen->conn_cnt */
81         LLOG_GEN_INC(ctxt->loc_gen);
82
83         /* first add llog_gen_rec */
84         OBD_ALLOC_PTR(lgr);
85         if (!lgr)
86                 RETURN(-ENOMEM);
87         lgr->lgr_hdr.lrh_len = lgr->lgr_tail.lrt_len = sizeof(*lgr);
88         lgr->lgr_hdr.lrh_type = LLOG_GEN_REC;
89         lgr->lgr_gen = ctxt->loc_gen;
90         rc = llog_add(ctxt, &lgr->lgr_hdr, NULL, NULL, 1);
91         OBD_FREE_PTR(lgr);
92         if (rc != 1)
93                 RETURN(rc);
94
95         LASSERT(ctxt->loc_imp);
96         req = ptlrpc_request_alloc_pack(ctxt->loc_imp, &RQF_LLOG_ORIGIN_CONNECT,
97                                         LUSTRE_LOG_VERSION,
98                                         LLOG_ORIGIN_CONNECT);
99         if (req == NULL)
100                 RETURN(-ENOMEM);
101
102         req_body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
103         req_body->lgdc_gen = ctxt->loc_gen;
104         req_body->lgdc_logid = ctxt->loc_handle->lgh_id;
105         req_body->lgdc_ctxt_idx = ctxt->loc_idx + 1;
106         ptlrpc_request_set_replen(req);
107
108         rc = ptlrpc_queue_wait(req);
109         ptlrpc_req_finished(req);
110
111         RETURN(rc);
112 }
113 EXPORT_SYMBOL(llog_origin_connect);
114
115 int llog_handle_connect(struct ptlrpc_request *req)
116 {
117         struct obd_device *obd = req->rq_export->exp_obd;
118         struct llogd_conn_body *req_body;
119         struct llog_ctxt *ctxt;
120         int rc;
121         ENTRY;
122
123         req_body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
124
125         ctxt = llog_get_context(obd, req_body->lgdc_ctxt_idx);
126         rc = llog_connect(ctxt, 1, &req_body->lgdc_logid,
127                           &req_body->lgdc_gen, NULL);
128
129         llog_ctxt_put(ctxt);
130         if (rc != 0)
131                 CERROR("failed at llog_relp_connect\n");
132
133         RETURN(rc);
134 }
135 EXPORT_SYMBOL(llog_handle_connect);
136
137 int llog_receptor_accept(struct llog_ctxt *ctxt, struct obd_import *imp)
138 {
139         ENTRY;
140
141         LASSERT(ctxt);
142         mutex_down(&ctxt->loc_sem);
143         if (ctxt->loc_imp != imp) {
144                 CWARN("changing the import %p - %p\n", ctxt->loc_imp, imp);
145                 if (ctxt->loc_imp)
146                         class_import_put(ctxt->loc_imp);
147                 ctxt->loc_imp = class_import_get(imp);
148         }
149         mutex_up(&ctxt->loc_sem);
150         RETURN(0);
151 }
152 EXPORT_SYMBOL(llog_receptor_accept);
153
154 #else /* !__KERNEL__ */
155
156 int llog_origin_connect(struct llog_ctxt *ctxt, int count,
157                         struct llog_logid *logid, struct llog_gen *gen,
158                         struct obd_uuid *uuid)
159 {
160         return 0;
161 }
162 #endif
163
164 int llog_initiator_connect(struct llog_ctxt *ctxt)
165 {
166         struct obd_import *new_imp;
167         ENTRY;
168
169         LASSERT(ctxt);
170         new_imp = ctxt->loc_obd->u.cli.cl_import;
171         LASSERTF(ctxt->loc_imp == NULL || ctxt->loc_imp == new_imp,
172                  "%p - %p\n", ctxt->loc_imp, new_imp);
173         mutex_down(&ctxt->loc_sem);
174         if (ctxt->loc_imp != new_imp) {
175                 if (ctxt->loc_imp)
176                         class_import_put(ctxt->loc_imp);
177                 ctxt->loc_imp = class_import_get(new_imp);
178         }
179         mutex_up(&ctxt->loc_sem);
180         RETURN(0);
181 }
182 EXPORT_SYMBOL(llog_initiator_connect);