]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/DiskIO/AIO/AIODiskFile.cc
2 * Copyright (C) 1996-2023 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 "debug/Stream.h"
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, "got failure (" << errno
<< ")");
72 debugs(79, 3, "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! - TODO fix 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
= nullptr;
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) {
136 fatalf("Aiee! aio_read() returned error (%d) TODO fix and wrap file_read !\n", xerrno
);
137 debugs(79, DBG_IMPORTANT
, "WARNING: aio_read() returned error: " << xstrerr(xerrno
));
138 /* fall back to blocking method */
139 // file_read(fd, request->buf, request->len, request->offset, callback, data);
145 AIODiskFile::write(WriteRequest
*request
)
148 async_queue_entry_t
*qe
;
150 assert(strategy
->aq
.aq_state
== AQ_STATE_SETUP
);
152 /* Find a free slot */
153 slot
= strategy
->findSlot();
156 /* No free slot? Callback error, and return */
157 fatal("Aiee! out of aiocb slots TODO fix and wrap file_write !\n");
158 debugs(79, DBG_IMPORTANT
, "WARNING: out of aiocb slots!");
159 /* fall back to blocking method */
160 // file_write(fd, offset, buf, len, callback, data, freefunc);
164 /* Mark slot as ours */
165 qe
= &strategy
->aq
.aq_queue
[slot
];
167 qe
->aq_e_state
= AQ_ENTRY_USED
;
169 qe
->aq_e_callback_data
= cbdataReference(request
);
171 qe
->theFile
= cbdataReference(this);
173 qe
->aq_e_type
= AQ_ENTRY_WRITE
;
175 qe
->aq_e_free
= request
->free_func
;
177 qe
->aq_e_buf
= (void *)request
->buf
;
181 qe
->aq_e_aiocb
.aio_fildes
= fd
;
183 qe
->aq_e_aiocb
.aio_nbytes
= request
->len
;
185 qe
->aq_e_aiocb
.aio_offset
= request
->offset
;
187 qe
->aq_e_aiocb
.aio_buf
= (void *)request
->buf
;
190 ++strategy
->aq
.aq_numpending
;
193 if (aio_write(&qe
->aq_e_aiocb
) < 0) {
195 fatalf("Aiee! aio_write() returned error (%d) TODO fix and wrap file_write !\n", xerrno
);
196 debugs(79, DBG_IMPORTANT
, "WARNING: aio_write() returned error: " << xstrerr(xerrno
));
197 /* fall back to blocking method */
198 // file_write(fd, offset, buf, len, callback, data, freefunc);
203 AIODiskFile::close ()
214 assert (ioRequestor
!= nullptr);
215 ioRequestor
->closeCompleted();
219 AIODiskFile::canRead() const
225 AIODiskFile::canWrite() const
231 AIODiskFile::getFD() const
237 AIODiskFile::error() const
243 AIODiskFile::ioInProgress() const