This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / fs / intermezzo / journal_reiserfs.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
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.
9  *
10  *   This file is part of InterMezzo, http://www.inter-mezzo.org.
11  *
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.
15  *
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.
20  *
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.
24  */
25
26 #include <linux/types.h>
27 #include <linux/param.h>
28 #include <linux/sched.h>
29 #include <linux/fs.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>
37 #if 0
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>
42 #endif
43
44 #include "intermezzo_fs.h"
45 #include "intermezzo_psdev.h"
46
47 #if defined(CONFIG_REISERFS_FS) || defined(CONFIG_REISERFS_FS_MODULE)
48
49
50 static loff_t presto_reiserfs_freespace(struct presto_cache *cache,
51                                          struct super_block *sb)
52 {
53         struct reiserfs_super_block * rs = SB_DISK_SUPER_BLOCK (sb);
54         loff_t avail;
55
56         avail =   le32_to_cpu(rs->s_free_blocks) * 
57                 le16_to_cpu(rs->s_blocksize);
58         return avail; 
59 }
60
61 /* start the filesystem journal operations */
62 static void *presto_reiserfs_trans_start(struct presto_file_set *fset, 
63                                    struct inode *inode, 
64                                    int op)
65 {
66         int jblocks;
67         __u32 avail_kmlblocks;
68         struct reiserfs_transaction_handle *th ;
69
70         PRESTO_ALLOC(th, sizeof(*th));
71         if (!th) { 
72                 CERROR("presto: No memory for trans handle\n");
73                 return NULL;
74         }
75
76         avail_kmlblocks = presto_reiserfs_freespace(fset->fset_cache, 
77                                                     inode->i_sb);
78         if ( presto_no_journal(fset) ||
79              strcmp(fset->fset_cache->cache_type, "reiserfs"))
80                 {
81                         CDEBUG(D_JOURNAL, "got cache_type \"%s\"\n",
82                                fset->fset_cache->cache_type);
83                         return NULL;
84                 }
85
86         if ( avail_kmlblocks < 3 ) {
87                 return ERR_PTR(-ENOSPC);
88         }
89         
90         if (  (op != PRESTO_OP_UNLINK && op != PRESTO_OP_RMDIR)
91               && avail_kmlblocks < 6 ) {
92                 return ERR_PTR(-ENOSPC);
93         }            
94
95         jblocks = 3 + JOURNAL_PER_BALANCE_CNT * 4;
96         CDEBUG(D_JOURNAL, "creating journal handle (%d blocks)\n", jblocks);
97
98         lock_kernel();
99         journal_begin(th, inode->i_sb, jblocks);
100         unlock_kernel();
101         return th; 
102 }
103
104 static void presto_reiserfs_trans_commit(struct presto_file_set *fset,
105                                          void *handle)
106 {
107         int jblocks;
108         jblocks = 3 + JOURNAL_PER_BALANCE_CNT * 4;
109         
110         lock_kernel();
111         journal_end(handle, fset->fset_cache->cache_sb, jblocks);
112         unlock_kernel();
113         PRESTO_FREE(handle, sizeof(struct reiserfs_transaction_handle));
114 }
115
116 static void presto_reiserfs_journal_file_data(struct inode *inode)
117 {
118 #ifdef EXT3_JOURNAL_DATA_FL
119         inode->u.ext3_i.i_flags |= EXT3_JOURNAL_DATA_FL;
120 #else
121 #warning You must have a facility to enable journaled writes for recovery!
122 #endif
123 }
124
125 static int presto_reiserfs_has_all_data(struct inode *inode)
126 {
127         BUG();
128         return 0;
129 }
130
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
137 };
138
139 #endif
140 #endif