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 (info->opt_flag & WRITE_CACHE_USED)
00052 if (info->rec_cache.flush())
00053 error=errno;
00054 if (info->opt_flag & READ_CACHE_USED)
00055 {
00056 if (info->rec_cache.flush())
00057 error=errno;
00058 info->rec_cache.reinit_io_cache(internal::READ_CACHE,0, (bool) (info->lock_type != F_UNLCK),1);
00059 }
00060 if (info->lock_type != F_UNLCK && ! info->was_locked)
00061 {
00062 info->was_locked=info->lock_type;
00063 if (mi_lock_database(info,F_UNLCK))
00064 error=errno;
00065 }
00066 #ifdef CANT_OPEN_FILES_TWICE
00067 if (info->s->kfile >= 0 && internal::my_close(info->s->kfile,MYF(0)))
00068 error = errno;
00069 if (info->dfile >= 0 && internal::my_close(info->dfile,MYF(0)))
00070 error = errno;
00071 info->s->kfile=info->dfile= -1;
00072 break;
00073 #endif
00074 case HA_PANIC_READ:
00075 #ifdef CANT_OPEN_FILES_TWICE
00076 {
00077 char name_buff[FN_REFLEN];
00078 if (info->s->kfile < 0)
00079 if ((info->s->kfile= internal::my_open(internal::fn_format(name_buff,info->filename,"",
00080 N_NAME_IEXT,4),info->mode,
00081 MYF(MY_WME))) < 0)
00082 error = errno;
00083 if (info->dfile < 0)
00084 {
00085 if ((info->dfile= internal::my_open(internal::fn_format(name_buff,info->filename,"",
00086 N_NAME_DEXT,4),info->mode,
00087 MYF(MY_WME))) < 0)
00088 error = errno;
00089 info->rec_cache.file=info->dfile;
00090 }
00091 }
00092 #endif
00093 if (info->was_locked)
00094 {
00095 if (mi_lock_database(info, info->was_locked))
00096 error=errno;
00097 info->was_locked=0;
00098 }
00099 break;
00100 }
00101 ++it;
00102 }
00103 THR_LOCK_myisam.unlock();
00104 if (!error)
00105 return(0);
00106 return(errno=error);
00107 }