Whamcloud - gitweb
492f39085b85d79bda908e3d581b2f88d5fae8ff
[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  *  Copyright (C) 2001-2003 Cluster File Systems, Inc.
5  *   Author: Andreas Dilger <adilger@clusterfs.com>
6  *
7  *   This file is part of the Lustre file system, http://www.lustre.org
8  *   Lustre is a trademark of Cluster File Systems, Inc.
9  *
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.
14  *
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.
19  *
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.
24  *
25  * OST<->MDS recovery logging infrastructure.
26  *
27  * Invariants in implementation:
28  * - we do not share logs among different OST<->MDS connections, so that
29  *   if an OST or MDS fails it need only look at log(s) relevant to itself
30  */
31
32 #define DEBUG_SUBSYSTEM S_LOG
33
34 #ifndef EXPORT_SYMTAB
35 #define EXPORT_SYMTAB
36 #endif
37
38 #ifdef __KERNEL__
39 #include <libcfs/libcfs.h>
40 #else
41 #include <liblustre.h>
42 #endif
43
44 #include <obd_class.h>
45 #include <lustre_log.h>
46 #include <libcfs/list.h>
47 #include <lvfs.h>
48
49 #ifdef __KERNEL__
50 int llog_origin_connect(struct llog_ctxt *ctxt, int count,
51                         struct llog_logid *logid, struct llog_gen *gen,
52                         struct obd_uuid *uuid)
53 {
54         struct llog_gen_rec    *lgr;
55         struct ptlrpc_request  *req;
56         struct llogd_conn_body *req_body;
57         int                     rc;
58         ENTRY;
59
60         if (list_empty(&ctxt->loc_handle->u.chd.chd_head)) {
61                 CDEBUG(D_HA, "there is no record related to ctxt %p\n", ctxt);
62                 RETURN(0);
63         }
64
65         /* FIXME what value for gen->conn_cnt */
66         LLOG_GEN_INC(ctxt->loc_gen);
67
68         /* first add llog_gen_rec */
69         OBD_ALLOC_PTR(lgr);
70         if (!lgr)
71                 RETURN(-ENOMEM);
72         lgr->lgr_hdr.lrh_len = lgr->lgr_tail.lrt_len = sizeof(*lgr);
73         lgr->lgr_hdr.lrh_type = LLOG_GEN_REC;
74         lgr->lgr_gen = ctxt->loc_gen;
75         rc = llog_add(ctxt, &lgr->lgr_hdr, NULL, NULL, 1);
76         OBD_FREE_PTR(lgr);
77         if (rc != 1)
78                 RETURN(rc);
79
80         LASSERT(ctxt->loc_imp);
81         req = ptlrpc_request_alloc_pack(ctxt->loc_imp, &RQF_LLOG_ORIGIN_CONNECT,
82                                         LUSTRE_LOG_VERSION,
83                                         LLOG_ORIGIN_CONNECT);
84         if (req == NULL)
85                 RETURN(-ENOMEM);
86
87         req_body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
88         req_body->lgdc_gen = ctxt->loc_gen;
89         req_body->lgdc_logid = ctxt->loc_handle->lgh_id;
90         req_body->lgdc_ctxt_idx = ctxt->loc_idx + 1;
91         ptlrpc_request_set_replen(req);
92
93         rc = ptlrpc_queue_wait(req);
94         ptlrpc_req_finished(req);
95
96         RETURN(rc);
97 }
98 EXPORT_SYMBOL(llog_origin_connect);
99
100 int llog_handle_connect(struct ptlrpc_request *req)
101 {
102         struct obd_device *obd = req->rq_export->exp_obd;
103         struct llogd_conn_body *req_body;
104         struct llog_ctxt *ctxt;
105         int rc;
106         ENTRY;
107
108         req_body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
109
110         ctxt = llog_get_context(obd, req_body->lgdc_ctxt_idx);
111         rc = llog_connect(ctxt, 1, &req_body->lgdc_logid,
112                           &req_body->lgdc_gen, NULL);
113         if (rc != 0)
114                 CERROR("failed at llog_relp_connect\n");
115
116         RETURN(rc);
117 }
118 EXPORT_SYMBOL(llog_handle_connect);
119
120 int llog_receptor_accept(struct llog_ctxt *ctxt, struct obd_import *imp)
121 {
122         ENTRY;
123         LASSERT(ctxt);
124         ctxt->loc_imp = imp;
125         RETURN(0);
126 }
127 EXPORT_SYMBOL(llog_receptor_accept);
128
129 int llog_initiator_connect(struct llog_ctxt *ctxt)
130 {
131         ENTRY;
132         LASSERT(ctxt);
133         ctxt->loc_imp = ctxt->loc_obd->u.cli.cl_import;
134         RETURN(0);
135 }
136 EXPORT_SYMBOL(llog_initiator_connect);
137
138 #else /* !__KERNEL__ */
139
140 int llog_origin_connect(struct llog_ctxt *ctxt, int count,
141                         struct llog_logid *logid, struct llog_gen *gen,
142                         struct obd_uuid *uuid)
143 {
144         return 0;
145 }
146
147 int llog_initiator_connect(struct llog_ctxt *ctxt)
148 {
149         return 0;
150 }
151 #endif