1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre/smfs/smfs_llog.c
5 * Lustre filesystem abstraction routines
7 * Copyright (C) 2004 Cluster File Systems, Inc.
9 * This file is part of Lustre, http://www.lustre.org.
11 * Lustre is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General Public
13 * License as published by the Free Software Foundation.
15 * Lustre is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Lustre; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #define DEBUG_SUBSYSTEM S_SM
27 #include <linux/lustre_log.h>
28 #include <linux/lustre_fsfilt.h>
29 #include <linux/lustre_smfs.h>
30 #include <linux/lvfs.h>
32 #include "smfs_internal.h"
34 static int smfs_llog_process_rec_cb(struct llog_handle *handle,
35 struct llog_rec_hdr *rec, void *data)
38 struct smfs_proc_args *args = (struct smfs_proc_args *)data;
39 struct lvfs_run_ctxt saved;
42 if (!(le32_to_cpu(handle->lgh_hdr->llh_flags) & LLOG_F_IS_PLAIN)) {
43 CERROR("log is not plain\n");
47 if (le32_to_cpu(rec->lrh_type) == LLOG_GEN_REC) {
48 struct llog_cookie cookie;
50 cookie.lgc_lgl = handle->lgh_id;
51 cookie.lgc_index = le32_to_cpu(rec->lrh_index);
53 llog_cancel(handle->lgh_ctxt, 1, &cookie, 0, NULL);
54 RETURN(LLOG_PROC_BREAK);
57 if (le32_to_cpu(rec->lrh_type) != SMFS_UPDATE_REC)
60 rec_buf = (char*) (rec + 1);
62 if (!S2SMI(args->sr_sb)->smsi_ctxt)
63 GOTO(exit, rc = -ENODEV);
65 push_ctxt(&saved, S2SMI(args->sr_sb)->smsi_ctxt, NULL);
67 /*FIXME later should first unpack the rec,
68 * then call lvfs_reint or lvfs_undo
69 * kml rec format has changed lvfs_reint lvfs_undo should
70 * be rewrite FIXME later*/
71 if (SMFS_DO_REINT_REC(args->sr_flags))
72 rc = lvfs_reint(args->sr_sb, rec_buf);
74 rc = lvfs_undo(args->sr_sb, rec_buf);
76 if (!rc && !SMFS_DO_REC_ALL(args->sr_flags)) {
78 if (args->sr_count == 0)
81 pop_ctxt(&saved, S2SMI(args->sr_sb)->smsi_ctxt, NULL);
86 int smfs_llog_setup(struct super_block *sb, struct vfsmount *mnt)
88 struct llog_ctxt **ctxt = &(S2SMI(sb)->smsi_rec_log);
89 struct lvfs_run_ctxt saved;
90 struct dentry *dentry;
93 /* create OBJECTS and LOGS for writing logs */
98 push_ctxt(&saved, S2SMI(sb)->smsi_ctxt, NULL);
99 dentry = simple_mkdir(current->fs->pwd, "LOGS", 0777, 1);
100 if (IS_ERR(dentry)) {
101 rc = PTR_ERR(dentry);
102 CERROR("cannot create LOGS directory: rc = %d\n", rc);
103 GOTO(exit, rc = -EINVAL);
106 S2SMI(sb)->smsi_logs_dir = dentry;
107 dentry = simple_mkdir(current->fs->pwd, "OBJECTS", 0777, 1);
108 if (IS_ERR(dentry)) {
109 rc = PTR_ERR(dentry);
110 CERROR("cannot create OBJECTS directory: rc = %d\n", rc);
111 GOTO(exit, rc = -EINVAL);
114 S2SMI(sb)->smsi_objects_dir = dentry;
116 /* write log will not write to KML, cleanup kml flags */
117 SMFS_CLEAN_INODE_REC(S2SMI(sb)->smsi_objects_dir->d_inode);
118 SMFS_CLEAN_INODE_REC(S2SMI(sb)->smsi_logs_dir->d_inode);
120 /* log create does not call cache hooks, cleanup hook flags */
121 SMFS_CLEAN_INODE_CACHE_HOOK(S2SMI(sb)->smsi_objects_dir->d_inode);
122 SMFS_CLEAN_INODE_CACHE_HOOK(S2SMI(sb)->smsi_logs_dir->d_inode);
124 if (SMFS_DO_REC(S2SMI(sb))) {
125 rc = llog_catalog_setup(ctxt, KML_LOG_NAME, S2SMI(sb)->smsi_exp,
126 S2SMI(sb)->smsi_ctxt, S2SMI(sb)->sm_fsfilt,
127 S2SMI(sb)->smsi_logs_dir,
128 S2SMI(sb)->smsi_objects_dir);
129 (*ctxt)->llog_proc_cb = smfs_llog_process_rec_cb;
132 if (SMFS_CACHE_HOOK(S2SMI(sb))) {
133 rc2 = cache_space_hook_setup(sb);
138 pop_ctxt(&saved, S2SMI(sb)->smsi_ctxt, NULL);
142 int smfs_llog_cleanup(struct super_block *sb)
144 struct llog_ctxt *ctxt = S2SMI(sb)->smsi_rec_log;
148 if (SMFS_CACHE_HOOK(S2SMI(sb)))
149 rc = cache_space_hook_cleanup();
151 if (SMFS_DO_REC(S2SMI(sb))) {
152 rc2 = llog_catalog_cleanup(ctxt);
153 OBD_FREE(ctxt, sizeof(*ctxt));
158 if (S2SMI(sb)->smsi_logs_dir) {
159 l_dput(S2SMI(sb)->smsi_logs_dir);
160 S2SMI(sb)->smsi_logs_dir = NULL;
162 if (S2SMI(sb)->smsi_objects_dir) {
163 l_dput(S2SMI(sb)->smsi_objects_dir);
164 S2SMI(sb)->smsi_objects_dir = NULL;
169 int smfs_llog_add_rec(struct smfs_super_info * sinfo, void *data, int data_size)
171 struct llog_rec_hdr rec;
174 rec.lrh_len = size_round(data_size);
175 rec.lrh_type = SMFS_UPDATE_REC;
177 rc = llog_add(sinfo->smsi_rec_log, &rec, data, NULL, 0, NULL, NULL, NULL);
179 CERROR("error adding kml rec: %d\n", rc);