]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
profile: collect per-share counters from TDB
authorShachar Sharon <ssharon@redhat.com>
Mon, 28 Apr 2025 12:06:59 +0000 (15:06 +0300)
committerAnoop C S <anoopcs@samba.org>
Mon, 23 Jun 2025 13:04:31 +0000 (13:04 +0000)
Helper functions to iterate over per-share profile counters from TDB
file using callback function.

Signed-off-by: Shachar Sharon <ssharon@redhat.com>
Reviewed-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Anoop C S <anoopcs@samba.org>
source3/include/smbprofile.h
source3/profile/profile.c
source3/profile/profile_read.c

index d900025a6bc0ccee3dc5dbf64f839a2cdd236f14..6bdbf6a2180aca5d689ea211e4a207d396b023ea 100644 (file)
@@ -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 = {};       \
index f01fa999b054ca7ec17248cf4dba1d61d8459848..0b87d7b7c0bed1542e5b0d416e9b0c30c3542db8 100644 (file)
@@ -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);
+}
index c4b99b80e923b96c78d4ab555d7f201656a3a422..8284e1d81be204681d1ba41f9cd23668ec671077 100644 (file)
@@ -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;
+}