]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/DiskIO/AIO/AIODiskFile.cc
2 * Copyright (C) 1996-2014 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.
24 #include "AIODiskFile.h"
25 #include "AIODiskIOStrategy.h"
27 #include "DiskIO/IORequestor.h"
28 #include "DiskIO/ReadRequest.h"
29 #include "DiskIO/WriteRequest.h"
34 CBDATA_CLASS_INIT(AIODiskFile
);
36 AIODiskFile::AIODiskFile(char const *aPath
, AIODiskIOStrategy
*aStrategy
) : fd(-1), closed(true), error_(false)
41 debugs(79, 3, "AIODiskFile::AIODiskFile: " << aPath
);
44 AIODiskFile::~AIODiskFile()
48 AIODiskFile::error(bool const &aBool
)
54 AIODiskFile::open(int flags
, mode_t mode
, RefCount
<IORequestor
> callback
)
56 /* Simulate async calls */
58 fd
= aio_open(path
.termedBuf(), flags
);
60 fd
= file_open(path
.termedBuf() , flags
);
63 ioRequestor
= callback
;
66 debugs(79, 3, HERE
<< ": got failure (" << errno
<< ")");
71 debugs(79, 3, HERE
<< ": opened FD " << fd
);
74 callback
->ioCompletedNotification();
78 AIODiskFile::create(int flags
, mode_t mode
, RefCount
<IORequestor
> callback
)
80 /* We use the same logic path for open */
81 open(flags
, mode
, callback
);
85 AIODiskFile::read(ReadRequest
*request
)
88 async_queue_entry_t
*qe
;
90 assert(strategy
->aq
.aq_state
== AQ_STATE_SETUP
);
92 /* Find a free slot */
93 slot
= strategy
->findSlot();
96 /* No free slot? Callback error, and return */
97 fatal("Aiee! out of aiocb slots! - FIXME and wrap file_read\n");
98 debugs(79, DBG_IMPORTANT
, "WARNING: out of aiocb slots!");
99 /* fall back to blocking method */
100 // file_read(fd, request->buf, request->len, request->offset, callback, data);
104 /* Mark slot as ours */
105 qe
= &strategy
->aq
.aq_queue
[slot
];
107 qe
->aq_e_state
= AQ_ENTRY_USED
;
109 qe
->aq_e_callback_data
= cbdataReference(request
);
111 qe
->theFile
= cbdataReference(this);
113 qe
->aq_e_type
= AQ_ENTRY_READ
;
115 qe
->aq_e_free
= NULL
;
117 qe
->aq_e_buf
= request
->buf
;
119 qe
->aq_e_fd
= getFD();
121 qe
->aq_e_aiocb
.aio_fildes
= getFD();
123 qe
->aq_e_aiocb
.aio_nbytes
= request
->len
;
125 qe
->aq_e_aiocb
.aio_offset
= request
->offset
;
127 qe
->aq_e_aiocb
.aio_buf
= request
->buf
;
130 ++ strategy
->aq
.aq_numpending
;
133 if (aio_read(&qe
->aq_e_aiocb
) < 0) {
134 fatalf("Aiee! aio_read() returned error (%d) FIXME and wrap file_read !\n", errno
);
135 debugs(79, DBG_IMPORTANT
, "WARNING: aio_read() returned error: " << xstrerror());
136 /* fall back to blocking method */
137 // file_read(fd, request->buf, request->len, request->offset, callback, data);
143 AIODiskFile::write(WriteRequest
*request
)
146 async_queue_entry_t
*qe
;
148 assert(strategy
->aq
.aq_state
== AQ_STATE_SETUP
);
150 /* Find a free slot */
151 slot
= strategy
->findSlot();
154 /* No free slot? Callback error, and return */
155 fatal("Aiee! out of aiocb slots FIXME and wrap file_write !\n");
156 debugs(79, DBG_IMPORTANT
, "WARNING: out of aiocb slots!");
157 /* fall back to blocking method */
158 // file_write(fd, offset, buf, len, callback, data, freefunc);
162 /* Mark slot as ours */
163 qe
= &strategy
->aq
.aq_queue
[slot
];
165 qe
->aq_e_state
= AQ_ENTRY_USED
;
167 qe
->aq_e_callback_data
= cbdataReference(request
);
169 qe
->theFile
= cbdataReference(this);
171 qe
->aq_e_type
= AQ_ENTRY_WRITE
;
173 qe
->aq_e_free
= request
->free_func
;
175 qe
->aq_e_buf
= (void *)request
->buf
;
179 qe
->aq_e_aiocb
.aio_fildes
= fd
;
181 qe
->aq_e_aiocb
.aio_nbytes
= request
->len
;
183 qe
->aq_e_aiocb
.aio_offset
= request
->offset
;
185 qe
->aq_e_aiocb
.aio_buf
= (void *)request
->buf
;
188 ++strategy
->aq
.aq_numpending
;
191 if (aio_write(&qe
->aq_e_aiocb
) < 0) {
192 fatalf("Aiee! aio_write() returned error (%d) FIXME and wrap file_write !\n", errno
);
193 debugs(79, DBG_IMPORTANT
, "WARNING: aio_write() returned error: " << xstrerror());
194 /* fall back to blocking method */
195 // file_write(fd, offset, buf, len, callback, data, freefunc);
200 AIODiskFile::close ()
211 assert (ioRequestor
!= NULL
);
212 ioRequestor
->closeCompleted();
216 AIODiskFile::canRead() const
222 AIODiskFile::canWrite() const
228 AIODiskFile::getFD() const
234 AIODiskFile::error() const
240 AIODiskFile::ioInProgress() const