00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "myisam_priv.h"
00017
00018 using namespace std;
00019 using namespace drizzled;
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 int mi_panic(enum ha_panic_function flag)
00030 {
00031 int error=0;
00032 MI_INFO *info;
00033
00034 THR_LOCK_myisam.lock();
00035 list<MI_INFO *>::iterator it= myisam_open_list.begin();
00036 while (it != myisam_open_list.end())
00037 {
00038 info= *it;
00039 switch (flag) {
00040 case HA_PANIC_CLOSE:
00041 THR_LOCK_myisam.unlock();
00042 if (mi_close(info))
00043 error=errno;
00044 THR_LOCK_myisam.lock();
00045 break;
00046 case HA_PANIC_WRITE:
00047 #ifdef CANT_OPEN_FILES_TWICE
00048 if (info->s->options & HA_OPTION_READ_ONLY_DATA)
00049 break;
00050 #endif
00051 if (flush_key_blocks(info->s->getKeyCache(), info->s->kfile, FLUSH_RELEASE))
00052 error=errno;
00053 if (info->opt_flag & WRITE_CACHE_USED)
00054 if (flush_io_cache(&info->rec_cache))
00055 error=errno;
00056 if (info->opt_flag & READ_CACHE_USED)
00057 {
00058 if (flush_io_cache(&info->rec_cache))
00059 error=errno;
00060 info->rec_cache.reinit_io_cache(internal::READ_CACHE,0, (bool) (info->lock_type != F_UNLCK),1);
00061 }
00062 if (info->lock_type != F_UNLCK && ! info->was_locked)
00063 {
00064 info->was_locked=info->lock_type;
00065 if (mi_lock_database(info,F_UNLCK))
00066 error=errno;
00067 }
00068 #ifdef CANT_OPEN_FILES_TWICE
00069 if (info->s->kfile >= 0 && internal::my_close(info->s->kfile,MYF(0)))
00070 error = errno;
00071 if (info->dfile >= 0 && internal::my_close(info->dfile,MYF(0)))
00072 error = errno;
00073 info->s->kfile=info->dfile= -1;
00074 break;
00075 #endif
00076 case HA_PANIC_READ:
00077 #ifdef CANT_OPEN_FILES_TWICE
00078 {
00079 char name_buff[FN_REFLEN];
00080 if (info->s->kfile < 0)
00081 if ((info->s->kfile= internal::my_open(internal::fn_format(name_buff,info->filename,"",
00082 N_NAME_IEXT,4),info->mode,
00083 MYF(MY_WME))) < 0)
00084 error = errno;
00085 if (info->dfile < 0)
00086 {
00087 if ((info->dfile= internal::my_open(internal::fn_format(name_buff,info->filename,"",
00088 N_NAME_DEXT,4),info->mode,
00089 MYF(MY_WME))) < 0)
00090 error = errno;
00091 info->rec_cache.file=info->dfile;
00092 }
00093 }
00094 #endif
00095 if (info->was_locked)
00096 {
00097 if (mi_lock_database(info, info->was_locked))
00098 error=errno;
00099 info->was_locked=0;
00100 }
00101 break;
00102 }
00103 ++it;
00104 }
00105 THR_LOCK_myisam.unlock();
00106 if (!error)
00107 return(0);
00108 return(errno=error);
00109 }