1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
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>
9 * This file is part of the Lustre file system, http://www.lustre.org
10 * Lustre is a trademark of Cluster File Systems, Inc.
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.
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.
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.
29 # define EXPORT_SYMTAB
31 #define DEBUG_SUBSYSTEM S_LOV
33 #include <linux/slab.h>
34 #include <linux/module.h>
35 #include <linux/init.h>
36 #include <linux/slab.h>
37 #include <linux/pagemap.h>
38 #include <asm/div64.h>
39 #include <linux/seq_file.h>
41 #include <liblustre.h>
44 #include <linux/obd_support.h>
45 #include <linux/lustre_lib.h>
46 #include <linux/lustre_net.h>
47 #include <linux/lustre_idl.h>
48 #include <linux/lustre_dlm.h>
49 #include <linux/lustre_mds.h>
50 #include <linux/obd_class.h>
51 #include <linux/obd_lov.h>
52 #include <linux/obd_ost.h>
53 #include <linux/lprocfs_status.h>
55 #include "lov_internal.h"
57 /* Add log records for each OSC that this object is striped over, and return
58 * cookies for each one. We _would_ have nice abstraction here, except that
59 * we need to keep cookies in stripe order, even if some are NULL, so that
60 * the right cookies are passed back to the right OSTs at the client side.
61 * Unset cookies should be all-zero (which will never occur naturally). */
62 static int lov_llog_origin_add(struct llog_ctxt *ctxt,
63 struct llog_rec_hdr *rec, struct lov_stripe_md *lsm,
64 struct llog_cookie *logcookies, int numcookies)
66 struct obd_device *obd = ctxt->loc_obd;
67 struct lov_obd *lov = &obd->u.lov;
68 struct lov_oinfo *loi;
72 LASSERTF(logcookies && numcookies >= lsm->lsm_stripe_count,
73 "logcookies %p, numcookies %d lsm->lsm_stripe_count %d \n",
74 logcookies, numcookies, lsm->lsm_stripe_count);
76 for (i = 0,loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++,loi++) {
77 struct obd_device *child = lov->tgts[loi->loi_ost_idx].ltd_exp->exp_obd;
78 struct llog_ctxt *cctxt = llog_get_context(child, ctxt->loc_idx);
80 /* fill mds unlink/setattr log record */
81 switch (rec->lrh_type) {
82 case MDS_UNLINK_REC: {
83 struct llog_unlink_rec *lur = (struct llog_unlink_rec *)rec;
84 lur->lur_oid = loi->loi_id;
85 lur->lur_ogen = loi->loi_gr;
88 case MDS_SETATTR_REC: {
89 struct llog_setattr_rec *lsr = (struct llog_setattr_rec *)rec;
90 lsr->lsr_oid = loi->loi_id;
91 lsr->lsr_ogen = loi->loi_gr;
98 rc += llog_add(cctxt, rec, NULL, logcookies + rc,
105 static int lov_llog_origin_connect(struct llog_ctxt *ctxt, int count,
106 struct llog_logid *logid,
107 struct llog_gen *gen,
108 struct obd_uuid *uuid)
110 struct obd_device *obd = ctxt->loc_obd;
111 struct lov_obd *lov = &obd->u.lov;
112 struct lov_tgt_desc *tgt;
116 /* We might have added an osc and not told the mds yet */
117 if (count != lov->desc.ld_tgt_count)
118 CERROR("Origin connect mds cnt %d != lov cnt %d\n", count,
119 lov->desc.ld_tgt_count);
121 for (i = 0, tgt = lov->tgts; i < count; i++, tgt++) {
122 struct obd_device *child;
123 struct llog_ctxt *cctxt;
127 child = tgt->ltd_exp->exp_obd;
128 cctxt = llog_get_context(child, ctxt->loc_idx);
129 if (uuid && !obd_uuid_equals(uuid, &lov->tgts[i].uuid))
132 rc = llog_connect(cctxt, 1, logid, gen, uuid);
134 CERROR("error osc_llog_connect tgt %d (%d)\n", i, rc);
142 /* the replicators commit callback */
143 static int lov_llog_repl_cancel(struct llog_ctxt *ctxt, struct lov_stripe_md *lsm,
144 int count, struct llog_cookie *cookies, int flags)
147 struct obd_device *obd = ctxt->loc_obd;
148 struct lov_oinfo *loi;
152 LASSERT(lsm != NULL);
153 LASSERT(count == lsm->lsm_stripe_count);
155 loi = lsm->lsm_oinfo;
157 for (i = 0; i < count; i++, cookies++, loi++) {
158 struct obd_device *child = lov->tgts[loi->loi_ost_idx].ltd_exp->exp_obd;
159 struct llog_ctxt *cctxt = llog_get_context(child, ctxt->loc_idx);
162 err = llog_cancel(cctxt, NULL, 1, cookies, flags);
163 if (err && lov->tgts[loi->loi_ost_idx].active) {
164 CERROR("error: objid "LPX64" subobj "LPX64
165 " on OST idx %d: rc = %d\n", lsm->lsm_object_id,
166 loi->loi_id, loi->loi_ost_idx, err);
174 static struct llog_operations lov_mds_ost_orig_logops = {
175 lop_add: lov_llog_origin_add,
176 lop_connect: lov_llog_origin_connect
179 static struct llog_operations lov_size_repl_logops = {
180 lop_cancel: lov_llog_repl_cancel
183 int lov_llog_init(struct obd_device *obd, struct obd_device *tgt,
184 int count, struct llog_catid *logid)
186 struct lov_obd *lov = &obd->u.lov;
187 struct lov_tgt_desc *ctgt;
191 rc = llog_setup(obd, LLOG_MDS_OST_ORIG_CTXT, tgt, 0, NULL,
192 &lov_mds_ost_orig_logops);
196 rc = llog_setup(obd, LLOG_SIZE_REPL_CTXT, tgt, 0, NULL,
197 &lov_size_repl_logops);
201 CDEBUG(D_CONFIG, "llog init with %d targets\n", count);
202 LASSERT(lov->desc.ld_tgt_count == count);
203 for (i = 0, ctgt = lov->tgts; i < lov->desc.ld_tgt_count; i++, ctgt++) {
204 struct obd_device *child;
207 child = ctgt->ltd_exp->exp_obd;
208 rc = obd_llog_init(child, tgt, 1, logid + i);
210 CERROR("error osc_llog_init %d\n", i);
217 int lov_llog_finish(struct obd_device *obd, int count)
219 struct llog_ctxt *ctxt;
223 /* cleanup our llogs only if the ctxts have been setup
224 * (client lov doesn't setup, mds lov does). */
225 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
227 rc = llog_cleanup(ctxt);
229 ctxt = llog_get_context(obd, LLOG_SIZE_REPL_CTXT);
231 rc2 = llog_cleanup(ctxt);
235 /* lov->tgt llogs are cleaned during osc_cleanup. */