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>
6 * This file is part of InterMezzo, http://www.inter-mezzo.org.
8 * InterMezzo is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * InterMezzo is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with InterMezzo; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <linux/types.h>
23 #include <linux/kernel.h>
24 #include <linux/sched.h>
26 #include <linux/slab.h>
27 #include <linux/vmalloc.h>
28 #include <linux/stat.h>
29 #include <linux/errno.h>
30 #include <asm/segment.h>
31 #include <asm/uaccess.h>
32 #include <linux/string.h>
33 #include <linux/ext2_fs.h>
35 #include "intermezzo_fs.h"
36 #include "intermezzo_psdev.h"
38 #if defined(CONFIG_EXT2_FS)
40 /* EXT2 has no journalling, so these functions do nothing */
41 static loff_t presto_e2_freespace(struct presto_cache *cache,
42 struct super_block *sb)
44 unsigned long freebl = le32_to_cpu(EXT2_SB(sb)->s_es->s_free_blocks_count);
45 unsigned long avail = freebl - le32_to_cpu(EXT2_SB(sb)->s_es->s_r_blocks_count);
46 return (avail << EXT2_BLOCK_SIZE_BITS(sb));
49 /* start the filesystem journal operations */
50 static void *presto_e2_trans_start(struct presto_file_set *fset, struct inode *inode, int op)
52 __u32 avail_kmlblocks;
54 if ( presto_no_journal(fset) ||
55 strcmp(fset->fset_cache->cache_type, "ext2"))
58 avail_kmlblocks = EXT2_SB(inode->i_sb)->s_es->s_free_blocks_count;
60 if ( avail_kmlblocks < 3 ) {
61 return ERR_PTR(-ENOSPC);
64 if ( (op != KML_OPCODE_UNLINK && op != KML_OPCODE_RMDIR)
65 && avail_kmlblocks < 6 ) {
66 return ERR_PTR(-ENOSPC);
71 static void presto_e2_trans_commit(struct presto_file_set *fset, void *handle)
76 static int presto_e2_has_all_data(struct inode *inode)
82 struct journal_ops presto_ext2_journal_ops = {
83 .tr_all_data = presto_e2_has_all_data,
84 .tr_avail = presto_e2_freespace,
85 .tr_start = presto_e2_trans_start,
86 .tr_commit = presto_e2_trans_commit,
87 .tr_journal_data = NULL
90 #endif /* CONFIG_EXT2_FS */