1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/mds/mds_log.c
38 * Author: Peter Braam <braam@clusterfs.com>
39 * Author: Andreas Dilger <adilger@clusterfs.com>
40 * Author: Phil Schwan <phil@clusterfs.com>
43 #define DEBUG_SUBSYSTEM S_MDS
45 #ifndef AUTOCONF_INCLUDED
46 #include <linux/config.h>
48 #include <linux/module.h>
49 #include <linux/version.h>
51 #include <libcfs/list.h>
52 #include <obd_class.h>
53 #include <lustre_fsfilt.h>
54 #include <lustre_mds.h>
55 #include <lustre_log.h>
56 #include "mds_internal.h"
58 static int mds_llog_origin_add(struct llog_ctxt *ctxt, struct llog_rec_hdr *rec,
59 struct lov_stripe_md *lsm,
60 struct llog_cookie *logcookies, int numcookies)
62 struct obd_device *obd = ctxt->loc_obd;
63 struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
64 struct llog_ctxt *lctxt;
68 lctxt = llog_get_context(lov_obd, ctxt->loc_idx);
69 rc = llog_add(lctxt, rec, lsm, logcookies, numcookies);
75 static int mds_llog_origin_connect(struct llog_ctxt *ctxt,
76 struct llog_logid *logid,
78 struct obd_uuid *uuid)
80 struct obd_device *obd = ctxt->loc_obd;
81 struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
82 struct llog_ctxt *lctxt;
86 lctxt = llog_get_context(lov_obd, ctxt->loc_idx);
87 rc = llog_connect(lctxt, logid, gen, uuid);
92 static int mds_llog_repl_cancel(struct llog_ctxt *ctxt, struct lov_stripe_md *lsm,
93 int count, struct llog_cookie *cookies, int flags)
95 struct obd_device *obd = ctxt->loc_obd;
96 struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
97 struct llog_ctxt *lctxt;
101 lctxt = llog_get_context(lov_obd, ctxt->loc_idx);
102 rc = llog_cancel(lctxt, lsm, count, cookies, flags);
103 llog_ctxt_put(lctxt);
107 static int mds_llog_add_unlink(struct obd_device *obd,
108 struct lov_stripe_md *lsm, obd_count count,
109 struct llog_cookie *logcookie, int cookies)
111 struct llog_unlink_rec *lur;
112 struct llog_ctxt *ctxt;
115 rc = obd_checkmd(obd->u.mds.mds_osc_exp, obd->obd_self_export, lsm);
118 /* first prepare unlink log record */
121 RETURN(rc = -ENOMEM);
122 lur->lur_hdr.lrh_len = lur->lur_tail.lrt_len = sizeof(*lur);
123 lur->lur_hdr.lrh_type = MDS_UNLINK_REC;
124 lur->lur_count = count;
126 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
127 rc = llog_add(ctxt, &lur->lur_hdr, lsm, logcookie, cookies);
134 int mds_log_op_unlink(struct obd_device *obd,
135 struct lov_mds_md *lmm, int lmm_size,
136 struct llog_cookie *logcookies, int cookies_size)
138 struct mds_obd *mds = &obd->u.mds;
139 struct lov_stripe_md *lsm = NULL;
143 if (IS_ERR(mds->mds_osc_obd))
144 RETURN(PTR_ERR(mds->mds_osc_obd));
146 rc = obd_unpackmd(mds->mds_osc_exp, &lsm, lmm, lmm_size);
149 rc = mds_llog_add_unlink(obd, lsm, 0, logcookies,
150 cookies_size / sizeof(struct llog_cookie));
151 obd_free_memmd(mds->mds_osc_exp, &lsm);
155 int mds_log_op_orphan(struct obd_device *obd, struct lov_stripe_md *lsm,
158 struct mds_obd *mds = &obd->u.mds;
159 struct llog_cookie logcookie;
163 if (IS_ERR(mds->mds_osc_obd))
164 RETURN(PTR_ERR(mds->mds_osc_obd));
166 rc = obd_checkmd(mds->mds_osc_exp, obd->obd_self_export, lsm);
169 rc = mds_llog_add_unlink(obd, lsm, count - 1, &logcookie, 1);
173 int mds_log_op_setattr(struct obd_device *obd, struct inode *inode,
174 struct lov_mds_md *lmm, int lmm_size,
175 struct llog_cookie *logcookies, int cookies_size)
177 struct mds_obd *mds = &obd->u.mds;
178 struct lov_stripe_md *lsm = NULL;
179 struct llog_setattr_rec *lsr;
180 struct llog_ctxt *ctxt;
184 if (IS_ERR(mds->mds_osc_obd))
185 RETURN(PTR_ERR(mds->mds_osc_obd));
187 rc = obd_unpackmd(mds->mds_osc_exp, &lsm, lmm, lmm_size);
191 rc = obd_checkmd(mds->mds_osc_exp, obd->obd_self_export, lsm);
195 OBD_ALLOC(lsr, sizeof(*lsr));
197 GOTO(out, rc = -ENOMEM);
199 /* prepare setattr log record */
200 lsr->lsr_hdr.lrh_len = lsr->lsr_tail.lrt_len = sizeof(*lsr);
201 lsr->lsr_hdr.lrh_type = MDS_SETATTR_REC;
202 lsr->lsr_uid = inode->i_uid;
203 lsr->lsr_gid = inode->i_gid;
205 /* write setattr log */
206 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
207 rc = llog_add(ctxt, &lsr->lsr_hdr, lsm, logcookies,
208 cookies_size / sizeof(struct llog_cookie));
212 OBD_FREE(lsr, sizeof(*lsr));
214 obd_free_memmd(mds->mds_osc_exp, &lsm);
218 static struct llog_operations mds_ost_orig_logops = {
219 lop_add: mds_llog_origin_add,
220 lop_connect: mds_llog_origin_connect,
223 static struct llog_operations mds_size_repl_logops = {
224 lop_cancel: mds_llog_repl_cancel,
227 int mds_llog_init(struct obd_device *obd, struct obd_device *disk_obd,
230 struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
231 struct llog_ctxt *ctxt;
235 rc = llog_setup(obd, LLOG_MDS_OST_ORIG_CTXT, disk_obd, 0, NULL,
236 &mds_ost_orig_logops);
240 rc = llog_setup(obd, LLOG_SIZE_REPL_CTXT, disk_obd, 0, NULL,
241 &mds_size_repl_logops);
245 rc = obd_llog_init(lov_obd, disk_obd, index);
247 CERROR("lov_llog_init err %d\n", rc);
248 GOTO(err_cleanup, rc);
252 ctxt = llog_get_context(obd, LLOG_SIZE_REPL_CTXT);
256 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
262 int mds_llog_finish(struct obd_device *obd, int count)
264 struct llog_ctxt *ctxt;
268 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
270 rc = llog_cleanup(ctxt);
272 ctxt = llog_get_context(obd, LLOG_SIZE_REPL_CTXT);
274 rc2 = llog_cleanup(ctxt);