Whamcloud - gitweb
land v0.9.1 on HEAD, in preparation for a 1.0.x branch
[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 <portals/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,
49                         struct llog_ctxt_gen *gen)
50 {
51         struct obd_import *imp;
52         struct ptlrpc_request *request;
53         struct llogd_conn_body *req_body;
54         int size = sizeof(struct llogd_conn_body);
55         int rc;
56         ENTRY;
57
58         LASSERT(ctxt->loc_imp);
59         imp = ctxt->loc_imp;
60
61         request = ptlrpc_prep_req(imp, LLOG_ORIGIN_CONNECT, 1, &size, NULL);
62         if (!request) 
63                 RETURN(-ENOMEM);
64
65         req_body = lustre_msg_buf(request->rq_reqmsg, 0, sizeof(*req_body));
66
67         req_body->lgdc_gen = ctxt->loc_gen;
68         req_body->lgdc_logid = ctxt->loc_handle->lgh_id;
69         req_body->lgdc_ctxt_idx = ctxt->loc_idx + 1;
70         request->rq_replen = lustre_msg_size(0, NULL);
71
72         rc = ptlrpc_queue_wait(request);
73         ptlrpc_req_finished(request);
74
75         RETURN(rc);
76 }
77 EXPORT_SYMBOL(llog_origin_connect);
78
79 int llog_handle_connect(struct ptlrpc_request *req)
80 {
81         struct obd_device *obd = req->rq_export->exp_obd;
82         struct llogd_conn_body *req_body;
83         struct llog_ctxt *ctxt;
84         int rc;
85         ENTRY;
86
87         req_body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*req_body));
88
89         ctxt = llog_get_context(obd, req_body->lgdc_ctxt_idx);
90         rc = llog_connect(ctxt, 1, &req_body->lgdc_logid, 
91                           &req_body->lgdc_gen);
92         if (rc != 0) 
93                 CERROR("failed at llog_relp_connect\n");
94
95         RETURN(rc);
96 }
97 EXPORT_SYMBOL(llog_handle_connect);
98
99 int llog_receptor_accept(struct llog_ctxt *ctxt, struct obd_import *imp)
100 {
101         ENTRY;
102         LASSERT(ctxt);
103         ctxt->loc_imp = imp;
104         RETURN(0);
105 }
106 EXPORT_SYMBOL(llog_receptor_accept);
107
108 int llog_initiator_connect(struct llog_ctxt *ctxt)
109 {
110         ENTRY;
111         LASSERT(ctxt);
112         ctxt->loc_imp = ctxt->loc_obd->u.cli.cl_import;
113         RETURN(0);
114 }
115 EXPORT_SYMBOL(llog_initiator_connect);
116
117 #else /* !__KERNEL__ */
118
119 int llog_origin_connect(struct llog_ctxt *ctxt, int count,
120                         struct llog_logid *logid,
121                         struct llog_ctxt_gen *gen)
122 {
123         return 0;
124 }
125
126 int llog_initiator_connect(struct llog_ctxt *ctxt)
127 {
128         return 0;
129 }
130 #endif