ablog

不器用で落着きのない技術者のメモ

ASMLib Kernel Driver とは

Project Source Control: ASMLib Kernel Driver - oss.oracle.comソースコードを読める。

 /* -*- mode: c; c-basic-offset: 8; -*-
   2  * vim: noexpandtab sw=8 ts=8 sts=0:
   3  *
   4  * NAME
   5  *      oracleasm.c - ASM library kernel driver.
   6  *
   7  * AUTHOR
   8  *      Joel Becker <joel.becker@oracle.com>
   9  *
  10  * DESCRIPTION
  11  *      This file contains the kernel driver of the Oracle Automatic
  12  *      Storage Managment userspace library.  It provides the routines
  13  *      required to support the userspace library.
  14  *
  15  * MODIFIED   (YYYY/MM/DD)
  16  *      2004/01/02 - Joel Becker <joel.becker@oracle.com>
  17  *              Initial GPL header.
  18  *      2004/09/10 - Joel Becker <joel.becker@oracle.com>
  19  *              First port to 2.6.
  20  *      2004/12/16 - Joel Becker <joel.becker@oracle.com>
  21  *              Change from ioctl to transaction files.
  22  *
  23  * Copyright (c) 2002-2004 Oracle Corporation.  All rights reserved.
  24  *
  25  * This library is free software; you can redistribute it and/or
  26  * modify it under the terms of the GNU General Public
  27  * License, version 2 as published by the Free Software Foundation.
  28  * 
  29  * This library is distributed in the hope that it will be useful,
  30  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  32  * General Public License for more details.
  33  * 
  34  * You should have recieved a copy of the GNU General Public
  35  * License along with this library; if not, write to the
  36  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  37  * Boston, MA 021110-1307, USA.
  38  */
  39 
  40 /*
  41  * This driver's filesystem code is based on the ramfs filesystem.
  42  * Copyright information for the original source appears below.
  43  */
  44 
  45 /* Simple VFS hooks based on: */
  46 /*
  47  * Resizable simple ram filesystem for Linux.
  48  *
  49  * Copyright (C) 2000 Linus Torvalds.
  50  *               2000 Transmeta Corp.
  51  *
  52  * Usage limits added by David Gibson, Linuxcare Australia.
  53  * This file is released under the GPL.
  54  */
  55 
  56 
  57 #include <linux/fs.h>
  58 #include <linux/file.h>
  59 #include <linux/module.h>
  60 #include <linux/pagemap.h>
  61 #include <linux/init.h>
  62 #include <linux/string.h>
  63 #include <linux/highmem.h>
  64 #include <linux/slab.h>
  65 #include <linux/blkdev.h>
  66 #include <linux/mount.h>
  67 #include <linux/smp_lock.h>
  68 #include <linux/parser.h>
  69 #include <linux/backing-dev.h>
  70 
  71 #include <asm/uaccess.h>
  72 #include <linux/spinlock.h>
  73 
  74 #include "linux/oracleasm/compat32.h"
  75 #include "linux/oracleasm/kernel.h"
  76 #include "linux/oracleasm/abi.h"
  77 #include "linux/oracleasm/disk.h"
  78 #include "linux/oracleasm/manager.h"
  79 #include "linux/oracleasm/error.h"
  80 
  81 #include "linux/oracleasm/module_version.h"
  82 
  83 /*
  84  * Modern kernels don't need this.  Older kernels will have it defined
  85  * by the compat code.
  86  */
  87 #ifndef set_i_blksize
  88 # define set_i_blksize(i, bs) do { /* Nothing */ } while (0)
  89 #endif
  90 
  91 
  92 #include "masklog.h"
  93 #include "proc.h"
  94 #if 0
  95 #include "transaction_file.h"
  96 #else
  97 /* XXX ugly for now */
  98 #include "transaction_file.c"
  99 #include "proc.c"
 100 #endif 
 101 
 102 #if PAGE_CACHE_SIZE % 1024
 103 #error Oh no, PAGE_CACHE_SIZE is not divisible by 1k! I cannot cope.
 104 #endif  /* PAGE_CACHE_SIZE % 1024 */
 105 
 106 
 107 
 108 /*
 109  * Compat32
 110  */
 111 #define ASM_BPL_32              32
 112 #if BITS_PER_LONG == 32
 113 # define asm_submit_io_32       asm_submit_io_native
 114 # define asm_maybe_wait_io_32   asm_maybe_wait_io_native
 115 # define asm_complete_ios_32    asm_complete_ios_native
 116 #else
 117 # if BITS_PER_LONG == 64
 118 #  define ASM_BPL_64            64
 119 #  define asm_submit_io_32      asm_submit_io_thunk
 120 #  define asm_submit_io_64      asm_submit_io_native
 121 #  define asm_maybe_wait_io_32  asm_maybe_wait_io_thunk
 122 #  define asm_maybe_wait_io_64  asm_maybe_wait_io_native
 123 #  define asm_complete_ios_32   asm_complete_ios_thunk
 124 #  define asm_complete_ios_64   asm_complete_ios_native
 125 # endif  /* BITS_PER_LONG == 64 */
 126 #endif  /* BITS_PER_LONG == 32 */
 127 
 128 
 129 static struct super_operations asmfs_ops;
 130 static struct file_operations asmfs_dir_operations;
 131 static struct file_operations asmfs_file_operations;
 132 static struct inode_operations asmfs_file_inode_operations;
 133 static struct inode_operations asmfs_disk_dir_inode_operations;
 134 static struct inode_operations asmfs_iid_dir_inode_operations;
 135 
 136 static kmem_cache_t     *asm_request_cachep;
 137 static kmem_cache_t     *asmfs_inode_cachep;
 138 static kmem_cache_t     *asmdisk_cachep;
 139 
 140 /*
 141  * asmfs super-block data in memory
 142  */
 143 struct asmfs_sb_info {
 144         struct super_block *asmfs_super;
 145         /* Prevent races accessing the used block
 146          * counts. Conceptually, this could probably be a semaphore,
 147          * but the only thing we do while holding the lock is
 148          * arithmetic, so there's no point */
 149         spinlock_t asmfs_lock;
 150 
 151         /* It is important that at least the free counts below be
 152            signed.  free_XXX may become negative if a limit is changed
 153            downwards (by a remount) below the current usage. */   
 154 
 155         /* max number of inodes - controls # of instances */
 156         long max_inodes;
 157         /* free_inodes = max_inodes - total number of inodes currently in use */
 158         long free_inodes;
 159 
 160         unsigned long next_iid;
 161 };