• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

I_AIO.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 /****************************************************************************
00025 
00026   Async Disk IO operations.
00027 
00028 
00029 
00030  ****************************************************************************/
00031 #if !defined (_I_AIO_h_)
00032 #define _I_AIO_h_
00033 
00034 #include "libts.h"
00035 #include "I_EventSystem.h"
00036 #include "I_RecProcess.h"
00037 
00038 #define AIO_MODULE_MAJOR_VERSION 1
00039 #define AIO_MODULE_MINOR_VERSION 0
00040 #define AIO_MODULE_VERSION       makeModuleVersion(AIO_MODULE_MAJOR_VERSION,\
00041                                                    AIO_MODULE_MINOR_VERSION,\
00042                                                    PUBLIC_MODULE_HEADER)
00043 
00044 #define AIO_EVENT_DONE           (AIO_EVENT_EVENTS_START+0)
00045 
00046 #define AIO_MODE_AIO             0
00047 #define AIO_MODE_SYNC            1
00048 #define AIO_MODE_THREAD          2
00049 #define AIO_MODE_NATIVE          3
00050 
00051 #if TS_USE_LINUX_NATIVE_AIO
00052 #define AIO_MODE                 AIO_MODE_NATIVE
00053 #else
00054 #define AIO_MODE                 AIO_MODE_THREAD
00055 #endif
00056 
00057 #define LIO_READ        0x1
00058 #define LIO_WRITE       0x2
00059 
00060 #if AIO_MODE == AIO_MODE_NATIVE
00061 
00062 #include <libaio.h>
00063 
00064 #define MAX_AIO_EVENTS 1024
00065 
00066 typedef struct iocb ink_aiocb_t;
00067 typedef struct io_event ink_io_event_t;
00068 
00069 // XXX hokey old-school compatibility with ink_aiocb.h ...
00070 #define aio_nbytes  u.c.nbytes
00071 #define aio_offset  u.c.offset
00072 #define aio_buf     u.c.buf
00073 
00074 #else
00075 
00076 typedef struct ink_aiocb
00077 {
00078   int aio_fildes;
00079   volatile void *aio_buf;       /* buffer location */
00080   size_t aio_nbytes;            /* length of transfer */
00081   off_t aio_offset;             /* file offset */
00082 
00083   int aio_reqprio;              /* request priority offset */
00084   int aio_lio_opcode;           /* listio operation */
00085   int aio_state;                /* state flag for List I/O */
00086   int aio__pad[1];              /* extension padding */
00087 } ink_aiocb_t;
00088 
00089 bool ink_aio_thread_num_set(int thread_num);
00090 
00091 #endif
00092 
00093 // AIOCallback::thread special values
00094 #define AIO_CALLBACK_THREAD_ANY ((EThread*)0) // any regular event thread
00095 #define AIO_CALLBACK_THREAD_AIO ((EThread*)-1)
00096 
00097 #define AIO_LOWEST_PRIORITY      0
00098 #define AIO_DEFAULT_PRIORITY     AIO_LOWEST_PRIORITY
00099 
00100 struct AIOCallback: public Continuation
00101 {
00102   // set before calling aio_read/aio_write
00103   ink_aiocb_t aiocb;
00104   Action action;
00105   EThread *thread;
00106   AIOCallback *then;
00107   // set on return from aio_read/aio_write
00108   int64_t aio_result;
00109 
00110   int ok();
00111   AIOCallback() : thread(AIO_CALLBACK_THREAD_ANY), then(0) {
00112     aiocb.aio_reqprio = AIO_DEFAULT_PRIORITY;
00113   }
00114 };
00115 
00116 #if AIO_MODE == AIO_MODE_NATIVE
00117 
00118 struct AIOVec: public Continuation
00119 {
00120   Action action;
00121   int size;
00122   int completed;
00123   AIOCallback *first;
00124 
00125   AIOVec(int sz, AIOCallback *c): Continuation(new_ProxyMutex()), size(sz), completed(0), first(c)
00126   {
00127     action = c->action;
00128     SET_HANDLER(&AIOVec::mainEvent);
00129   }
00130 
00131   int mainEvent(int event, Event *e);
00132 };
00133 
00134 struct DiskHandler: public Continuation
00135 {
00136   Event *trigger_event;
00137   io_context_t ctx;
00138   ink_io_event_t events[MAX_AIO_EVENTS];
00139   Que(AIOCallback, link) ready_list;
00140   Que(AIOCallback, link) complete_list;
00141   int startAIOEvent(int event, Event *e);
00142   int mainAIOEvent(int event, Event *e);
00143   DiskHandler() {
00144     SET_HANDLER(&DiskHandler::startAIOEvent);
00145     memset(&ctx, 0, sizeof(ctx));
00146     int ret = io_setup(MAX_AIO_EVENTS, &ctx);
00147     if (ret < 0) {
00148       perror("io_setup error");
00149     }
00150   }
00151 };
00152 #endif
00153 
00154 void ink_aio_init(ModuleVersion version);
00155 int ink_aio_start();
00156 void ink_aio_set_callback(Continuation * error_callback);
00157 
00158 int ink_aio_read(AIOCallback *op, int fromAPI = 0);   // fromAPI is a boolean to indicate if this is from a API call such as upload proxy feature
00159 int ink_aio_write(AIOCallback *op, int fromAPI = 0);
00160 int ink_aio_readv(AIOCallback *op, int fromAPI = 0);   // fromAPI is a boolean to indicate if this is from a API call such as upload proxy feature
00161 int ink_aio_writev(AIOCallback *op, int fromAPI = 0);
00162 AIOCallback *new_AIOCallback(void);
00163 #endif

Generated by  doxygen 1.7.1