Whamcloud - gitweb
b=21411 Avoid infinite loop when bulk IO delayed.
[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
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
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 #include <lustre_fsfilt.h>
64
65 #ifdef __KERNEL__
66 int llog_origin_connect(struct llog_ctxt *ctxt,
67                         struct llog_logid *logid, struct llog_gen *gen,
68                         struct obd_uuid *uuid)
69 {
70         struct llog_gen_rec *lgr;
71         struct obd_import *imp;
72         struct ptlrpc_request *request;
73         struct llogd_conn_body *req_body;
74         int size[2] = { sizeof(struct ptlrpc_body),
75                         sizeof(struct llogd_conn_body) };
76         struct inode *inode;
77         void *handle;
78         int rc, rc1;
79         ENTRY;
80
81         LASSERT(ctxt != NULL);
82         LASSERT(ctxt->loc_handle != NULL);
83         LASSERT(ctxt->loc_handle->lgh_file != NULL);
84         LASSERT(ctxt->loc_handle->lgh_file->f_dentry != NULL);
85         inode = ctxt->loc_handle->lgh_file->f_dentry->d_inode;
86
87         if (list_empty(&ctxt->loc_handle->u.chd.chd_head)) {
88                 CDEBUG(D_HA, "there is no record related to ctxt %p\n", ctxt);
89                 RETURN(0);
90         }
91
92         /* FIXME what value for gen->conn_cnt */
93         LLOG_GEN_INC(ctxt->loc_gen);
94
95         /* first add llog_gen_rec */
96         OBD_ALLOC(lgr, sizeof(*lgr));
97         if (!lgr)
98                 RETURN(-ENOMEM);
99         lgr->lgr_hdr.lrh_len = lgr->lgr_tail.lrt_len = sizeof(*lgr);
100         lgr->lgr_hdr.lrh_type = LLOG_GEN_REC;
101
102         handle = fsfilt_start_log(ctxt->loc_exp->exp_obd, inode,
103                                   FSFILT_OP_CANCEL_UNLINK, NULL, 1);
104
105         if (IS_ERR(handle)) {
106                 CERROR("fsfilt_start failed: %ld\n", PTR_ERR(handle));
107                 OBD_FREE(lgr, sizeof(*lgr));
108                 rc = PTR_ERR(handle);
109                 RETURN(rc);
110         }
111         lgr->lgr_gen = ctxt->loc_gen;
112         rc = llog_add(ctxt, &lgr->lgr_hdr, NULL, NULL, 1);
113         OBD_FREE(lgr, sizeof(*lgr));
114
115         rc1 = fsfilt_commit(ctxt->loc_exp->exp_obd, inode, handle, 0);
116         if (rc != 1 || rc1 != 0) {
117                 rc = (rc != 1) ? rc : rc1;
118                 RETURN(rc);
119         }
120
121         LASSERT(ctxt->loc_imp);
122         imp = ctxt->loc_imp;
123
124         request = ptlrpc_prep_req(imp, LUSTRE_LOG_VERSION,
125                                   LLOG_ORIGIN_CONNECT, 2, size, NULL);
126         if (!request)
127                 RETURN(-ENOMEM);
128
129         req_body = lustre_msg_buf(request->rq_reqmsg, REQ_REC_OFF,
130                                   sizeof(*req_body));
131
132         req_body->lgdc_gen = ctxt->loc_gen;
133         req_body->lgdc_logid = ctxt->loc_handle->lgh_id;
134         req_body->lgdc_ctxt_idx = ctxt->loc_idx + 1;
135         ptlrpc_req_set_repsize(request, 1, NULL);
136
137         rc = ptlrpc_queue_wait(request);
138         ptlrpc_req_finished(request);
139
140         RETURN(rc);
141 }
142 EXPORT_SYMBOL(llog_origin_connect);
143
144 int llog_handle_connect(struct ptlrpc_request *req)
145 {
146         struct obd_device *obd = req->rq_export->exp_obd;
147         struct llogd_conn_body *req_body;
148         struct llog_ctxt *ctxt;
149         int rc;
150         ENTRY;
151
152         req_body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF,
153                                   sizeof(*req_body));
154
155         ctxt = llog_get_context(obd, req_body->lgdc_ctxt_idx);
156         rc = llog_connect(ctxt, &req_body->lgdc_logid,
157                           &req_body->lgdc_gen, NULL);
158
159         llog_ctxt_put(ctxt);
160         if (rc != 0)
161                 CERROR("failed at llog_relp_connect\n");
162
163         RETURN(rc);
164 }
165 EXPORT_SYMBOL(llog_handle_connect);
166
167 int llog_receptor_accept(struct llog_ctxt *ctxt, struct obd_import *imp)
168 {
169         ENTRY;
170         LASSERT(ctxt);
171         mutex_down(&ctxt->loc_sem);
172         if (ctxt->loc_imp != imp) {
173                 if (ctxt->loc_imp) {
174                         CWARN("changing the import %p - %p\n",
175                               ctxt->loc_imp, imp);
176                         class_import_put(ctxt->loc_imp);
177                 }
178                 ctxt->loc_imp = class_import_get(imp);
179         }
180         mutex_up(&ctxt->loc_sem);
181         RETURN(0);
182 }
183 EXPORT_SYMBOL(llog_receptor_accept);
184
185 #else /* !__KERNEL__ */
186
187 int llog_origin_connect(struct llog_ctxt *ctxt,
188                         struct llog_logid *logid, struct llog_gen *gen,
189                         struct obd_uuid *uuid)
190 {
191         return 0;
192 }
193 #endif
194
195 int llog_initiator_connect(struct llog_ctxt *ctxt)
196 {
197         struct obd_import *new_imp;
198         ENTRY;
199         LASSERT(ctxt);
200         new_imp = ctxt->loc_obd->u.cli.cl_import;
201         mutex_down(&ctxt->loc_sem);
202         if (ctxt->loc_imp != new_imp) {
203                 if (ctxt->loc_imp)
204                         class_import_put(ctxt->loc_imp);
205                 ctxt->loc_imp = class_import_get(new_imp);
206         }
207         mutex_up(&ctxt->loc_sem);
208         RETURN(0);
209 }
210 EXPORT_SYMBOL(llog_initiator_connect);