1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 1998 Peter J. Braam <braam@clusterfs.com>
5 * Copyright (C) 2000 Red Hat, Inc.
6 * Copyright (C) 2000 Los Alamos National Laboratory
7 * Copyright (C) 2000 TurboLinux, Inc.
8 * Copyright (C) 2001 Mountain View Data, Inc.
10 * This file is part of InterMezzo, http://www.inter-mezzo.org.
12 * InterMezzo is free software; you can redistribute it and/or
13 * modify it under the terms of version 2 of the GNU General Public
14 * License as published by the Free Software Foundation.
16 * InterMezzo is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with InterMezzo; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <linux/types.h>
27 #include <linux/param.h>
28 #include <linux/sched.h>
30 #include <linux/slab.h>
31 #include <linux/vmalloc.h>
32 #include <linux/stat.h>
33 #include <linux/errno.h>
34 #include <linux/smp_lock.h>
35 #include <linux/locks.h>
36 #include <asm/segment.h>
37 #include <asm/uaccess.h>
38 #include <linux/string.h>
40 #if defined(CONFIG_REISERFS_FS) || defined(CONFIG_REISERFS_FS_MODULE)
41 #include <linux/reiserfs_fs.h>
42 #include <linux/reiserfs_fs_sb.h>
43 #include <linux/reiserfs_fs_i.h>
46 #include <linux/intermezzo_fs.h>
47 #include <linux/intermezzo_psdev.h>
49 #if defined(CONFIG_REISERFS_FS) || defined(CONFIG_REISERFS_FS_MODULE)
52 static loff_t presto_reiserfs_freespace(struct presto_cache *cache,
53 struct super_block *sb)
55 struct reiserfs_super_block * rs = SB_DISK_SUPER_BLOCK (sb);
58 avail = le32_to_cpu(rs->s_free_blocks) *
59 le16_to_cpu(rs->s_blocksize);
63 /* start the filesystem journal operations */
64 static void *presto_reiserfs_trans_start(struct presto_file_set *fset,
69 __u32 avail_kmlblocks;
70 struct reiserfs_transaction_handle *th ;
72 PRESTO_ALLOC(th, sizeof(*th));
74 CERROR("presto: No memory for trans handle\n");
78 avail_kmlblocks = presto_reiserfs_freespace(fset->fset_cache,
80 if ( presto_no_journal(fset) ||
81 strcmp(fset->fset_cache->cache_type, "reiserfs"))
83 CDEBUG(D_JOURNAL, "got cache_type \"%s\"\n",
84 fset->fset_cache->cache_type);
88 if ( avail_kmlblocks < 3 ) {
89 return ERR_PTR(-ENOSPC);
92 if ( (op != PRESTO_OP_UNLINK && op != PRESTO_OP_RMDIR)
93 && avail_kmlblocks < 6 ) {
94 return ERR_PTR(-ENOSPC);
97 jblocks = 3 + JOURNAL_PER_BALANCE_CNT * 4;
98 CDEBUG(D_JOURNAL, "creating journal handle (%d blocks)\n", jblocks);
101 journal_begin(th, inode->i_sb, jblocks);
106 static void presto_reiserfs_trans_commit(struct presto_file_set *fset,
110 jblocks = 3 + JOURNAL_PER_BALANCE_CNT * 4;
113 journal_end(handle, fset->fset_cache->cache_sb, jblocks);
115 PRESTO_FREE(handle, sizeof(struct reiserfs_transaction_handle));
118 static void presto_reiserfs_journal_file_data(struct inode *inode)
120 #ifdef EXT3_JOURNAL_DATA_FL
121 inode->u.ext3_i.i_flags |= EXT3_JOURNAL_DATA_FL;
123 #warning You must have a facility to enable journaled writes for recovery!
127 static int presto_reiserfs_has_all_data(struct inode *inode)
133 struct journal_ops presto_reiserfs_journal_ops = {
134 .tr_all_data = presto_reiserfs_has_all_data,
135 .tr_avail = presto_reiserfs_freespace,
136 .tr_start = presto_reiserfs_trans_start,
137 .tr_commit = presto_reiserfs_trans_commit,
138 .tr_journal_data = presto_reiserfs_journal_file_data