Whamcloud - gitweb
- make HEAD from b_post_cmd3
[fs/lustre-release.git] / lustre / lov / lov_log.c
1  /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
5  * Author: Phil Schwan <phil@clusterfs.com>
6  *         Peter Braam <braam@clusterfs.com>
7  *         Mike Shaver <shaver@clusterfs.com>
8  *
9  *   This file is part of the Lustre file system, http://www.lustre.org
10  *   Lustre is a trademark of Cluster File Systems, Inc.
11  *
12  *   You may have signed or agreed to another license before downloading
13  *   this software.  If so, you are bound by the terms and conditions
14  *   of that agreement, and the following does not apply to you.  See the
15  *   LICENSE file included with this distribution for more information.
16  *
17  *   If you did not agree to a different license, then this copy of Lustre
18  *   is open source software; you can redistribute it and/or modify it
19  *   under the terms of version 2 of the GNU General Public License as
20  *   published by the Free Software Foundation.
21  *
22  *   In either case, Lustre is distributed in the hope that it will be
23  *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
24  *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  *   license text for more details.
26  */
27
28 #ifndef EXPORT_SYMTAB
29 # define EXPORT_SYMTAB
30 #endif
31 #define DEBUG_SUBSYSTEM S_LOV
32 #ifdef __KERNEL__
33 #include <libcfs/libcfs.h>
34 #else
35 #include <liblustre.h>
36 #endif
37
38 #include <obd_support.h>
39 #include <lustre_lib.h>
40 #include <lustre_net.h>
41 #include <lustre/lustre_idl.h>
42 #include <lustre_dlm.h>
43 #include <lustre_mds.h>
44 #include <obd_class.h>
45 #include <obd_lov.h>
46 #include <obd_ost.h>
47 #include <lprocfs_status.h>
48
49 #include "lov_internal.h"
50
51 /* Add log records for each OSC that this object is striped over, and return
52  * cookies for each one.  We _would_ have nice abstraction here, except that
53  * we need to keep cookies in stripe order, even if some are NULL, so that
54  * the right cookies are passed back to the right OSTs at the client side.
55  * Unset cookies should be all-zero (which will never occur naturally). */
56 static int lov_llog_origin_add(struct llog_ctxt *ctxt,
57                         struct llog_rec_hdr *rec, struct lov_stripe_md *lsm,
58                         struct llog_cookie *logcookies, int numcookies)
59 {
60         struct obd_device *obd = ctxt->loc_obd;
61         struct lov_obd *lov = &obd->u.lov;
62         int i, rc = 0, rc1;
63         ENTRY;
64
65         LASSERTF(logcookies && numcookies >= lsm->lsm_stripe_count, 
66                  "logcookies %p, numcookies %d lsm->lsm_stripe_count %d \n",
67                  logcookies, numcookies, lsm->lsm_stripe_count);
68
69         for (i = 0; i < lsm->lsm_stripe_count; i++) {
70                 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
71                 struct obd_device *child = 
72                         lov->lov_tgts[loi->loi_ost_idx]->ltd_exp->exp_obd; 
73                 struct llog_ctxt *cctxt = llog_get_context(child, ctxt->loc_idx);
74
75                 /* fill mds unlink/setattr log record */
76                 switch (rec->lrh_type) {
77                 case MDS_UNLINK_REC: {
78                         struct llog_unlink_rec *lur = (struct llog_unlink_rec *)rec;
79                         lur->lur_oid = loi->loi_id;
80                         lur->lur_ogen = loi->loi_gr;
81                         break;
82                 }
83                 case MDS_SETATTR_REC: {
84                         struct llog_setattr_rec *lsr = (struct llog_setattr_rec *)rec;
85                         lsr->lsr_oid = loi->loi_id;
86                         lsr->lsr_ogen = loi->loi_gr;
87                         break;
88                 }
89                 default:
90                         break;
91                 }
92                 LASSERT(lsm->lsm_object_gr == loi->loi_gr);
93                 rc1 = llog_add(cctxt, rec, NULL, logcookies + rc,
94                                numcookies - rc);
95                 if (rc1 < 0)
96                         RETURN(rc1);
97                 rc += rc1;
98         }
99
100         RETURN(rc);
101 }
102
103 static int lov_llog_origin_connect(struct llog_ctxt *ctxt, int count,
104                                    struct llog_logid *logid,
105                                    struct llog_gen *gen,
106                                    struct obd_uuid *uuid)
107 {
108         struct obd_device *obd = ctxt->loc_obd;
109         struct lov_obd *lov = &obd->u.lov;
110         int i, rc = 0, err = 0;
111         ENTRY;
112
113         lov_getref(obd);
114         for (i = 0; i < count; i++) {
115                 struct obd_device *child;
116                 struct llog_ctxt *cctxt;
117                 
118                 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
119                         continue;
120                 if (uuid && !obd_uuid_equals(uuid, &lov->lov_tgts[i]->ltd_uuid))
121                         continue;
122                 CDEBUG(D_CONFIG, "connect %d/%d\n", i, count);
123                 child = lov->lov_tgts[i]->ltd_exp->exp_obd;
124                 cctxt = llog_get_context(child, ctxt->loc_idx);
125                 rc = llog_connect(cctxt, 1, logid, gen, uuid);
126                 if (rc) {
127                         CERROR("error osc_llog_connect tgt %d (%d)\n", i, rc);
128                         if (!err) 
129                                 err = rc;
130                 }
131         }
132         lov_putref(obd);
133
134         RETURN(err);
135 }
136
137 /* the replicators commit callback */
138 static int lov_llog_repl_cancel(struct llog_ctxt *ctxt, struct lov_stripe_md *lsm,
139                           int count, struct llog_cookie *cookies, int flags)
140 {
141         struct lov_obd *lov;
142         struct obd_device *obd = ctxt->loc_obd;
143         int rc = 0, i;
144         ENTRY;
145
146         LASSERT(lsm != NULL);
147         LASSERT(count == lsm->lsm_stripe_count);
148
149         lov = &obd->u.lov;
150         lov_getref(obd);
151         for (i = 0; i < count; i++, cookies++) {
152                 struct lov_oinfo *loi = lsm->lsm_oinfo[i];
153                 struct obd_device *child = 
154                         lov->lov_tgts[loi->loi_ost_idx]->ltd_exp->exp_obd;
155                 struct llog_ctxt *cctxt = 
156                         llog_get_context(child, ctxt->loc_idx);
157                 int err;
158
159                 err = llog_cancel(cctxt, NULL, 1, cookies, flags);
160                 if (err && lov->lov_tgts[loi->loi_ost_idx]->ltd_active) {
161                         CERROR("error: objid "LPX64" subobj "LPX64
162                                " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
163                                loi->loi_id, loi->loi_ost_idx, err);
164                         if (!rc)
165                                 rc = err;
166                 }
167         }
168         lov_putref(obd);
169         RETURN(rc);
170 }
171
172 static struct llog_operations lov_mds_ost_orig_logops = {
173         lop_add: lov_llog_origin_add,
174         lop_connect: lov_llog_origin_connect
175 };
176
177 static struct llog_operations lov_size_repl_logops = {
178         lop_cancel: lov_llog_repl_cancel
179 };
180
181 int lov_llog_init(struct obd_device *obd, struct obd_llogs *llogs, 
182                   struct obd_device *tgt, int count, struct llog_catid *logid, 
183                   struct obd_uuid *uuid)
184 {
185         struct lov_obd *lov = &obd->u.lov;
186         struct obd_device *child;
187         int i, rc = 0, err = 0;
188         ENTRY;
189
190         rc = llog_setup(obd, llogs, LLOG_MDS_OST_ORIG_CTXT, tgt, 0, NULL,
191                         &lov_mds_ost_orig_logops);
192         if (rc)
193                 RETURN(rc);
194
195         rc = llog_setup(obd, llogs, LLOG_SIZE_REPL_CTXT, tgt, 0, NULL,
196                         &lov_size_repl_logops);
197         if (rc)
198                 RETURN(rc);
199
200         lov_getref(obd);
201         /* count may not match lov->desc.ld_tgt_count during dynamic ost add */
202         for (i = 0; i < count; i++) {
203                 if (!lov->lov_tgts[i] || !lov->lov_tgts[i]->ltd_active)
204                         continue;
205                 if (uuid && !obd_uuid_equals(uuid, &lov->lov_tgts[i]->ltd_uuid))
206                         continue;
207                 CDEBUG(D_CONFIG, "init %d/%d\n", i, count);
208                 LASSERT(lov->lov_tgts[i]->ltd_exp);
209                 child = lov->lov_tgts[i]->ltd_exp->exp_obd;
210                 rc = obd_llog_init(child, llogs, tgt, 1, logid + i, uuid);
211                 if (rc) {
212                         CERROR("error osc_llog_init idx %d osc '%s' tgt '%s' "
213                                "(rc=%d)\n", i, child->obd_name, tgt->obd_name,
214                                rc);
215                         if (!err) 
216                                 err = rc;
217                 }
218         }
219         lov_putref(obd);
220         RETURN(err);
221 }
222
223 int lov_llog_finish(struct obd_device *obd, int count)
224 {
225         struct llog_ctxt *ctxt;
226         int rc = 0, rc2 = 0;
227         ENTRY;
228
229         /* cleanup our llogs only if the ctxts have been setup
230          * (client lov doesn't setup, mds lov does). */
231         ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
232         if (ctxt)
233                 rc = llog_cleanup(ctxt);
234
235         ctxt = llog_get_context(obd, LLOG_SIZE_REPL_CTXT);
236         if (ctxt)
237                 rc2 = llog_cleanup(ctxt);
238         if (!rc)
239                 rc = rc2;
240
241         /* lov->tgt llogs are cleaned during osc_cleanup. */
242         RETURN(rc);
243 }