From 99769ac3437f0487d6bc1ebe7f0d701a04133d1c Mon Sep 17 00:00:00 2001 From: Jeff Elsloo Date: Tue, 4 May 2021 17:13:29 -0600 Subject: [PATCH 1/4] Adds new TS API TSHttpTxnCacheDiskPathGet to obtain the path of the disk that contains the requested object. --- 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 | 17 +++++++++++++++++ 5 files changed, 46 insertions(+) diff --git a/include/ts/ts.h b/include/ts/ts.h index d36586701e1..9125a7bb366 100644 --- a/include/ts/ts.h +++ b/include/ts/ts.h @@ -2485,6 +2485,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 TSReturnCode TSHttpTxnCacheDiskPathGet(TSHttpTxn txnp, const char **path); 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 69d26a9461a..19ebb62706d 100644 --- a/iocore/cache/P_CacheInternal.h +++ b/iocore/cache/P_CacheInternal.h @@ -294,6 +294,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 2fc0c0ec2aa..aa00e1923fe 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 ec7ed4e42d1..31dae3fedad 100644 --- a/src/traffic_server/InkAPI.cc +++ b/src/traffic_server/InkAPI.cc @@ -5489,6 +5489,23 @@ TSHttpTxnIsWebsocket(TSHttpTxn txnp) return sm->t_state.is_websocket; } +TSReturnCode +TSHttpTxnCacheDiskPathGet(TSHttpTxn txnp, const char **path) +{ + sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); + + HttpSM *s = reinterpret_cast(txnp); + HttpCacheSM *c_sm = &(s->get_cache_sm()); + + if (!c_sm) { + return TS_ERROR; + } + + *path = c_sm->get_disk_path(); + + return TS_SUCCESS; +} + TSReturnCode TSHttpTxnCacheLookupUrlGet(TSHttpTxn txnp, TSMBuffer bufp, TSMLoc obj) { From 020a093ab362b34647e5e42e437688ca289fd2bc Mon Sep 17 00:00:00 2001 From: Jeff Elsloo Date: Thu, 6 May 2021 11:03:20 -0600 Subject: [PATCH 2/4] * Modified API to return path instead of taking a double pointer argument --- include/ts/ts.h | 2 +- src/traffic_server/InkAPI.cc | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/include/ts/ts.h b/include/ts/ts.h index 9125a7bb366..3862801b2b5 100644 --- a/include/ts/ts.h +++ b/include/ts/ts.h @@ -2485,7 +2485,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 TSReturnCode TSHttpTxnCacheDiskPathGet(TSHttpTxn txnp, const char **path); +tsapi const char *TSHttpTxnCacheDiskPathGet(TSHttpTxn txnp); tsapi int TSHttpTxnBackgroundFillStarted(TSHttpTxn txnp); tsapi int TSHttpTxnIsWebsocket(TSHttpTxn txnp); diff --git a/src/traffic_server/InkAPI.cc b/src/traffic_server/InkAPI.cc index 31dae3fedad..f46b8ed882a 100644 --- a/src/traffic_server/InkAPI.cc +++ b/src/traffic_server/InkAPI.cc @@ -5489,8 +5489,8 @@ TSHttpTxnIsWebsocket(TSHttpTxn txnp) return sm->t_state.is_websocket; } -TSReturnCode -TSHttpTxnCacheDiskPathGet(TSHttpTxn txnp, const char **path) +const char * +TSHttpTxnCacheDiskPathGet(TSHttpTxn txnp) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); @@ -5498,12 +5498,10 @@ TSHttpTxnCacheDiskPathGet(TSHttpTxn txnp, const char **path) HttpCacheSM *c_sm = &(s->get_cache_sm()); if (!c_sm) { - return TS_ERROR; + return nullptr; } - *path = c_sm->get_disk_path(); - - return TS_SUCCESS; + return c_sm->get_disk_path(); } TSReturnCode From b44c9d932f3c4d9fdbdb037d7286d859e260bfe1 Mon Sep 17 00:00:00 2001 From: Jeff Elsloo Date: Fri, 7 May 2021 11:19:49 -0600 Subject: [PATCH 3/4] * Modified TSHttpTxnCacheDiskPathGet to take a length argument that is set to the length of the returned string --- include/ts/ts.h | 2 +- src/traffic_server/InkAPI.cc | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/include/ts/ts.h b/include/ts/ts.h index 3862801b2b5..61e7d45e251 100644 --- a/include/ts/ts.h +++ b/include/ts/ts.h @@ -2485,7 +2485,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); +tsapi const char *TSHttpTxnCacheDiskPathGet(TSHttpTxn txnp, int *length); tsapi int TSHttpTxnBackgroundFillStarted(TSHttpTxn txnp); tsapi int TSHttpTxnIsWebsocket(TSHttpTxn txnp); diff --git a/src/traffic_server/InkAPI.cc b/src/traffic_server/InkAPI.cc index f46b8ed882a..cce110df783 100644 --- a/src/traffic_server/InkAPI.cc +++ b/src/traffic_server/InkAPI.cc @@ -5490,7 +5490,7 @@ TSHttpTxnIsWebsocket(TSHttpTxn txnp) } const char * -TSHttpTxnCacheDiskPathGet(TSHttpTxn txnp) +TSHttpTxnCacheDiskPathGet(TSHttpTxn txnp, int *length) { sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); @@ -5498,10 +5498,19 @@ TSHttpTxnCacheDiskPathGet(TSHttpTxn txnp) HttpCacheSM *c_sm = &(s->get_cache_sm()); if (!c_sm) { + *length = 0; return nullptr; } - return c_sm->get_disk_path(); + const char *path = c_sm->get_disk_path(); + + if (path == nullptr) { + *length = 0; + } else { + *length = strlen(path); + } + + return path; } TSReturnCode From 66113cf6ab857fad1156eab7ea70527244da4aa0 Mon Sep 17 00:00:00 2001 From: Jeff Elsloo Date: Mon, 10 May 2021 09:25:01 -0600 Subject: [PATCH 4/4] * Added a check for length being set to nullptr --- src/traffic_server/InkAPI.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/traffic_server/InkAPI.cc b/src/traffic_server/InkAPI.cc index cce110df783..d4fa9fb8a04 100644 --- a/src/traffic_server/InkAPI.cc +++ b/src/traffic_server/InkAPI.cc @@ -5498,16 +5498,21 @@ TSHttpTxnCacheDiskPathGet(TSHttpTxn txnp, int *length) HttpCacheSM *c_sm = &(s->get_cache_sm()); if (!c_sm) { - *length = 0; + if (length != nullptr) { + *length = 0; + } + return nullptr; } const char *path = c_sm->get_disk_path(); - if (path == nullptr) { - *length = 0; - } else { - *length = strlen(path); + if (length != nullptr) { + if (path != nullptr) { + *length = strlen(path); + } else { + *length = 0; + } } return path;