[1] | 1 | /* Copyright (C) 2000 MySQL AB |
---|
| 2 | |
---|
| 3 | This program is free software; you can redistribute it and/or modify |
---|
| 4 | it under the terms of the GNU General Public License as published by |
---|
| 5 | the Free Software Foundation; either version 2 of the License, or |
---|
| 6 | (at your option) any later version. |
---|
| 7 | |
---|
| 8 | This program is distributed in the hope that it will be useful, |
---|
| 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 11 | GNU General Public License for more details. |
---|
| 12 | |
---|
| 13 | You should have received a copy of the GNU General Public License |
---|
| 14 | along with this program; if not, write to the Free Software |
---|
| 15 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
---|
| 16 | |
---|
| 17 | /* Parser needs these defines always, even if USE_RAID is not defined */ |
---|
| 18 | #define RAID_TYPE_0 1 /* Striping */ |
---|
| 19 | #define RAID_TYPE_x 2 /* Some new modes */ |
---|
| 20 | #define RAID_TYPE_y 3 |
---|
| 21 | |
---|
| 22 | #define RAID_DEFAULT_CHUNKS 4 |
---|
| 23 | #define RAID_DEFAULT_CHUNKSIZE 256*1024 /* 256kB */ |
---|
| 24 | |
---|
| 25 | C_MODE_START |
---|
| 26 | #define my_raid_type(raid_type) raid_type_string[(int)(raid_type)] |
---|
| 27 | extern const char *raid_type_string[]; |
---|
| 28 | C_MODE_END |
---|
| 29 | |
---|
| 30 | #ifdef DONT_USE_RAID |
---|
| 31 | #undef USE_RAID |
---|
| 32 | #endif |
---|
| 33 | #if defined(USE_RAID) |
---|
| 34 | |
---|
| 35 | #include "my_dir.h" |
---|
| 36 | |
---|
| 37 | /* Trap all occurences of my_...() in source and use our wrapper around this function */ |
---|
| 38 | |
---|
| 39 | #ifdef MAP_TO_USE_RAID |
---|
| 40 | #define my_read(A,B,C,D) my_raid_read(A,B,C,D) |
---|
| 41 | #define my_write(A,B,C,D) my_raid_write(A,B,C,D) |
---|
| 42 | #define my_pwrite(A,B,C,D,E) my_raid_pwrite(A,B,C,D,E) |
---|
| 43 | #define my_pread(A,B,C,D,E) my_raid_pread(A,B,C,D,E) |
---|
| 44 | #define my_chsize(A,B,C,D) my_raid_chsize(A,B,C,D) |
---|
| 45 | #define my_close(A,B) my_raid_close(A,B) |
---|
| 46 | #define my_tell(A,B) my_raid_tell(A,B) |
---|
| 47 | #define my_seek(A,B,C,D) my_raid_seek(A,B,C,D) |
---|
| 48 | #define my_lock(A,B,C,D,E) my_raid_lock(A,B,C,D,E) |
---|
| 49 | #define my_fstat(A,B,C) my_raid_fstat(A,B,C) |
---|
| 50 | #endif /* MAP_TO_USE_RAID */ |
---|
| 51 | |
---|
| 52 | #ifdef __cplusplus |
---|
| 53 | extern "C" { |
---|
| 54 | #endif |
---|
| 55 | |
---|
| 56 | void init_raid(void); |
---|
| 57 | void end_raid(void); |
---|
| 58 | |
---|
| 59 | bool is_raid(File fd); |
---|
| 60 | File my_raid_create(const char *FileName, int CreateFlags, int access_flags, |
---|
| 61 | uint raid_type, uint raid_chunks, ulong raid_chunksize, |
---|
| 62 | myf MyFlags); |
---|
| 63 | File my_raid_open(const char *FileName, int Flags, |
---|
| 64 | uint raid_type, uint raid_chunks, ulong raid_chunksize, |
---|
| 65 | myf MyFlags); |
---|
| 66 | int my_raid_rename(const char *from, const char *to, uint raid_chunks, |
---|
| 67 | myf MyFlags); |
---|
| 68 | int my_raid_delete(const char *from, uint raid_chunks, myf MyFlags); |
---|
| 69 | int my_raid_redel(const char *old_name, const char *new_name, |
---|
| 70 | uint raid_chunks, myf MyFlags); |
---|
| 71 | |
---|
| 72 | my_off_t my_raid_seek(File fd, my_off_t pos, int whence, myf MyFlags); |
---|
| 73 | my_off_t my_raid_tell(File fd, myf MyFlags); |
---|
| 74 | |
---|
| 75 | uint my_raid_write(File,const byte *Buffer, uint Count, myf MyFlags); |
---|
| 76 | uint my_raid_read(File Filedes, byte *Buffer, uint Count, myf MyFlags); |
---|
| 77 | |
---|
| 78 | uint my_raid_pread(File Filedes, byte *Buffer, uint Count, my_off_t offset, |
---|
| 79 | myf MyFlags); |
---|
| 80 | uint my_raid_pwrite(int Filedes, const byte *Buffer, uint Count, |
---|
| 81 | my_off_t offset, myf MyFlags); |
---|
| 82 | |
---|
| 83 | int my_raid_lock(File,int locktype, my_off_t start, my_off_t length, |
---|
| 84 | myf MyFlags); |
---|
| 85 | int my_raid_chsize(File fd, my_off_t newlength, int filler, myf MyFlags); |
---|
| 86 | int my_raid_close(File, myf MyFlags); |
---|
| 87 | int my_raid_fstat(int Filedes, struct stat *buf, myf MyFlags); |
---|
| 88 | |
---|
| 89 | #ifdef __cplusplus |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | #ifdef USE_PRAGMA_INTERFACE |
---|
| 93 | #pragma interface /* gcc class implementation */ |
---|
| 94 | #endif |
---|
| 95 | |
---|
| 96 | class RaidName { |
---|
| 97 | public: |
---|
| 98 | RaidName(const char *FileName); |
---|
| 99 | ~RaidName(); |
---|
| 100 | bool IsRaid(); |
---|
| 101 | int Rename(const char * from, const char * to, myf MyFlags); |
---|
| 102 | private: |
---|
| 103 | uint _raid_type; /* RAID_TYPE_0 or RAID_TYPE_1 or RAID_TYPE_5 */ |
---|
| 104 | uint _raid_chunks; /* 1..n */ |
---|
| 105 | ulong _raid_chunksize; /* 1..n in bytes */ |
---|
| 106 | }; |
---|
| 107 | |
---|
| 108 | class RaidFd { |
---|
| 109 | public: |
---|
| 110 | RaidFd(uint raid_type, uint raid_chunks , ulong raid_chunksize); |
---|
| 111 | ~RaidFd(); |
---|
| 112 | File Create(const char *FileName, int CreateFlags, int access_flags, |
---|
| 113 | myf MyFlags); |
---|
| 114 | File Open(const char *FileName, int Flags, myf MyFlags); |
---|
| 115 | my_off_t Seek(my_off_t pos,int whence,myf MyFlags); |
---|
| 116 | my_off_t Tell(myf MyFlags); |
---|
| 117 | int Write(const byte *Buffer, uint Count, myf MyFlags); |
---|
| 118 | int Read(const byte *Buffer, uint Count, myf MyFlags); |
---|
| 119 | int Lock(int locktype, my_off_t start, my_off_t length, myf MyFlags); |
---|
| 120 | int Chsize(File fd, my_off_t newlength, int filler, myf MyFlags); |
---|
| 121 | int Fstat(int fd, MY_STAT *stat_area, myf MyFlags ); |
---|
| 122 | int Close(myf MyFlags); |
---|
| 123 | static bool IsRaid(File fd); |
---|
| 124 | static DYNAMIC_ARRAY _raid_map; /* Map of RaidFD* */ |
---|
| 125 | private: |
---|
| 126 | |
---|
| 127 | uint _raid_type; /* RAID_TYPE_0 or RAID_TYPE_1 or RAID_TYPE_5 */ |
---|
| 128 | uint _raid_chunks; /* 1..n */ |
---|
| 129 | ulong _raid_chunksize; /* 1..n in bytes */ |
---|
| 130 | |
---|
| 131 | ulong _total_block; /* We are operating with block no x (can be 0..many). */ |
---|
| 132 | uint _this_block; /* can be 0.._raid_chunks */ |
---|
| 133 | uint _remaining_bytes; /* Maximum bytes that can be written in this block */ |
---|
| 134 | |
---|
| 135 | my_off_t _position; |
---|
| 136 | my_off_t _size; /* Cached file size for faster seek(SEEK_END) */ |
---|
| 137 | File _fd; |
---|
| 138 | File *_fd_vector; /* Array of File */ |
---|
| 139 | off_t *_seek_vector; /* Array of cached seek positions */ |
---|
| 140 | |
---|
| 141 | inline void Calculate() |
---|
| 142 | { |
---|
| 143 | DBUG_ENTER("RaidFd::_Calculate"); |
---|
| 144 | DBUG_PRINT("info",("_position: %lu _raid_chunksize: %d, _size: %lu", |
---|
| 145 | (ulong) _position, _raid_chunksize, (ulong) _size)); |
---|
| 146 | |
---|
| 147 | _total_block = (ulong) (_position / _raid_chunksize); |
---|
| 148 | _this_block = _total_block % _raid_chunks; /* can be 0.._raid_chunks */ |
---|
| 149 | _remaining_bytes = (uint) (_raid_chunksize - |
---|
| 150 | (_position - _total_block * _raid_chunksize)); |
---|
| 151 | DBUG_PRINT("info", |
---|
| 152 | ("_total_block: %d this_block: %d _remaining_bytes:%d", |
---|
| 153 | _total_block, _this_block, _remaining_bytes)); |
---|
| 154 | DBUG_VOID_RETURN; |
---|
| 155 | } |
---|
| 156 | }; |
---|
| 157 | |
---|
| 158 | #endif /* __cplusplus */ |
---|
| 159 | #endif /* USE_RAID */ |
---|