Whamcloud - gitweb
- out of date warning has been removed
[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 Lustre, http://www.lustre.org.
8  *
9  *   Lustre is free software; you can redistribute it and/or
10  *   modify it under the terms of version 2 of the GNU General Public
11  *   License as published by the Free Software Foundation.
12  *
13  *   Lustre is distributed in the hope that it will be useful,
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *   GNU General Public License for more details.
17  *
18  *   You should have received a copy of the GNU General Public License
19  *   along with Lustre; if not, write to the Free Software
20  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  * OST<->MDS recovery logging infrastructure.
23  *
24  * Invariants in implementation:
25  * - we do not share logs among different OST<->MDS connections, so that
26  *   if an OST or MDS fails it need only look at log(s) relevant to itself
27  */
28
29 #define DEBUG_SUBSYSTEM S_LOG
30
31 #ifndef EXPORT_SYMTAB
32 #define EXPORT_SYMTAB
33 #endif
34
35 #ifdef __KERNEL__
36 #include <linux/fs.h>
37 #else
38 #include <liblustre.h>
39 #endif
40
41 #include <linux/obd_class.h>
42 #include <linux/lustre_log.h>
43 #include <libcfs/list.h>
44 #include <linux/lvfs.h>
45
46 #ifdef __KERNEL__
47 int llog_origin_connect(struct llog_ctxt *ctxt, int count,
48                         struct llog_logid *logid, struct llog_gen *gen,
49                         struct obd_uuid *uuid)
50 {
51         struct llog_gen_rec *lgr;
52         struct obd_import *imp;
53         struct ptlrpc_request *request;
54         struct llogd_conn_body *req_body;
55         int size = sizeof(struct llogd_conn_body);
56         int rc;
57         ENTRY;
58
59         if (list_empty(&ctxt->loc_handle->u.chd.chd_head)) {
60                 CDEBUG(D_HA, "there is no record related to ctxt %p\n", ctxt);
61                 RETURN(0);
62         }
63
64         /* FIXME what value for gen->conn_cnt */
65         LLOG_GEN_INC(ctxt->loc_gen);
66
67         /* first add llog_gen_rec */
68         OBD_ALLOC(lgr, sizeof(*lgr));
69         if (!lgr)
70                 RETURN(-ENOMEM);
71         lgr->lgr_hdr.lrh_len = lgr->lgr_tail.lrt_len = sizeof(*lgr);
72         lgr->lgr_hdr.lrh_type = LLOG_GEN_REC;
73         lgr->lgr_gen = ctxt->loc_gen;
74         rc = llog_add(ctxt, &lgr->lgr_hdr, NULL, NULL, 1, NULL, NULL, NULL);
75         OBD_FREE(lgr, sizeof(*lgr));
76         if (rc != 1)
77                 RETURN(rc);
78
79         LASSERT(ctxt->loc_imp);
80         imp = ctxt->loc_imp;
81
82         request = ptlrpc_prep_req(imp, LUSTRE_LOG_VERSION, LLOG_ORIGIN_CONNECT,
83                                   1, &size, NULL);
84         if (!request)
85                 RETURN(-ENOMEM);
86
87         req_body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof(*req_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         request->rq_replen = lustre_msg_size(0, NULL);
92
93         rc = ptlrpc_queue_wait(request);
94         ptlrpc_req_finished(request);
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 = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*req_body));
109
110         ctxt = llog_get_context(&obd->obd_llogs, 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