From 52d31963e19d617462689f39b72b06fd28136ea1 Mon Sep 17 00:00:00 2001 From: Jeff Elsloo Date: Mon, 10 May 2021 11:03:34 -0600 Subject: [PATCH 1/2] Adds new TS API TSHttpTxnCacheDiskPathGet (#7783) * Adds new TS API TSHttpTxnCacheDiskPathGet to obtain the path of the disk that contains the requested object. * * Modified API to return path instead of taking a double pointer argument * * Modified TSHttpTxnCacheDiskPathGet to take a length argument that is set to the length of the returned string * * Added a check for length being set to nullptr (cherry picked from commit 7d60962600e0de5331c0c8bbfbedf215b3056d04) --- include/ts/ts.h | 1 + iocore/cache/I_Cache.h | 6 ++++++ iocore/cache/P_CacheInternal.h | 10 ++++++++++ proxy/http/HttpCacheSM.h | 12 ++++++++++++ src/traffic_server/InkAPI.cc | 29 +++++++++++++++++++++++++++++ 5 files changed, 58 insertions(+) diff --git a/include/ts/ts.h b/include/ts/ts.h index a74f65ce145..a6f17af43fa 100644 --- a/include/ts/ts.h +++ b/include/ts/ts.h @@ -2486,6 +2486,7 @@ tsapi TSReturnCode TSHttpTxnCacheLookupStatusSet(TSHttpTxn txnp, int cachelookup tsapi TSReturnCode TSHttpTxnCacheLookupUrlGet(TSHttpTxn txnp, TSMBuffer bufp, TSMLoc obj); tsapi TSReturnCode TSHttpTxnCacheLookupUrlSet(TSHttpTxn txnp, TSMBuffer bufp, TSMLoc obj); tsapi TSReturnCode TSHttpTxnPrivateSessionSet(TSHttpTxn txnp, int private_session); +tsapi const char *TSHttpTxnCacheDiskPathGet(TSHttpTxn txnp, int *length); tsapi int TSHttpTxnBackgroundFillStarted(TSHttpTxn txnp); tsapi int TSHttpTxnIsWebsocket(TSHttpTxn txnp); diff --git a/iocore/cache/I_Cache.h b/iocore/cache/I_Cache.h index d38716a45b0..0586d8c23d7 100644 --- a/iocore/cache/I_Cache.h +++ b/iocore/cache/I_Cache.h @@ -205,6 +205,12 @@ struct CacheVConnection : public VConnection { return -1; } + virtual const char * + get_disk_path() const + { + return nullptr; + } + /** Test if the VC can support pread. @return @c true if @c do_io_pread will work, @c false if not. */ diff --git a/iocore/cache/P_CacheInternal.h b/iocore/cache/P_CacheInternal.h index 70f670537d8..68714b55c0b 100644 --- a/iocore/cache/P_CacheInternal.h +++ b/iocore/cache/P_CacheInternal.h @@ -293,6 +293,16 @@ struct CacheVC : public CacheVConnection { return -1; } + const char * + get_disk_path() const override + { + if (vol && vol->disk) { + return vol->disk->path; + } + + return nullptr; + } + bool is_compressed_in_ram() const override { diff --git a/proxy/http/HttpCacheSM.h b/proxy/http/HttpCacheSM.h index 9add57fa26a..29a66ae144d 100644 --- a/proxy/http/HttpCacheSM.h +++ b/proxy/http/HttpCacheSM.h @@ -138,6 +138,18 @@ class HttpCacheSM : public Continuation return cache_read_vc ? (cache_read_vc->get_volume_number()) : -1; } + const char * + get_disk_path() + { + if (cache_read_vc) { + return cache_read_vc->get_disk_path(); + } else if (cache_write_vc) { + return cache_write_vc->get_disk_path(); + } + + return nullptr; + } + inline void abort_read() { diff --git a/src/traffic_server/InkAPI.cc b/src/traffic_server/InkAPI.cc index ef495cb3d11..95e7cb85681 100644 --- a/src/traffic_server/InkAPI.cc +++ b/src/traffic_server/InkAPI.cc @@ -5551,6 +5551,35 @@ TSHttpTxnIsWebsocket(TSHttpTxn txnp) return sm->t_state.is_websocket; } +const char * +TSHttpTxnCacheDiskPathGet(TSHttpTxn txnp, int *length) +{ + sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); + + HttpSM *s = reinterpret_cast(txnp); + HttpCacheSM *c_sm = &(s->get_cache_sm()); + + if (!c_sm) { + if (length != nullptr) { + *length = 0; + } + + return nullptr; + } + + const char *path = c_sm->get_disk_path(); + + if (length != nullptr) { + if (path != nullptr) { + *length = strlen(path); + } else { + *length = 0; + } + } + + return path; +} + TSReturnCode TSHttpTxnCacheLookupUrlGet(TSHttpTxn txnp, TSMBuffer bufp, TSMLoc obj) { From bb6657bab6dac70338bbc336a43972bf6fddd81d Mon Sep 17 00:00:00 2001 From: "Alan M. Carroll" Date: Mon, 10 May 2021 18:30:08 -0500 Subject: [PATCH 2/2] TSHttpTxnCacheDiskPathGet - tighten up the code a bit. (#7806) (cherry picked from commit 5c39528d2b8e06145cb4fa4ccd0579714cf490b8) --- src/traffic_server/InkAPI.cc | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/traffic_server/InkAPI.cc b/src/traffic_server/InkAPI.cc index 95e7cb85681..09a6bd0ab60 100644 --- a/src/traffic_server/InkAPI.cc +++ b/src/traffic_server/InkAPI.cc @@ -5556,25 +5556,14 @@ TSHttpTxnCacheDiskPathGet(TSHttpTxn txnp, int *length) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); - HttpSM *s = reinterpret_cast(txnp); - HttpCacheSM *c_sm = &(s->get_cache_sm()); - - if (!c_sm) { - if (length != nullptr) { - *length = 0; - } + HttpSM *sm = reinterpret_cast(txnp); + char const *path = nullptr; - return nullptr; + if (HttpCacheSM *c_sm = &(sm->get_cache_sm()); c_sm) { + path = c_sm->get_disk_path(); } - - const char *path = c_sm->get_disk_path(); - - if (length != nullptr) { - if (path != nullptr) { - *length = strlen(path); - } else { - *length = 0; - } + if (length) { + *length = path ? strlen(path) : 0; } return path;