/********************************************************************//**
Reads or writes data. This operation is asynchronous (aio).
@return DB_SUCCESS, or DB_TABLESPACE_DELETED if we are trying to do
i/o on a tablespace which does not exist */
UNIV_INTERN
ulint
fil_io(
/*===*/
    ulint    type,        /*!< in: OS_FILE_READ or OS_FILE_WRITE,
                ORed to OS_FILE_LOG, if a log i/o
                and ORed to OS_AIO_SIMULATED_WAKE_LATER
                if simulated aio and we want to post a
                batch of i/os; NOTE that a simulated batch
                may introduce hidden chances of deadlocks,
                because i/os are not actually handled until
                all have been posted: use with great
                caution! */
    ibool    sync,        /*!< in: TRUE if synchronous aio is desired */
    ulint    space_id,    /*!< in: space id */
    ulint    zip_size,    /*!< in: compressed page size in bytes;
                0 for uncompressed pages */
    ulint    block_offset,    /*!< in: offset in number of blocks */
    ulint    byte_offset,    /*!< in: remainder of offset in bytes; in
                aio this must be divisible by the OS block
                size */
    ulint    len,        /*!< in: how many bytes to read or write; this
                must not cross a file boundary; in aio this
                must be a block size multiple */
    void*    buf,        /*!< in/out: buffer where to store read data
                or from where to write; in aio this must be
                appropriately aligned */
    void*    message)    /*!< in: message for aio handler if non-sync
                aio used, else ignored */
{
    ulint        mode;
    fil_space_t*    space;
    fil_node_t*    node;
    ulint        offset_high;
    ulint        offset_low;
    ibool        ret;
    ulint        is_log;
    ulint        wake_later;

    is_log = type & OS_FILE_LOG;
    type = type & ~OS_FILE_LOG;

    wake_later = type & OS_AIO_SIMULATED_WAKE_LATER;
    type = type & ~OS_AIO_SIMULATED_WAKE_LATER;

    ut_ad(byte_offset < UNIV_PAGE_SIZE);
    ut_ad(!zip_size || !byte_offset);
    ut_ad(ut_is_2pow(zip_size));
    ut_ad(buf);
    ut_ad(len > );
#if (1 << UNIV_PAGE_SIZE_SHIFT) != UNIV_PAGE_SIZE
# error "(1 << UNIV_PAGE_SIZE_SHIFT) != UNIV_PAGE_SIZE"
#endif
    ut_ad(fil_validate_skip());
#ifndef UNIV_HOTBACKUP
# ifndef UNIV_LOG_DEBUG
    /* ibuf bitmap pages must be read in the sync aio mode: */
    ut_ad(recv_no_ibuf_operations || (type == OS_FILE_WRITE)
          || !ibuf_bitmap_page(zip_size, block_offset)
          || sync || is_log);
# endif /* UNIV_LOG_DEBUG */
    if (sync) {
        mode = OS_AIO_SYNC;
    } else if (is_log) {
        mode = OS_AIO_LOG;
    } else if (type == OS_FILE_READ
           && !recv_no_ibuf_operations
           && ibuf_page(space_id, zip_size, block_offset, NULL)) {
        mode = OS_AIO_IBUF;
    } else {
        mode = OS_AIO_NORMAL;
    }
#else /* !UNIV_HOTBACKUP */
    ut_a(sync);
    mode = OS_AIO_SYNC;
#endif /* !UNIV_HOTBACKUP */

    if (type == OS_FILE_READ) {
        srv_data_read+= len;
    } else if (type == OS_FILE_WRITE) {
        srv_data_written+= len;
    }

    /* Reserve the fil_system mutex and make sure that we can open at
    least one file while holding it, if the file is not already open */

    fil_mutex_enter_and_prepare_for_io(space_id);

    space = fil_space_get_by_id(space_id);

    /* If we are deleting a tablespace we don't allow any read
    operations on that. However, we do allow write operations. */
    if (!space || (type == OS_FILE_READ && space->stop_new_ops)) {
        mutex_exit(&fil_system->mutex);

        ut_print_timestamp(stderr);
        fprintf(stderr,
            "  InnoDB: Error: trying to do i/o"
            " to a tablespace which does not exist.\n"
            "InnoDB: i/o type %lu, space id %lu,"
            " page no. %lu, i/o length %lu bytes\n",
            (ulong) type, (ulong) space_id, (ulong) block_offset,
            (ulong) len);

        return(DB_TABLESPACE_DELETED);
    }

    ut_ad((mode != OS_AIO_IBUF) || (space->purpose == FIL_TABLESPACE));

    node = UT_LIST_GET_FIRST(space->chain);

    for (;;) {
        if (UNIV_UNLIKELY(node == NULL)) {
            fil_report_invalid_page_access(
                block_offset, space_id, space->name,
                byte_offset, len, type);

            ut_error;
        }

         && node->size == ) {
            /* We do not know the size of a single-table tablespace
            before we open the file */

            break;
        }

        if (node->size > block_offset) {
            /* Found! */
            break;
        } else {
            block_offset -= node->size;
            node = UT_LIST_GET_NEXT(chain, node);
        }
    }

    /* Open file if closed */
    fil_node_prepare_for_io(node, fil_system, space);

    /* Check that at least the start offset is within the bounds of a
    single-table tablespace */
    if (UNIV_UNLIKELY(node->size <= block_offset)
        && space->id !=  && space->purpose == FIL_TABLESPACE) {

        fil_report_invalid_page_access(
            block_offset, space_id, space->name, byte_offset,
            len, type);

        ut_error;
    }

    /* Now we have made the changes in the data structures of fil_system */
    mutex_exit(&fil_system->mutex);

    /* Calculate the low 32 bits and the high 32 bits of the file offset */

    if (!zip_size) {
        offset_high = (block_offset >> ( - UNIV_PAGE_SIZE_SHIFT));
        offset_low  = ((block_offset << UNIV_PAGE_SIZE_SHIFT)
                   & 0xFFFFFFFFUL) + byte_offset;

        ut_a(node->size - block_offset
             >= ((byte_offset + len + (UNIV_PAGE_SIZE - ))
             / UNIV_PAGE_SIZE));
    } else {
        ulint    zip_size_shift;
        switch (zip_size) {
        : zip_size_shift = ; break;
        : zip_size_shift = ; break;
        : zip_size_shift = ; break;
        : zip_size_shift = ; break;
        : zip_size_shift = ; break;
        default: ut_error;
        }
        offset_high = block_offset >> ( - zip_size_shift);
        offset_low = (block_offset << zip_size_shift & 0xFFFFFFFFUL)
            + byte_offset;
        ut_a(node->size - block_offset
             >= (len + (zip_size - )) / zip_size);
    }

    /* Do aio */

    ut_a(byte_offset % OS_FILE_LOG_BLOCK_SIZE == );
    ut_a((len % OS_FILE_LOG_BLOCK_SIZE) == );

#ifdef UNIV_HOTBACKUP
    /* In ibbackup do normal i/o, not aio */
    if (type == OS_FILE_READ) {
        ret = os_file_read(node->handle, buf, offset_low, offset_high,len); //详见
    } else {
        ret = os_file_write(node->name, node->handle, buf,
                    offset_low, offset_high, len);
    }
#else
    /* Queue the aio request */
    ret = os_aio(type, mode | wake_later, node->name, node->handle, buf,
             offset_low, offset_high, len, node, message);
#endif
    ut_a(ret);

    if (mode == OS_AIO_SYNC) {
        /* The i/o operation is already completed when we return from
        os_aio: */

        mutex_enter(&fil_system->mutex);

        fil_node_complete_io(node, fil_system, type);

        mutex_exit(&fil_system->mutex);

        ut_ad(fil_validate_skip());
    }

    return(DB_SUCCESS);
}

函数fil_io的更多相关文章

  1. Python 小而美的函数

    python提供了一些有趣且实用的函数,如any all zip,这些函数能够大幅简化我们得代码,可以更优雅的处理可迭代的对象,同时使用的时候也得注意一些情况   any any(iterable) ...

  2. 探究javascript对象和数组的异同,及函数变量缓存技巧

    javascript中最经典也最受非议的一句话就是:javascript中一切皆是对象.这篇重点要提到的,就是任何jser都不陌生的Object和Array. 有段时间曾经很诧异,到底两种数据类型用来 ...

  3. JavaScript权威指南 - 函数

    函数本身就是一段JavaScript代码,定义一次但可能被调用任意次.如果函数挂载在一个对象上,作为对象的一个属性,通常这种函数被称作对象的方法.用于初始化一个新创建的对象的函数被称作构造函数. 相对 ...

  4. C++对C的函数拓展

    一,内联函数 1.内联函数的概念 C++中的const常量可以用来代替宏常数的定义,例如:用const int a = 10来替换# define a 10.那么C++中是否有什么解决方案来替代宏代码 ...

  5. 菜鸟Python学习笔记第一天:关于一些函数库的使用

    2017年1月3日 星期二 大一学习一门新的计算机语言真的很难,有时候连函数拼写出错查错都能查半天,没办法,谁让我英语太渣. 关于计算机语言的学习我想还是从C语言学习开始为好,Python有很多语言的 ...

  6. javascript中的this与函数讲解

    前言 javascript中没有块级作用域(es6以前),javascript中作用域分为函数作用域和全局作用域.并且,大家可以认为全局作用域其实就是Window函数的函数作用域,我们编写的js代码, ...

  7. 复杂的 Hash 函数组合有意义吗?

    很久以前看到一篇文章,讲某个大网站储存用户口令时,会经过十分复杂的处理.怎么个复杂记不得了,大概就是先 Hash,结果加上一些特殊字符再 Hash,结果再加上些字符.再倒序.再怎么怎么的.再 Hash ...

  8. JS核心系列:浅谈函数的作用域

    一.作用域(scope) 所谓作用域就是:变量在声明它们的函数体以及这个函数体嵌套的任意函数体内都是有定义的. function scope(){ var foo = "global&quo ...

  9. C++中的时间函数

    C++获取时间函数众多,何时该用什么函数,拿到的是什么时间?该怎么用?很多人都会混淆. 本文是本人经历了几款游戏客户端和服务器开发后,对游戏中时间获取的一点总结. 最早学习游戏客户端时,为了获取最精确 ...

随机推荐

  1. Careercup - Facebook面试题 - 5733320654585856

    2014-05-02 09:59 题目链接 原题: Group Anagrams input = ["star, astr, car, rac, st"] output = [[& ...

  2. [C#]Linq To Xml 实例操作- 转

    http://blog.sina.com.cn/s/blog_6c762bb301010oi5.html http://blog.xuite.net/cppbuilder/blog/9940157 在 ...

  3. ios map 显示用户位置

    昨天遇到个奇怪的问题,用户的位置在地图中死活不显示,showUserLocation也设置了,最后发现是因为实现了 mapView protocol中的一个方法: -(MKAnnotationView ...

  4. 'mysql' 不是内部或外部命令,也不是可运行的程序或批处理文件的解决办法

    前言: 本文的解决方法来自http://www.cnblogs.com/xionghui/archive/2012/04/11/2442404.html --感谢! 问题描述:新电脑装mysql后在c ...

  5. 牛客最近来了一个新员工Fish,每天早晨总是会拿着一本英文杂志,写些句子在本子上。同事Cat对Fish写的内容颇感兴趣,有一天他向Fish借来翻看,但却读不懂它的意思。例如,“student. a am I”。后来才意识到,这家伙原来把句子单词的顺序翻转了,正确的句子应该是“I am a student.”。Cat对一一的翻转这些单词顺序可不在行,你能帮助他么?

    // test20.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...

  6. AngularJS 基础

    1. AngularJs 是一个JS 框架,是一种基于MVC的设计模式 2. script 需引用 <script src="angular.min.js">,安装包 ...

  7. java socket编程基础(转)

    一,网络编程中两个主要的问题 一个是如何准确的定位网络上一台或多台主机,另一个就是找到主机后如何可靠高效的进行数据传输. 在TCP/IP协议中IP层主要负责网络主机的定位,数据传输的路由,由IP地址可 ...

  8. 配置java环境

    1.下载JDK http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html 2.下载之后ne ...

  9. 利用Qemu Guest Agent (Qemu-ga) 实现 Openstack 监控平台

    经常使用vmWare的同学都知道有vmware-tools这个工具,这个安装在vm内部的工具,可以实现宿主机与虚拟机的通讯,大大增强了虚拟机的性能与功能, 如vmware现在的Unity mode下可 ...

  10. C#中 ? 和?? 的用法

    C#中 ?? 和? 的意思 1.? 如果直接定义一个 值类型,给负值null:就会提示“无法将 Null转换成‘值类型(比如:int)’,因为他是一种不可为null的值 de类型” 例如 int in ...