]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/DiskIO/AIO/AIODiskFile.cc
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 79 Disk IO Routines */
13 * These routines are simple plugin replacements for the file_* routines
14 * in disk.c . They back-end into the POSIX AIO routines to provide
15 * a nice and simple async IO framework for COSS.
18 * AIO is suitable for COSS - the only sync operations that the standard
19 * supports are read/write, and since COSS works on a single file
20 * per storedir it should work just fine.
25 #include "DiskIO/AIO/AIODiskFile.h"
26 #include "DiskIO/AIO/AIODiskIOStrategy.h"
27 #include "DiskIO/IORequestor.h"
28 #include "DiskIO/ReadRequest.h"
29 #include "DiskIO/WriteRequest.h"
35 CBDATA_CLASS_INIT(AIODiskFile
);
37 AIODiskFile::AIODiskFile(char const *aPath
, AIODiskIOStrategy
*aStrategy
) : fd(-1), closed(true), error_(false)
42 debugs(79, 3, "AIODiskFile::AIODiskFile: " << aPath
);
45 AIODiskFile::~AIODiskFile()
49 AIODiskFile::error(bool const &aBool
)
55 AIODiskFile::open(int flags
, mode_t
, RefCount
<IORequestor
> callback
)
57 /* Simulate async calls */
59 fd
= aio_open(path
.termedBuf(), flags
);
61 fd
= file_open(path
.termedBuf() , flags
);
64 ioRequestor
= callback
;
67 debugs(79, 3, HERE
<< ": got failure (" << errno
<< ")");
72 debugs(79, 3, HERE
<< ": opened FD " << fd
);
75 callback
->ioCompletedNotification();
79 AIODiskFile::create(int flags
, mode_t mode
, RefCount
<IORequestor
> callback
)
81 /* We use the same logic path for open */
82 open(flags
, mode
, callback
);
86 AIODiskFile::read(ReadRequest
*request
)
89 async_queue_entry_t
*qe
;
91 assert(strategy
->aq
.aq_state
== AQ_STATE_SETUP
);
93 /* Find a free slot */
94 slot
= strategy
->findSlot();
97 /* No free slot? Callback error, and return */
98 fatal("Aiee! out of aiocb slots! - FIXME and wrap file_read\n");
99 debugs(79, DBG_IMPORTANT
, "WARNING: out of aiocb slots!");
100 /* fall back to blocking method */
101 // file_read(fd, request->buf, request->len, request->offset, callback, data);
105 /* Mark slot as ours */
106 qe
= &strategy
->aq
.aq_queue
[slot
];
108 qe
->aq_e_state
= AQ_ENTRY_USED
;
110 qe
->aq_e_callback_data
= cbdataReference(request
);
112 qe
->theFile
= cbdataReference(this);
114 qe
->aq_e_type
= AQ_ENTRY_READ
;
116 qe
->aq_e_free
= NULL
;
118 qe
->aq_e_buf
= request
->buf
;
120 qe
->aq_e_fd
= getFD();
122 qe
->aq_e_aiocb
.aio_fildes
= getFD();
124 qe
->aq_e_aiocb
.aio_nbytes
= request
->len
;
126 qe
->aq_e_aiocb
.aio_offset
= request
->offset
;
128 qe
->aq_e_aiocb
.aio_buf
= request
->buf
;
131 ++ strategy
->aq
.aq_numpending
;
134 if (aio_read(&qe
->aq_e_aiocb
) < 0) {
135 fatalf("Aiee! aio_read() returned error (%d) FIXME and wrap file_read !\n", errno
);
136 debugs(79, DBG_IMPORTANT
, "WARNING: aio_read() returned error: " << xstrerror());
137 /* fall back to blocking method */
138 // file_read(fd, request->buf, request->len, request->offset, callback, data);
144 AIODiskFile::write(WriteRequest
*request
)
147 async_queue_entry_t
*qe
;
149 assert(strategy
->aq
.aq_state
== AQ_STATE_SETUP
);
151 /* Find a free slot */
152 slot
= strategy
->findSlot();
155 /* No free slot? Callback error, and return */
156 fatal("Aiee! out of aiocb slots FIXME and wrap file_write !\n");
157 debugs(79, DBG_IMPORTANT
, "WARNING: out of aiocb slots!");
158 /* fall back to blocking method */
159 // file_write(fd, offset, buf, len, callback, data, freefunc);
163 /* Mark slot as ours */
164 qe
= &strategy
->aq
.aq_queue
[slot
];
166 qe
->aq_e_state
= AQ_ENTRY_USED
;
168 qe
->aq_e_callback_data
= cbdataReference(request
);
170 qe
->theFile
= cbdataReference(this);
172 qe
->aq_e_type
= AQ_ENTRY_WRITE
;
174 qe
->aq_e_free
= request
->free_func
;
176 qe
->aq_e_buf
= (void *)request
->buf
;
180 qe
->aq_e_aiocb
.aio_fildes
= fd
;
182 qe
->aq_e_aiocb
.aio_nbytes
= request
->len
;
184 qe
->aq_e_aiocb
.aio_offset
= request
->offset
;
186 qe
->aq_e_aiocb
.aio_buf
= (void *)request
->buf
;
189 ++strategy
->aq
.aq_numpending
;
192 if (aio_write(&qe
->aq_e_aiocb
) < 0) {
193 fatalf("Aiee! aio_write() returned error (%d) FIXME and wrap file_write !\n", errno
);
194 debugs(79, DBG_IMPORTANT
, "WARNING: aio_write() returned error: " << xstrerror());
195 /* fall back to blocking method */
196 // file_write(fd, offset, buf, len, callback, data, freefunc);
201 AIODiskFile::close ()
212 assert (ioRequestor
!= NULL
);
213 ioRequestor
->closeCompleted();
217 AIODiskFile::canRead() const
223 AIODiskFile::canWrite() const
229 AIODiskFile::getFD() const
235 AIODiskFile::error() const
241 AIODiskFile::ioInProgress() const