From: Jim Cromie <[email protected]>

Add an epilogue to the control-file, to allow display of statistics
etc, without disturbing the header.

NB: epilogue lines should start with "#: " to distinguish them from
lines describing pr_debugs (and from the header line).  No new lines
are added here, only the place to do so.

Signed-off-by: Jim Cromie <[email protected]>
---
v9:
. update ddebug_proc_start() to return EPILOGUE_TOKEN when seeking directly to 
epilogue.
---
 lib/dynamic_debug.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index eb28831a6cb2..406b64d67440 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -1183,6 +1183,9 @@ static struct _ddebug *ddebug_iter_next(struct 
ddebug_iter *iter)
  * read() call from userspace.  Takes the ddebug_lock and
  * seeks the seq_file's iterator to the given position.
  */
+static char ddebug_epilogue_token;
+#define EPILOGUE_TOKEN (&ddebug_epilogue_token)
+
 static void *ddebug_proc_start(struct seq_file *m, loff_t *pos)
 {
        struct ddebug_iter *iter = m->private;
@@ -1198,7 +1201,9 @@ static void *ddebug_proc_start(struct seq_file *m, loff_t 
*pos)
        dp = ddebug_iter_first(iter);
        while (dp != NULL && --n > 0)
                dp = ddebug_iter_next(iter);
-       return dp;
+       if (dp)
+               return dp;
+       return n <= 1 ? EPILOGUE_TOKEN : NULL;
 }
 
 /*
@@ -1211,12 +1216,20 @@ static void *ddebug_proc_next(struct seq_file *m, void 
*p, loff_t *pos)
        struct ddebug_iter *iter = m->private;
        struct _ddebug *dp;
 
+       (*pos)++;
+
+       if (p == EPILOGUE_TOKEN)
+               return NULL;
+
        if (p == SEQ_START_TOKEN)
                dp = ddebug_iter_first(iter);
        else
                dp = ddebug_iter_next(iter);
-       ++*pos;
-       return dp;
+
+       if (dp)
+               return dp;
+
+       return EPILOGUE_TOKEN;
 }
 
 static bool ddebug_class_map_in_range(const int class_id, const struct 
ddebug_class_map *map)
@@ -1268,6 +1281,10 @@ static int ddebug_proc_show(struct seq_file *m, void *p)
                         "# filename:lineno [module]function flags format\n");
                return 0;
        }
+       if (p == EPILOGUE_TOKEN) {
+               /* use this soon */
+               return 0;
+       }
 
        seq_printf(m, "%s:%u [%s]%s =%s \"",
                   trim_prefix(dp->filename), dp->lineno,

-- 
2.55.0



Reply via email to