~james-page/ubuntu/precise/mysql-5.5/misc-fixes

« back to all changes in this revision

Viewing changes to storage/perfschema/pfs_instr.cc

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-06-11 07:34:33 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20120611073433-l9za2ni4ipp848y3
Tags: 5.5.24-0ubuntu0.12.04.1
* SECURITY UPDATE: Update to 5.5.24 to fix security issues (LP: #1011371)
  - http://dev.mysql.com/doc/refman/5.5/en/news-5-5-24.html

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
 
1
/* Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
2
2
 
3
3
  This program is free software; you can redistribute it and/or modify
4
4
  it under the terms of the GNU General Public License as published by
802
802
}
803
803
 
804
804
/**
 
805
  Get the hash pins for @filename_hash.
 
806
  @param thread The running thread.
 
807
  @returns The LF_HASH pins for the thread.
 
808
*/
 
809
LF_PINS* get_filename_hash_pins(PFS_thread *thread)
 
810
{
 
811
  if (unlikely(thread->m_filename_hash_pins == NULL))
 
812
  {
 
813
    if (! filename_hash_inited)
 
814
      return NULL;
 
815
    thread->m_filename_hash_pins= lf_hash_get_pins(&filename_hash);
 
816
  }
 
817
  return thread->m_filename_hash_pins;
 
818
}
 
819
 
 
820
/**
805
821
  Find or create instrumentation for a file instance by file name.
806
822
  @param thread                       the executing instrumented thread
807
823
  @param klass                        the file class
816
832
  PFS_file *pfs;
817
833
  PFS_scan scan;
818
834
 
819
 
  if (! filename_hash_inited)
 
835
  LF_PINS *pins= get_filename_hash_pins(thread);
 
836
  if (unlikely(pins == NULL))
820
837
  {
821
 
    /* File instrumentation can be turned off. */
822
838
    file_lost++;
823
839
    return NULL;
824
840
  }
825
841
 
826
 
  if (unlikely(thread->m_filename_hash_pins == NULL))
827
 
  {
828
 
    thread->m_filename_hash_pins= lf_hash_get_pins(&filename_hash);
829
 
    if (unlikely(thread->m_filename_hash_pins == NULL))
830
 
    {
831
 
      file_lost++;
832
 
      return NULL;
833
 
    }
834
 
  }
835
 
 
836
842
  char safe_buffer[FN_REFLEN];
837
843
  const char *safe_filename;
838
844
 
904
910
  /* Append the unresolved file name to the resolved path */
905
911
  char *ptr= buffer + strlen(buffer);
906
912
  char *buf_end= &buffer[sizeof(buffer)-1];
907
 
  if (buf_end > ptr)
 
913
  if ((buf_end > ptr) && (*(ptr-1) != FN_LIBCHAR))
908
914
    *ptr++= FN_LIBCHAR;
909
915
  if (buf_end > ptr)
910
916
    strncpy(ptr, safe_filename + dirlen, buf_end - ptr);
918
924
  const uint retry_max= 3;
919
925
search:
920
926
  entry= reinterpret_cast<PFS_file**>
921
 
    (lf_hash_search(&filename_hash, thread->m_filename_hash_pins,
 
927
    (lf_hash_search(&filename_hash, pins,
922
928
                    normalized_filename, normalized_length));
923
929
  if (entry && (entry != MY_ERRPTR))
924
930
  {
925
931
    pfs= *entry;
926
932
    pfs->m_file_stat.m_open_count++;
927
 
    lf_hash_search_unpin(thread->m_filename_hash_pins);
 
933
    lf_hash_search_unpin(pins);
928
934
    return pfs;
929
935
  }
930
936
 
 
937
  lf_hash_search_unpin(pins);
 
938
 
931
939
  /* filename is not constant, just using it for noise on create */
932
940
  uint random= randomized_index(filename, file_max);
933
941
 
954
962
          reset_single_stat_link(&pfs->m_wait_stat);
955
963
 
956
964
          int res;
957
 
          res= lf_hash_insert(&filename_hash, thread->m_filename_hash_pins,
 
965
          res= lf_hash_insert(&filename_hash, pins,
958
966
                              &pfs);
959
967
          if (likely(res == 0))
960
968
          {
1006
1014
void destroy_file(PFS_thread *thread, PFS_file *pfs)
1007
1015
{
1008
1016
  DBUG_ASSERT(thread != NULL);
1009
 
  DBUG_ASSERT(thread->m_filename_hash_pins != NULL);
1010
1017
  DBUG_ASSERT(pfs != NULL);
1011
 
  lf_hash_delete(&filename_hash, thread->m_filename_hash_pins,
 
1018
 
 
1019
  LF_PINS *pins= get_filename_hash_pins(thread);
 
1020
  DBUG_ASSERT(pins != NULL);
 
1021
 
 
1022
  lf_hash_delete(&filename_hash, pins,
1012
1023
                 pfs->m_filename, pfs->m_filename_length);
1013
1024
  pfs->m_lock.allocated_to_free();
1014
1025
}