From: Shachar Sharon Date: Mon, 28 Apr 2025 12:06:59 +0000 (+0300) Subject: profile: collect per-share counters from TDB X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a65ba08c0372f439bb8d06be0246bd0573f6cf12;p=thirdparty%2Fsamba.git profile: collect per-share counters from TDB Helper functions to iterate over per-share profile counters from TDB file using callback function. Signed-off-by: Shachar Sharon Reviewed-by: Volker Lendecke Reviewed-by: Anoop C S --- diff --git a/source3/include/smbprofile.h b/source3/include/smbprofile.h index d900025a6bc..6bdbf6a2180 100644 --- a/source3/include/smbprofile.h +++ b/source3/include/smbprofile.h @@ -751,6 +751,17 @@ void smbprofile_persvc_mkref(int snum, const char *svc, const char *remote); void smbprofile_persvc_unref(int snum); struct profile_stats *smbprofile_persvc_get(int snum); +int smbprofile_persvc_collect(int (*fn)(const char *key, + const struct profile_stats *stats, + void *private_data), + void *private_data); + +int smbprofile_persvc_collect_tdb(struct tdb_context *tdb, + int (*fn)(const char *, + const struct profile_stats *, + void *), + void *userp); + #define START_PROFILE_X(_snum, x) \ struct smbprofile_stats_basic_async __profasync_##x = {}; \ struct smbprofile_stats_basic_async __profasync_persvc_##x = {}; \ diff --git a/source3/profile/profile.c b/source3/profile/profile.c index f01fa999b05..0b87d7b7c0b 100644 --- a/source3/profile/profile.c +++ b/source3/profile/profile.c @@ -540,3 +540,15 @@ static void smbprofile_persvc_dump(void) } } +int smbprofile_persvc_collect(int (*fn)(const char *key, + const struct profile_stats *stats, + void *private_data), + void *private_data) +{ + if (smbprofile_state.internal.db == NULL) { + return 0; + } + return smbprofile_persvc_collect_tdb(smbprofile_state.internal.db->tdb, + fn, + private_data); +} diff --git a/source3/profile/profile_read.c b/source3/profile/profile_read.c index c4b99b80e92..8284e1d81be 100644 --- a/source3/profile/profile_read.c +++ b/source3/profile/profile_read.c @@ -242,3 +242,49 @@ size_t smbprofile_collect_tdb(struct tdb_context *tdb, return state.num_workers; } + +struct smbprofile_persvc_collector { + int (*cb)(const char *, const struct profile_stats *, void *); + void *userp; + int ret; +}; + +static int smbprofile_persvc_collect_fn(struct tdb_context *tdb, + TDB_DATA key, + TDB_DATA value, + void *private_data) +{ + + const struct profile_stats *stats = NULL; + struct smbprofile_persvc_collector *col = NULL; + + if (key.dsize < 5) { + return 0; + } + + if (value.dsize != sizeof(*stats)) { + return 0; + } + + col = (struct smbprofile_persvc_collector *)private_data; + stats = (const struct profile_stats *)(value.dptr); + + col->ret = col->cb((const char *)key.dptr, stats, col->userp); + return (col->ret == 0) ? 0 : -1; +} + +int smbprofile_persvc_collect_tdb(struct tdb_context *tdb, + int (*fn)(const char *, + const struct profile_stats *, + void *), + void *userp) +{ + struct smbprofile_persvc_collector col = { + .cb = fn, + .userp = userp, + .ret = 0, + }; + + tdb_traverse_read(tdb, smbprofile_persvc_collect_fn, &col); + return col.ret; +}