Whamcloud - gitweb
LU-1187 tests: Add DNE test cases in sanity.
[fs/lustre-release.git] / lustre / lov / lov_log.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 /*
31  * This file is part of Lustre, http://www.lustre.org/
32  * Lustre is a trademark of Sun Microsystems, Inc.
33  *
34  * lustre/lov/lov_log.c
35  *
36  * Author: Phil Schwan <phil@clusterfs.com>
37  * Author: Peter Braam <braam@clusterfs.com>
38  * Author: Mike Shaver <shaver@clusterfs.com>
39  */
40
41 #define DEBUG_SUBSYSTEM S_LOV
42 #ifdef __KERNEL__
43 #include <libcfs/libcfs.h>
44 #else
45 #include <liblustre.h>
46 #endif
47
48 #include <obd_support.h>
49 #include <lustre_lib.h>
50 #include <lustre_net.h>
51 #include <lustre/lustre_idl.h>
52 #include <lustre_dlm.h>
53 #include <lustre_mds.h>
54 #include <obd_class.h>
55 #include <obd_lov.h>
56 #include <obd_ost.h>
57 #include <lprocfs_status.h>
58 #include <lustre_log.h>
59
60 #include "lov_internal.h"
61
62 /* Add log records for each OSC that this object is striped over, and return
63  * cookies for each one.  We _would_ have nice abstraction here, except that
64  * we need to keep cookies in stripe order, even if some are NULL, so that
65  * the right cookies are passed back to the right OSTs at the client side.
66  * Unset cookies should be all-zero (which will never occur naturally). */
67 static int lov_llog_origin_add(const struct lu_env *env,
68                                struct llog_ctxt *ctxt,
69                                struct llog_rec_hdr *rec,
70                                struct lov_stripe_md *lsm,
71                                struct llog_cookie *logcookies, int numcookies)
72 {
73         struct obd_device *obd = ctxt->loc_obd;
74         struct lov_obd *lov = &obd->u.lov;
75         int i, rc = 0, cookies = 0;
76         ENTRY;
77
78         LASSERTF(logcookies && numcookies >= lsm->lsm_stripe_count,
79                  "logcookies %p, numcookies %d lsm->lsm_stripe_count %d \n",
80                  logcookies, numcookies, lsm->lsm_stripe_count);
81
82         for (i = 0; i < lsm->lsm_stripe_count; i++) {
83                 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
84                 struct obd_device *child =
85                         lov->lov_tgts[loi->loi_ost_idx]->ltd_exp->exp_obd;
86                 struct llog_ctxt *cctxt = llog_get_context(child, ctxt->loc_idx);
87
88                 /* fill mds unlink/setattr log record */
89                 switch (rec->lrh_type) {
90                 case MDS_UNLINK_REC: {
91                         struct llog_unlink_rec *lur = (struct llog_unlink_rec *)rec;
92                         lur->lur_oid = loi->loi_id;
93                         lur->lur_oseq = loi->loi_seq;
94                         break;
95                 }
96                 case MDS_SETATTR64_REC: {
97                         struct llog_setattr64_rec *lsr = (struct llog_setattr64_rec *)rec;
98                         lsr->lsr_oid = loi->loi_id;
99                         lsr->lsr_oseq = loi->loi_seq;
100                         break;
101                 }
102                 default:
103                         break;
104                 }
105
106                 /* inject error in llog_obd_add() below */
107                 if (OBD_FAIL_CHECK(OBD_FAIL_MDS_FAIL_LOV_LOG_ADD)) {
108                         llog_ctxt_put(cctxt);
109                         cctxt = NULL;
110                 }
111                 rc = llog_obd_add(env, cctxt, rec, NULL, logcookies + cookies,
112                                   numcookies - cookies);
113                 llog_ctxt_put(cctxt);
114                 if (rc < 0) {
115                         CERROR("Can't add llog (rc = %d) for stripe %d\n",
116                                rc, cookies);
117                         memset(logcookies + cookies, 0,
118                                sizeof(struct llog_cookie));
119                         rc = 1; /* skip this cookie */
120                 }
121                 /* Note that rc is always 1 if llog_obd_add was successful */
122                 cookies += rc;
123         }
124         RETURN(cookies);
125 }
126
127 static int lov_llog_origin_connect(struct llog_ctxt *ctxt,
128                                    struct llog_logid *logid,
129                                    struct llog_gen *gen,
130                                    struct obd_uuid *uuid)
131 {
132         struct obd_device *obd = ctxt->loc_obd;
133         struct lov_obd *lov = &obd->u.lov;
134         int i, rc = 0, err = 0;
135         ENTRY;
136
137         obd_getref(obd);
138         for (i = 0; i < lov->desc.ld_tgt_count; i++) {
139                 struct obd_device *child;
140                 struct llog_ctxt *cctxt;
141
142                 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
143                         continue;
144                 if (uuid && !obd_uuid_equals(uuid, &lov->lov_tgts[i]->ltd_uuid))
145                         continue;
146                 CDEBUG(D_CONFIG, "connect %d/%d\n", i, lov->desc.ld_tgt_count);
147                 child = lov->lov_tgts[i]->ltd_exp->exp_obd;
148                 cctxt = llog_get_context(child, ctxt->loc_idx);
149                 rc = llog_connect(cctxt, logid, gen, uuid);
150                 llog_ctxt_put(cctxt);
151
152                 if (rc) {
153                         CERROR("error osc_llog_connect tgt %d (%d)\n", i, rc);
154                         if (!err)
155                                 err = rc;
156                 }
157         }
158         obd_putref(obd);
159
160         RETURN(err);
161 }
162
163 /* the replicators commit callback */
164 static int lov_llog_repl_cancel(const struct lu_env *env,
165                                 struct llog_ctxt *ctxt,
166                                 struct lov_stripe_md *lsm,
167                                 int count, struct llog_cookie *cookies,
168                                 int flags)
169 {
170         struct lov_obd *lov;
171         struct obd_device *obd = ctxt->loc_obd;
172         int rc = 0, i;
173         ENTRY;
174
175         LASSERT(lsm != NULL);
176         LASSERT(count == lsm->lsm_stripe_count);
177
178         lov = &obd->u.lov;
179         obd_getref(obd);
180         for (i = 0; i < count; i++, cookies++) {
181                 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
182                 struct obd_device *child =
183                         lov->lov_tgts[loi->loi_ost_idx]->ltd_exp->exp_obd;
184                 struct llog_ctxt *cctxt =
185                         llog_get_context(child, ctxt->loc_idx);
186                 int err;
187
188                 err = llog_cancel(env, cctxt, NULL, 1, cookies, flags);
189                 llog_ctxt_put(cctxt);
190                 if (err && lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
191                         CERROR("error: objid "LPX64" subobj "LPX64
192                                " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
193                                loi->loi_id, loi->loi_ost_idx, err);
194                         if (!rc)
195                                 rc = err;
196                 }
197         }
198         obd_putref(obd);
199         RETURN(rc);
200 }
201
202 static struct llog_operations lov_mds_ost_orig_logops = {
203         .lop_obd_add    = lov_llog_origin_add,
204         .lop_connect    = lov_llog_origin_connect,
205 };
206
207 static struct llog_operations lov_size_repl_logops = {
208         .lop_cancel     = lov_llog_repl_cancel,
209 };
210
211 int lov_llog_init(struct obd_device *obd, struct obd_llog_group *olg,
212                   struct obd_device *disk_obd, int *index)
213 {
214         struct lov_obd *lov = &obd->u.lov;
215         struct obd_device *child;
216         int i, rc = 0;
217         ENTRY;
218
219         LASSERT(olg == &obd->obd_olg);
220         rc = llog_setup(NULL, obd, olg, LLOG_MDS_OST_ORIG_CTXT, disk_obd,
221                         &lov_mds_ost_orig_logops);
222         if (rc)
223                 RETURN(rc);
224
225         rc = llog_setup(NULL, obd, olg, LLOG_SIZE_REPL_CTXT, disk_obd,
226                         &lov_size_repl_logops);
227         if (rc)
228                 GOTO(err_cleanup, rc);
229
230         obd_getref(obd);
231         /* count may not match lov->desc.ld_tgt_count during dynamic ost add */
232         for (i = 0; i < lov->desc.ld_tgt_count; i++) {
233                 if (!lov->lov_tgts[i])
234                         continue;
235
236                 if (index && i != *index)
237                         continue;
238
239                 child = lov->lov_tgts[i]->ltd_obd;
240                 rc = obd_llog_init(child, &child->obd_olg, disk_obd, &i);
241                 if (rc)
242                         CERROR("error osc_llog_init idx %d osc '%s' tgt '%s' "
243                                "(rc=%d)\n", i, child->obd_name,
244                                disk_obd->obd_name, rc);
245                 rc = 0;
246         }
247         obd_putref(obd);
248         GOTO(err_cleanup, rc);
249 err_cleanup:
250         if (rc) {
251                 struct llog_ctxt *ctxt =
252                         llog_get_context(obd, LLOG_SIZE_REPL_CTXT);
253                 if (ctxt)
254                         llog_cleanup(NULL, ctxt);
255                 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
256                 if (ctxt)
257                         llog_cleanup(NULL, ctxt);
258         }
259         return rc;
260 }
261
262 int lov_llog_finish(struct obd_device *obd, int count)
263 {
264         struct llog_ctxt *ctxt;
265
266         ENTRY;
267
268         /* cleanup our llogs only if the ctxts have been setup
269          * (client lov doesn't setup, mds lov does). */
270         ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
271         if (ctxt)
272                 llog_cleanup(NULL, ctxt);
273
274         ctxt = llog_get_context(obd, LLOG_SIZE_REPL_CTXT);
275         if (ctxt)
276                 llog_cleanup(NULL, ctxt);
277
278         /* lov->tgt llogs are cleaned during osc_cleanup. */
279         RETURN(0);
280 }