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