Whamcloud - gitweb
LU-2446 build: Update Whamcloud copyright messages for Intel
[fs/lustre-release.git] / lustre / ptlrpc / llog_net.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
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.
9  *
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).
15  *
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
19  *
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
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2012, Intel Corporation.
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 #ifdef __KERNEL__
50 #include <libcfs/libcfs.h>
51 #else
52 #include <liblustre.h>
53 #endif
54
55 #include <obd_class.h>
56 #include <lustre_log.h>
57 #include <libcfs/list.h>
58 #include <lvfs.h>
59 #include <lustre_fsfilt.h>
60
61 #ifdef __KERNEL__
62 int llog_origin_connect(struct llog_ctxt *ctxt,
63                         struct llog_logid *logid, struct llog_gen *gen,
64                         struct obd_uuid *uuid)
65 {
66         struct llog_gen_rec    *lgr;
67         struct ptlrpc_request  *req;
68         struct llogd_conn_body *req_body;
69         struct inode* inode = ctxt->loc_handle->lgh_file->f_dentry->d_inode;
70         void *handle;
71         int rc, rc1;
72
73         ENTRY;
74
75         if (cfs_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_init(ctxt);
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
90         handle = fsfilt_start_log(ctxt->loc_exp->exp_obd, inode, 
91                                   FSFILT_OP_CANCEL_UNLINK, NULL, 1);
92         if (IS_ERR(handle)) {
93                CERROR("fsfilt_start failed: %ld\n", PTR_ERR(handle));
94                OBD_FREE(lgr, sizeof(*lgr));
95                rc = PTR_ERR(handle);
96                RETURN(rc);
97         }
98
99         lgr->lgr_gen = ctxt->loc_gen;
100         rc = llog_obd_add(NULL, ctxt, &lgr->lgr_hdr, NULL, NULL, 1);
101         OBD_FREE_PTR(lgr);
102         rc1 = fsfilt_commit(ctxt->loc_exp->exp_obd, inode, handle, 0);
103         if (rc != 1 || rc1 != 0) {
104                 rc = (rc != 1) ? rc : rc1;
105                 RETURN(rc);
106         }
107
108         LASSERT(ctxt->loc_imp);
109         req = ptlrpc_request_alloc_pack(ctxt->loc_imp, &RQF_LLOG_ORIGIN_CONNECT,
110                                         LUSTRE_LOG_VERSION,
111                                         LLOG_ORIGIN_CONNECT);
112         if (req == NULL)
113                 RETURN(-ENOMEM);
114
115         CDEBUG(D_OTHER, "%s mount_count "LPU64", connection count "LPU64"\n",
116                ctxt->loc_exp->exp_obd->obd_type->typ_name,
117                ctxt->loc_gen.mnt_cnt, ctxt->loc_gen.conn_cnt);
118
119         req_body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
120         req_body->lgdc_gen = ctxt->loc_gen;
121         req_body->lgdc_logid = ctxt->loc_handle->lgh_id;
122         req_body->lgdc_ctxt_idx = ctxt->loc_idx + 1;
123         ptlrpc_request_set_replen(req);
124
125         req->rq_no_resend = req->rq_no_delay = 1;
126         rc = ptlrpc_queue_wait(req);
127         ptlrpc_req_finished(req);
128
129         RETURN(rc);
130 }
131 EXPORT_SYMBOL(llog_origin_connect);
132
133 int llog_handle_connect(struct ptlrpc_request *req)
134 {
135         struct obd_device *obd = req->rq_export->exp_obd;
136         struct llogd_conn_body *req_body;
137         struct llog_ctxt *ctxt;
138         int rc;
139         ENTRY;
140
141         req_body = req_capsule_client_get(&req->rq_pill, &RMF_LLOGD_CONN_BODY);
142
143         ctxt = llog_get_context(obd, req_body->lgdc_ctxt_idx);
144         rc = llog_connect(ctxt, &req_body->lgdc_logid,
145                           &req_body->lgdc_gen, NULL);
146
147         llog_ctxt_put(ctxt);
148         if (rc != 0)
149                 CERROR("failed at llog_relp_connect\n");
150
151         RETURN(rc);
152 }
153 EXPORT_SYMBOL(llog_handle_connect);
154
155 int llog_receptor_accept(struct llog_ctxt *ctxt, struct obd_import *imp)
156 {
157         ENTRY;
158
159         LASSERT(ctxt);
160         mutex_lock(&ctxt->loc_mutex);
161         if (ctxt->loc_imp != imp) {
162                 if (ctxt->loc_imp) {
163                         CWARN("changing the import %p - %p\n",
164                               ctxt->loc_imp, imp);
165                         class_import_put(ctxt->loc_imp);
166                 }
167                 ctxt->loc_imp = class_import_get(imp);
168         }
169         mutex_unlock(&ctxt->loc_mutex);
170         RETURN(0);
171 }
172 EXPORT_SYMBOL(llog_receptor_accept);
173
174 #else /* !__KERNEL__ */
175
176 int llog_origin_connect(struct llog_ctxt *ctxt,
177                         struct llog_logid *logid, struct llog_gen *gen,
178                         struct obd_uuid *uuid)
179 {
180         return 0;
181 }
182 #endif
183
184 int llog_initiator_connect(struct llog_ctxt *ctxt)
185 {
186         struct obd_import *new_imp;
187         ENTRY;
188
189         LASSERT(ctxt);
190         new_imp = ctxt->loc_obd->u.cli.cl_import;
191         LASSERTF(ctxt->loc_imp == NULL || ctxt->loc_imp == new_imp,
192                  "%p - %p\n", ctxt->loc_imp, new_imp);
193         mutex_lock(&ctxt->loc_mutex);
194         if (ctxt->loc_imp != new_imp) {
195                 if (ctxt->loc_imp)
196                         class_import_put(ctxt->loc_imp);
197                 ctxt->loc_imp = class_import_get(new_imp);
198         }
199         mutex_unlock(&ctxt->loc_mutex);
200         RETURN(0);
201 }
202 EXPORT_SYMBOL(llog_initiator_connect);