From: hno <> Date: Tue, 27 Jun 2000 14:33:53 +0000 (+0000) Subject: Added support for USE_TRUNCATE_NOT_UNLINK to aufs X-Git-Tag: SQUID_3_0_PRE1~1910 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=15a47d1d86d680e29b763cc58faadeee43086703;p=thirdparty%2Fsquid.git Added support for USE_TRUNCATE_NOT_UNLINK to aufs --- diff --git a/src/fs/aufs/aiops.cc b/src/fs/aufs/aiops.cc index e99af58d4c..2138c6accc 100644 --- a/src/fs/aufs/aiops.cc +++ b/src/fs/aufs/aiops.cc @@ -1,5 +1,5 @@ /* - * $Id: aiops.cc,v 1.1 2000/05/03 17:15:46 adrian Exp $ + * $Id: aiops.cc,v 1.2 2000/06/27 08:33:53 hno Exp $ * * DEBUG: section 43 AIOPS * AUTHOR: Stewart Forster @@ -71,6 +71,7 @@ enum _aio_request_type { _AIO_OP_WRITE, _AIO_OP_CLOSE, _AIO_OP_UNLINK, + _AIO_OP_TRUNCATE, _AIO_OP_OPENDIR, _AIO_OP_STAT }; @@ -113,6 +114,7 @@ int aio_read(int, char *, int, off_t, int, aio_result_t *); int aio_write(int, char *, int, off_t, int, aio_result_t *); int aio_close(int, aio_result_t *); int aio_unlink(const char *, aio_result_t *); +int aio_truncate(const char *, off_t length, aio_result_t *); int aio_opendir(const char *, aio_result_t *); aio_result_t *aio_poll_done(); int aio_sync(void); @@ -128,6 +130,7 @@ static void aio_do_write(aio_request_t *); static void aio_do_close(aio_request_t *); static void aio_do_stat(aio_request_t *); static void aio_do_unlink(aio_request_t *); +static void aio_do_truncate(aio_request_t *); #if AIO_OPENDIR static void *aio_do_opendir(aio_request_t *); #endif @@ -281,6 +284,9 @@ aio_thread_loop(void *ptr) case _AIO_OP_UNLINK: aio_do_unlink(request); break; + case _AIO_OP_TRUNCATE: + aio_do_truncate(request); + break; #if AIO_OPENDIR /* Opendir not implemented yet */ case _AIO_OP_OPENDIR: aio_do_opendir(request); @@ -378,6 +384,9 @@ aio_queue_request(aio_request_t * requestp) case _AIO_OP_UNLINK: debug(43, 3) ("aio_queue_request: %d : unlink -> %s\n", i, rp->path); break; + case _AIO_OP_TRUNCATE: + debug(43, 3) ("aio_queue_request: %d : truncate -> %s\n", i, rp->path); + break; case _AIO_OP_STAT: debug(43, 3) ("aio_queue_request: %d : stat -> %s\n", i, rp->path); break; @@ -467,6 +476,7 @@ aio_cleanup_request(aio_request_t * requestp) close(requestp->fd); break; case _AIO_OP_UNLINK: + case _AIO_OP_TRUNCATE: case _AIO_OP_OPENDIR: xfree(requestp->path); break; @@ -737,6 +747,42 @@ aio_do_unlink(aio_request_t * requestp) requestp->err = errno; } +int +aio_truncate(const char *path, off_t length, aio_result_t * resultp) +{ + aio_request_t *requestp; + int len; + + if (!aio_initialised) + aio_init(); + if ((requestp = memPoolAlloc(aio_request_pool)) == NULL) { + errno = ENOMEM; + return -1; + } + len = strlen(path) + 1; + if ((requestp->path = (char *) xmalloc(len)) == NULL) { + memPoolFree(aio_request_pool, requestp); + errno = ENOMEM; + return -1; + } + requestp->offset = length; + strncpy(requestp->path, path, len); + requestp->resultp = resultp; + requestp->request_type = _AIO_OP_TRUNCATE; + requestp->cancelled = 0; + + aio_do_request(requestp); + return 0; +} + + +static void +aio_do_truncate(aio_request_t * requestp) +{ + requestp->ret = truncate(requestp->path, requestp->offset); + requestp->err = errno; +} + #if AIO_OPENDIR /* XXX aio_opendir NOT implemented? */ @@ -901,6 +947,9 @@ aio_debug(aio_request_t * requestp) case _AIO_OP_UNLINK: debug(43, 5) ("UNLINK of %s\n", requestp->path); break; + case _AIO_OP_TRUNCATE: + debug(43, 5) ("UNLINK of %s\n", requestp->path); + break; default: break; } diff --git a/src/fs/aufs/async_io.cc b/src/fs/aufs/async_io.cc index 036f238e54..af8a52b8b1 100644 --- a/src/fs/aufs/async_io.cc +++ b/src/fs/aufs/async_io.cc @@ -1,6 +1,6 @@ /* - * $Id: async_io.cc,v 1.4 2000/06/08 18:05:37 hno Exp $ + * $Id: async_io.cc,v 1.5 2000/06/27 08:33:53 hno Exp $ * * DEBUG: section 32 Asynchronous Disk I/O * AUTHOR: Pete Bentley @@ -42,6 +42,7 @@ #define _AIO_WRITE 2 #define _AIO_CLOSE 3 #define _AIO_UNLINK 4 +#define _AIO_TRUNCATE 4 #define _AIO_OPENDIR 5 #define _AIO_STAT 6 @@ -347,6 +348,34 @@ aioUnlink(const char *pathname, AIOCB * callback, void *callback_data) xfree(path); } /* aioUnlink */ +void +aioTruncate(const char *pathname, off_t length, AIOCB * callback, void *callback_data) +{ + aio_ctrl_t *ctrlp; + char *path; + assert(initialised); + aio_counts.unlink++; + ctrlp = memPoolAlloc(aio_ctrl_pool); + ctrlp->fd = -2; + ctrlp->done_handler = callback; + ctrlp->done_handler_data = callback_data; + ctrlp->operation = _AIO_TRUNCATE; + path = xstrdup(pathname); + cbdataLock(callback_data); + if (aio_truncate(path, length, &ctrlp->result) < 0) { + int ret = truncate(path, length); + if (callback) + (callback) (ctrlp->fd, callback_data, ret, errno); + cbdataUnlock(callback_data); + memPoolFree(aio_ctrl_pool, ctrlp); + xfree(path); + return; + } + ctrlp->next = used_list; + used_list = ctrlp; + xfree(path); +} /* aioTruncate */ + int aioCheckCallbacks(SwapDir * SD) diff --git a/src/fs/aufs/store_asyncufs.h b/src/fs/aufs/store_asyncufs.h index 2385ba5af7..071e1d4f47 100644 --- a/src/fs/aufs/store_asyncufs.h +++ b/src/fs/aufs/store_asyncufs.h @@ -31,6 +31,7 @@ int aio_write(int, char *, int, off_t, int, aio_result_t *); int aio_close(int, aio_result_t *); int aio_stat(const char *, struct stat *, aio_result_t *); int aio_unlink(const char *, aio_result_t *); +int aio_truncate(const char *, off_t length, aio_result_t *); int aio_opendir(const char *, aio_result_t *); aio_result_t *aio_poll_done(void); int aio_operations_pending(void); @@ -47,6 +48,7 @@ void aioWrite(int, int offset, char *, int size, AIOCB *, void *, FREE *); void aioRead(int, int offset, char *, int size, AIOCB *, void *); void aioStat(char *, struct stat *, AIOCB *, void *); void aioUnlink(const char *, AIOCB *, void *); +void aioTruncate(const char *, off_t length, AIOCB *, void *); int aioCheckCallbacks(SwapDir *); void aioSync(SwapDir *); int aioQueueSize(void); diff --git a/src/fs/aufs/store_dir_aufs.cc b/src/fs/aufs/store_dir_aufs.cc index 70e8bf3d62..465cce6d07 100644 --- a/src/fs/aufs/store_dir_aufs.cc +++ b/src/fs/aufs/store_dir_aufs.cc @@ -1,6 +1,6 @@ /* - * $Id: store_dir_aufs.cc,v 1.5 2000/06/26 03:36:13 wessels Exp $ + * $Id: store_dir_aufs.cc,v 1.6 2000/06/27 08:33:53 hno Exp $ * * DEBUG: section 47 Store Directory Routines * AUTHOR: Duane Wessels @@ -1392,7 +1392,11 @@ storeAufsDirUnlinkFile(SwapDir * SD, sfileno f) { debug(79, 3) ("storeAufsDirUnlinkFile: unlinking fileno %08X\n", f); /* storeAufsDirMapBitReset(SD, f); */ +#if USE_TRUNCATE_NOT_UNLINK + aioTruncate(storeAufsDirFullPath(SD, f, NULL), NULL, NULL); +#else aioUnlink(storeAufsDirFullPath(SD, f, NULL), NULL, NULL); +#endif } /*