1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * Copyright (c) 2001-2003 Cluster File Systems, Inc.
7 * Author: Peter Braam <braam@clusterfs.com>
8 * Author: Andreas Dilger <adilger@clusterfs.com>
9 * Author: Phil Schwan <phil@clusterfs.com>
11 * This file is part of Lustre, http://www.lustre.org.
13 * Lustre is free software; you can redistribute it and/or
14 * modify it under the terms of version 2 of the GNU General Public
15 * License as published by the Free Software Foundation.
17 * Lustre is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with Lustre; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #define DEBUG_SUBSYSTEM S_MDS
29 #include <linux/config.h>
30 #include <linux/module.h>
31 #include <linux/version.h>
33 #include <libcfs/list.h>
34 #include <linux/obd_class.h>
35 #include <linux/lustre_fsfilt.h>
36 #include <linux/lustre_commit_confd.h>
37 #include <linux/lustre_log.h>
39 #include "mds_internal.h"
41 /* callback function of lov to fill unlink log record */
42 static int mds_log_fill_unlink_rec(struct llog_rec_hdr *rec, void *data)
44 struct llog_fill_rec_data *lfd = (struct llog_fill_rec_data *)data;
45 struct llog_unlink_rec *lur = (struct llog_unlink_rec *)rec;
47 lur->lur_oid = lfd->lfd_id;
48 lur->lur_ogen = lfd->lfd_ogen;
53 /* callback function of lov to fill setattr log record */
54 static int mds_log_fill_setattr_rec(struct llog_rec_hdr *rec, void *data)
56 struct llog_fill_rec_data *lfd = (struct llog_fill_rec_data *)data;
57 struct llog_setattr_rec *lsr = (struct llog_setattr_rec *)rec;
59 lsr->lsr_oid = lfd->lfd_id;
60 lsr->lsr_ogen = lfd->lfd_ogen;
65 static int mds_llog_origin_add(struct llog_ctxt *ctxt,
66 struct llog_rec_hdr *rec, struct lov_stripe_md *lsm,
67 struct llog_cookie *logcookies, int numcookies,
68 llog_fill_rec_cb_t fill_cb)
70 struct obd_device *obd = ctxt->loc_obd;
71 struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
72 struct llog_ctxt *lctxt;
76 lctxt = llog_get_context(lov_obd, ctxt->loc_idx);
77 rc = llog_add(lctxt, rec, lsm, logcookies, numcookies, fill_cb);
81 static int mds_llog_origin_connect(struct llog_ctxt *ctxt, int count,
82 struct llog_logid *logid,
84 struct obd_uuid *uuid)
86 struct obd_device *obd = ctxt->loc_obd;
87 struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
88 struct llog_ctxt *lctxt;
92 lctxt = llog_get_context(lov_obd, ctxt->loc_idx);
93 rc = llog_connect(lctxt, count, logid, gen, uuid);
97 static int mds_llog_repl_cancel(struct llog_ctxt *ctxt, struct lov_stripe_md *lsm,
98 int count, struct llog_cookie *cookies, int flags)
100 struct obd_device *obd = ctxt->loc_obd;
101 struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
102 struct llog_ctxt *lctxt;
106 lctxt = llog_get_context(lov_obd, ctxt->loc_idx);
107 rc = llog_cancel(lctxt, lsm, count, cookies,flags);
111 int mds_log_op_unlink(struct obd_device *obd, struct inode *inode,
112 struct lov_mds_md *lmm, int lmm_size,
113 struct llog_cookie *logcookies, int cookies_size)
115 struct mds_obd *mds = &obd->u.mds;
116 struct lov_stripe_md *lsm = NULL;
117 struct llog_ctxt *ctxt;
118 struct llog_unlink_rec *lur;
122 if (IS_ERR(mds->mds_osc_obd))
123 RETURN(PTR_ERR(mds->mds_osc_obd));
125 rc = obd_unpackmd(mds->mds_osc_exp, &lsm,
130 /* first prepare unlink log record */
131 OBD_ALLOC(lur, sizeof(*lur));
134 lur->lur_hdr.lrh_len = lur->lur_tail.lrt_len = sizeof(*lur);
135 lur->lur_hdr.lrh_type = MDS_UNLINK_REC;
137 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
138 rc = llog_add(ctxt, &lur->lur_hdr, lsm, logcookies,
139 cookies_size / sizeof(struct llog_cookie),
140 mds_log_fill_unlink_rec);
142 obd_free_memmd(mds->mds_osc_exp, &lsm);
143 OBD_FREE(lur, sizeof(*lur));
148 int mds_log_op_setattr(struct obd_device *obd, struct inode *inode,
149 struct lov_mds_md *lmm, int lmm_size,
150 struct llog_cookie *logcookies, int cookies_size)
152 struct mds_obd *mds = &obd->u.mds;
153 struct lov_stripe_md *lsm = NULL;
154 struct llog_ctxt *ctxt;
155 struct llog_setattr_rec *lsr;
159 if (IS_ERR(mds->mds_osc_obd))
160 RETURN(PTR_ERR(mds->mds_osc_obd));
162 rc = obd_unpackmd(mds->mds_osc_exp, &lsm,
167 OBD_ALLOC(lsr, sizeof(*lsr));
171 /* prepare setattr log record */
172 lsr->lsr_hdr.lrh_len = lsr->lsr_tail.lrt_len = sizeof(*lsr);
173 lsr->lsr_hdr.lrh_type = MDS_SETATTR_REC;
174 lsr->lsr_uid = inode->i_uid;
175 lsr->lsr_gid = inode->i_gid;
177 /* write setattr log */
178 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
179 rc = llog_add(ctxt, &lsr->lsr_hdr, lsm, logcookies,
180 cookies_size / sizeof(struct llog_cookie),
181 mds_log_fill_setattr_rec);
183 obd_free_memmd(mds->mds_osc_exp, &lsm);
184 OBD_FREE(lsr, sizeof(*lsr));
189 static struct llog_operations mds_ost_orig_logops = {
190 lop_add: mds_llog_origin_add,
191 lop_connect: mds_llog_origin_connect,
194 static struct llog_operations mds_size_repl_logops = {
195 lop_cancel: mds_llog_repl_cancel
198 int mds_llog_init(struct obd_device *obd, struct obd_device *tgt,
199 int count, struct llog_catid *logid)
201 struct obd_device *lov_obd = obd->u.mds.mds_osc_obd;
205 rc = llog_setup(obd, LLOG_MDS_OST_ORIG_CTXT, tgt, 0, NULL,
206 &mds_ost_orig_logops);
210 rc = llog_setup(obd, LLOG_SIZE_REPL_CTXT, tgt, 0, NULL,
211 &mds_size_repl_logops);
215 rc = obd_llog_init(lov_obd, tgt, count, logid);
217 CERROR("error lov_llog_init\n");
222 int mds_llog_finish(struct obd_device *obd, int count)
224 struct llog_ctxt *ctxt;
228 ctxt = llog_get_context(obd, LLOG_MDS_OST_ORIG_CTXT);
230 rc = llog_cleanup(ctxt);
232 ctxt = llog_get_context(obd, LLOG_SIZE_REPL_CTXT);
234 rc2 = llog_cleanup(ctxt);