journal_reiserfs.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:4k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  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. #include <linux/types.h>
  26. #include <linux/param.h>
  27. #include <linux/sched.h>
  28. #include <linux/fs.h>
  29. #include <linux/slab.h>
  30. #include <linux/vmalloc.h>
  31. #include <linux/stat.h>
  32. #include <linux/errno.h>
  33. #include <linux/smp_lock.h>
  34. #include <linux/locks.h>
  35. #include <asm/segment.h>
  36. #include <asm/uaccess.h>
  37. #include <linux/string.h>
  38. #if 0
  39. #if defined(CONFIG_REISERFS_FS) || defined(CONFIG_REISERFS_FS_MODULE)
  40. #include <linux/reiserfs_fs.h>
  41. #include <linux/reiserfs_fs_sb.h>
  42. #include <linux/reiserfs_fs_i.h>
  43. #endif
  44. #include <linux/intermezzo_fs.h>
  45. #include <linux/intermezzo_psdev.h>
  46. #if defined(CONFIG_REISERFS_FS) || defined(CONFIG_REISERFS_FS_MODULE)
  47. static loff_t presto_reiserfs_freespace(struct presto_cache *cache,
  48.                                          struct super_block *sb)
  49. {
  50.         struct reiserfs_super_block * rs = SB_DISK_SUPER_BLOCK (sb);
  51. loff_t avail;
  52.         avail =   le32_to_cpu(rs->s_free_blocks) * 
  53. le16_to_cpu(rs->s_blocksize);
  54.         return avail; 
  55. }
  56. /* start the filesystem journal operations */
  57. static void *presto_reiserfs_trans_start(struct presto_file_set *fset, 
  58.                                    struct inode *inode, 
  59.                                    int op)
  60. {
  61. int jblocks;
  62.         __u32 avail_kmlblocks;
  63. struct reiserfs_transaction_handle *th ;
  64. PRESTO_ALLOC(th, sizeof(*th));
  65. if (!th) { 
  66. CERROR("presto: No memory for trans handlen");
  67. return NULL;
  68. }
  69.         avail_kmlblocks = presto_reiserfs_freespace(fset->fset_cache, 
  70.     inode->i_sb);
  71.         if ( presto_no_journal(fset) ||
  72.              strcmp(fset->fset_cache->cache_type, "reiserfs"))
  73. {
  74. CDEBUG(D_JOURNAL, "got cache_type "%s"n",
  75.        fset->fset_cache->cache_type);
  76. return NULL;
  77. }
  78.         if ( avail_kmlblocks < 3 ) {
  79.                 return ERR_PTR(-ENOSPC);
  80.         }
  81.         
  82.         if (  (op != PRESTO_OP_UNLINK && op != PRESTO_OP_RMDIR)
  83.               && avail_kmlblocks < 6 ) {
  84.                 return ERR_PTR(-ENOSPC);
  85.         }            
  86. jblocks = 3 + JOURNAL_PER_BALANCE_CNT * 4;
  87.         CDEBUG(D_JOURNAL, "creating journal handle (%d blocks)n", jblocks);
  88. lock_kernel();
  89. journal_begin(th, inode->i_sb, jblocks);
  90. unlock_kernel();
  91. return th; 
  92. }
  93. static void presto_reiserfs_trans_commit(struct presto_file_set *fset,
  94.                                          void *handle)
  95. {
  96. int jblocks;
  97. jblocks = 3 + JOURNAL_PER_BALANCE_CNT * 4;
  98. lock_kernel();
  99. journal_end(handle, fset->fset_cache->cache_sb, jblocks);
  100. unlock_kernel();
  101. PRESTO_FREE(handle, sizeof(struct reiserfs_transaction_handle));
  102. }
  103. static void presto_reiserfs_journal_file_data(struct inode *inode)
  104. {
  105. #ifdef EXT3_JOURNAL_DATA_FL
  106.         inode->u.ext3_i.i_flags |= EXT3_JOURNAL_DATA_FL;
  107. #else
  108. #warning You must have a facility to enable journaled writes for recovery!
  109. #endif
  110. }
  111. static int presto_reiserfs_has_all_data(struct inode *inode)
  112. {
  113.         BUG();
  114.         return 0;
  115. }
  116. struct journal_ops presto_reiserfs_journal_ops = {
  117.         .tr_all_data     = presto_reiserfs_has_all_data,
  118.         .tr_avail        = presto_reiserfs_freespace,
  119.         .tr_start        = presto_reiserfs_trans_start,
  120.         .tr_commit       = presto_reiserfs_trans_commit,
  121.         .tr_journal_data = presto_reiserfs_journal_file_data
  122. };
  123. #endif
  124. #endif