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 <asm/segment.h>
35 #include <asm/uaccess.h>
36 #include <linux/string.h>
38 #if defined(CONFIG_REISERFS_FS) || defined(CONFIG_REISERFS_FS_MODULE)
39 #include <linux/reiserfs_fs.h>
40 #include <linux/reiserfs_fs_sb.h>
41 #include <linux/reiserfs_fs_i.h>
44 #include "intermezzo_fs.h"
45 #include "intermezzo_psdev.h"
47 #if defined(CONFIG_REISERFS_FS) || defined(CONFIG_REISERFS_FS_MODULE)
50 static loff_t presto_reiserfs_freespace(struct presto_cache *cache,
51 struct super_block *sb)
53 struct reiserfs_super_block * rs = SB_DISK_SUPER_BLOCK (sb);
56 avail = le32_to_cpu(rs->s_free_blocks) *
57 le16_to_cpu(rs->s_blocksize);
61 /* start the filesystem journal operations */
62 static void *presto_reiserfs_trans_start(struct presto_file_set *fset,
67 __u32 avail_kmlblocks;
68 struct reiserfs_transaction_handle *th ;
70 PRESTO_ALLOC(th, sizeof(*th));
72 CERROR("presto: No memory for trans handle\n");
76 avail_kmlblocks = presto_reiserfs_freespace(fset->fset_cache,
78 if ( presto_no_journal(fset) ||
79 strcmp(fset->fset_cache->cache_type, "reiserfs"))
81 CDEBUG(D_JOURNAL, "got cache_type \"%s\"\n",
82 fset->fset_cache->cache_type);
86 if ( avail_kmlblocks < 3 ) {
87 return ERR_PTR(-ENOSPC);
90 if ( (op != PRESTO_OP_UNLINK && op != PRESTO_OP_RMDIR)
91 && avail_kmlblocks < 6 ) {
92 return ERR_PTR(-ENOSPC);
95 jblocks = 3 + JOURNAL_PER_BALANCE_CNT * 4;
96 CDEBUG(D_JOURNAL, "creating journal handle (%d blocks)\n", jblocks);
99 journal_begin(th, inode->i_sb, jblocks);
104 static void presto_reiserfs_trans_commit(struct presto_file_set *fset,
108 jblocks = 3 + JOURNAL_PER_BALANCE_CNT * 4;
111 journal_end(handle, fset->fset_cache->cache_sb, jblocks);
113 PRESTO_FREE(handle, sizeof(struct reiserfs_transaction_handle));
116 static void presto_reiserfs_journal_file_data(struct inode *inode)
118 #ifdef EXT3_JOURNAL_DATA_FL
119 inode->u.ext3_i.i_flags |= EXT3_JOURNAL_DATA_FL;
121 #warning You must have a facility to enable journaled writes for recovery!
125 static int presto_reiserfs_has_all_data(struct inode *inode)
131 struct journal_ops presto_reiserfs_journal_ops = {
132 .tr_all_data = presto_reiserfs_has_all_data,
133 .tr_avail = presto_reiserfs_freespace,
134 .tr_start = presto_reiserfs_trans_start,
135 .tr_commit = presto_reiserfs_trans_commit,
136 .tr_journal_data = presto_reiserfs_journal_file_data