LTP GCOV extension - code coverage report
Current view: directory - storage/maria - ma_panic.c
Test: maria-mtr.html
Date: 2009-03-04 Instrumented lines: 38
Code covered: 28.9 % Executed lines: 11

       1                 : /* Copyright (C) 2006 MySQL AB & MySQL Finland AB & TCX DataKonsult 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; version 2 of the License.
       6                 : 
       7                 :    This program is distributed in the hope that it will be useful,
       8                 :    but WITHOUT ANY WARRANTY; without even the implied warranty of
       9                 :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      10                 :    GNU General Public License for more details.
      11                 : 
      12                 :    You should have received a copy of the GNU General Public License
      13                 :    along with this program; if not, write to the Free Software
      14                 :    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
      15                 : 
      16                 : #include "ma_fulltext.h"
      17                 : 
      18                 : /*
      19                 :   Stop usage of Maria
      20                 : 
      21                 :   SYNOPSIS
      22                 :      maria_panic()
      23                 :      flag       HA_PANIC_CLOSE:  All maria files (tables and log) are closed.
      24                 :                                  maria_end() is called.
      25                 :                 HA_PANIC_WRITE:  All misam files are unlocked and
      26                 :                                  all changed data in single user maria is
      27                 :                                  written to file
      28                 :                 HA_PANIC_READ    All maria files that was locked when
      29                 :                                  maria_panic(HA_PANIC_WRITE) was done is
      30                 :                                  locked. A maria_readinfo() is done for
      31                 :                                  all single user files to get changes
      32                 :                                  in database
      33                 : 
      34                 :   RETURN
      35                 :     0  ok
      36                 :     #  error number in case of error
      37                 : */
      38                 : 
      39                 : int maria_panic(enum ha_panic_function flag)
      40               4 : {
      41               4 :   int error=0;
      42                 :   LIST *list_element,*next_open;
      43                 :   MARIA_HA *info;
      44               4 :   DBUG_ENTER("maria_panic");
      45                 : 
      46               4 :   if (!maria_inited)
      47               0 :     DBUG_RETURN(0);
      48               4 :   pthread_mutex_lock(&THR_LOCK_maria);
      49               4 :   for (list_element=maria_open_list ; list_element ; list_element=next_open)
      50                 :   {
      51               0 :     next_open=list_element->next;            /* Save if close */
      52               0 :     info=(MARIA_HA*) list_element->data;
      53               0 :     switch (flag) {
      54                 :     case HA_PANIC_CLOSE:
      55                 :       /*
      56                 :         If bad luck (if some tables would be used now, which normally does not
      57                 :         happen in MySQL), as we release the mutex, the list may change and so
      58                 :         we may crash.
      59                 :       */
      60               0 :       pthread_mutex_unlock(&THR_LOCK_maria);
      61               0 :       if (maria_close(info))
      62               0 :         error=my_errno;
      63               0 :       pthread_mutex_lock(&THR_LOCK_maria);
      64               0 :       break;
      65                 :     case HA_PANIC_WRITE:                /* Do this to free databases */
      66                 : #ifdef CANT_OPEN_FILES_TWICE
      67                 :       if (info->s->options & HA_OPTION_READ_ONLY_DATA)
      68                 :         break;
      69                 : #endif
      70               0 :       if (flush_pagecache_blocks(info->s->pagecache, &info->s->kfile,
      71                 :                                  FLUSH_RELEASE))
      72               0 :         error=my_errno;
      73               0 :       if (info->opt_flag & WRITE_CACHE_USED)
      74               0 :         if (flush_io_cache(&info->rec_cache))
      75               0 :           error=my_errno;
      76               0 :       if (info->opt_flag & READ_CACHE_USED)
      77                 :       {
      78               0 :         if (flush_io_cache(&info->rec_cache))
      79               0 :           error=my_errno;
      80               0 :         reinit_io_cache(&info->rec_cache,READ_CACHE,0,
      81                 :                        (pbool) (info->lock_type != F_UNLCK),1);
      82                 :       }
      83               0 :       if (info->lock_type != F_UNLCK && ! info->was_locked)
      84                 :       {
      85               0 :         info->was_locked=info->lock_type;
      86               0 :         if (maria_lock_database(info,F_UNLCK))
      87               0 :           error=my_errno;
      88                 :       }
      89                 : #ifdef CANT_OPEN_FILES_TWICE
      90                 :       if (info->s->kfile.file >= 0 && my_close(info->s->kfile.file, MYF(0)))
      91                 :         error = my_errno;
      92                 :       if (info->dfile.file >= 0 && my_close(info->dfile.file, MYF(0)))
      93                 :         error = my_errno;
      94                 :       info->s->kfile.file= info->dfile.file= -1;/* Files aren't open anymore */
      95                 :       break;
      96                 : #endif
      97                 :     case HA_PANIC_READ:                 /* Restore to before WRITE */
      98                 : #ifdef CANT_OPEN_FILES_TWICE
      99                 :       {                                 /* Open closed files */
     100                 :         char name_buff[FN_REFLEN];
     101                 :         MARIA_SHARE *share= info->s;
     102                 :         if (share->kfile.file < 0)
     103                 :         {
     104                 : 
     105                 :           if ((share->kfile.file= my_open(fn_format(name_buff,
     106                 :                                                     info->filename, "",
     107                 :                                                     N_NAME_IEXT,4),
     108                 :                                           info->mode,
     109                 :                                           MYF(MY_WME))) < 0)
     110                 :             error = my_errno;  
     111                 :         }
     112                 :         if (info->dfile.file < 0)
     113                 :         {
     114                 :           if ((info->dfile.file= my_open(fn_format(name_buff, info->filename,
     115                 :                                                    "", N_NAME_DEXT, 4),
     116                 :                                          info->mode,
     117                 :                                          MYF(MY_WME))) < 0)
     118                 :             error = my_errno;
     119                 :           info->rec_cache.file= info->dfile.file;
     120                 :         }
     121                 :         if (share->bitmap.file.file < 0)
     122                 :           share->bitmap.file.file= info->dfile.file;
     123                 :       }
     124                 : #endif
     125               0 :       if (info->was_locked)
     126                 :       {
     127               0 :         if (maria_lock_database(info, info->was_locked))
     128               0 :           error=my_errno;
     129               0 :         info->was_locked=0;
     130                 :       }
     131                 :       break;
     132                 :     }
     133                 :   }
     134               4 :   pthread_mutex_unlock(&THR_LOCK_maria);
     135               4 :   if (flag == HA_PANIC_CLOSE)
     136               4 :     maria_end();
     137               4 :   if (!error)
     138               4 :     DBUG_RETURN(0);
     139               0 :   DBUG_RETURN(my_errno=error);
     140                 : } /* maria_panic */

Generated by: LTP GCOV extension version 1.4