Commit 023542f4 authored by Jani Nikula's avatar Jani Nikula Committed by Linus Torvalds

relay: allow the use of const callback structs

None of the relay users require the use of mutable structs for callbacks,
however the relay code does.  Instead of assigning the default callback
for subbuf_start, add a wrapper to conditionally call the client callback
if available, and fall back to default behaviour otherwise.

This lets all relay users make their struct rchan_callbacks const data.

[jani.nikula@intel.com: cleanups, per Christoph]
  Link: https://lkml.kernel.org/r/20201124115412.32402-1-jani.nikula@intel.com

Link: https://lkml.kernel.org/r/cc3ff292e4eb4fdc56bee3d690c7b8e39209cd37.1606153547.git.jani.nikula@intel.comSigned-off-by: default avatarJani Nikula <jani.nikula@intel.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Kalle Valo <kvalo@codeaurora.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 371e0388
...@@ -62,7 +62,7 @@ struct rchan ...@@ -62,7 +62,7 @@ struct rchan
size_t subbuf_size; /* sub-buffer size */ size_t subbuf_size; /* sub-buffer size */
size_t n_subbufs; /* number of sub-buffers per buffer */ size_t n_subbufs; /* number of sub-buffers per buffer */
size_t alloc_size; /* total buffer size allocated */ size_t alloc_size; /* total buffer size allocated */
struct rchan_callbacks *cb; /* client callbacks */ const struct rchan_callbacks *cb; /* client callbacks */
struct kref kref; /* channel refcount */ struct kref kref; /* channel refcount */
void *private_data; /* for user-defined data */ void *private_data; /* for user-defined data */
size_t last_toobig; /* tried to log event > subbuf size */ size_t last_toobig; /* tried to log event > subbuf size */
...@@ -157,7 +157,7 @@ struct rchan *relay_open(const char *base_filename, ...@@ -157,7 +157,7 @@ struct rchan *relay_open(const char *base_filename,
struct dentry *parent, struct dentry *parent,
size_t subbuf_size, size_t subbuf_size,
size_t n_subbufs, size_t n_subbufs,
struct rchan_callbacks *cb, const struct rchan_callbacks *cb,
void *private_data); void *private_data);
extern int relay_late_setup_files(struct rchan *chan, extern int relay_late_setup_files(struct rchan *chan,
const char *base_filename, const char *base_filename,
......
...@@ -252,23 +252,14 @@ EXPORT_SYMBOL_GPL(relay_buf_full); ...@@ -252,23 +252,14 @@ EXPORT_SYMBOL_GPL(relay_buf_full);
* High-level relay kernel API and associated functions. * High-level relay kernel API and associated functions.
*/ */
/* static int relay_subbuf_start(struct rchan_buf *buf, void *subbuf,
* rchan_callback implementations defining default channel behavior. Used void *prev_subbuf, size_t prev_padding)
* in place of corresponding NULL values in client callback struct.
*/
/*
* subbuf_start() default callback. Does nothing.
*/
static int subbuf_start_default_callback (struct rchan_buf *buf,
void *subbuf,
void *prev_subbuf,
size_t prev_padding)
{ {
if (relay_buf_full(buf)) if (!buf->chan->cb->subbuf_start)
return 0; return !relay_buf_full(buf);
return 1; return buf->chan->cb->subbuf_start(buf, subbuf,
prev_subbuf, prev_padding);
} }
/** /**
...@@ -314,7 +305,7 @@ static void __relay_reset(struct rchan_buf *buf, unsigned int init) ...@@ -314,7 +305,7 @@ static void __relay_reset(struct rchan_buf *buf, unsigned int init)
for (i = 0; i < buf->chan->n_subbufs; i++) for (i = 0; i < buf->chan->n_subbufs; i++)
buf->padding[i] = 0; buf->padding[i] = 0;
buf->chan->cb->subbuf_start(buf, buf->data, NULL, 0); relay_subbuf_start(buf, buf->data, NULL, 0);
} }
/** /**
...@@ -442,14 +433,6 @@ static void relay_close_buf(struct rchan_buf *buf) ...@@ -442,14 +433,6 @@ static void relay_close_buf(struct rchan_buf *buf)
kref_put(&buf->kref, relay_remove_buf); kref_put(&buf->kref, relay_remove_buf);
} }
static void setup_callbacks(struct rchan *chan,
struct rchan_callbacks *cb)
{
if (!cb->subbuf_start)
cb->subbuf_start = subbuf_start_default_callback;
chan->cb = cb;
}
int relay_prepare_cpu(unsigned int cpu) int relay_prepare_cpu(unsigned int cpu)
{ {
struct rchan *chan; struct rchan *chan;
...@@ -495,7 +478,7 @@ struct rchan *relay_open(const char *base_filename, ...@@ -495,7 +478,7 @@ struct rchan *relay_open(const char *base_filename,
struct dentry *parent, struct dentry *parent,
size_t subbuf_size, size_t subbuf_size,
size_t n_subbufs, size_t n_subbufs,
struct rchan_callbacks *cb, const struct rchan_callbacks *cb,
void *private_data) void *private_data)
{ {
unsigned int i; unsigned int i;
...@@ -529,7 +512,7 @@ struct rchan *relay_open(const char *base_filename, ...@@ -529,7 +512,7 @@ struct rchan *relay_open(const char *base_filename,
chan->has_base_filename = 1; chan->has_base_filename = 1;
strlcpy(chan->base_filename, base_filename, NAME_MAX); strlcpy(chan->base_filename, base_filename, NAME_MAX);
} }
setup_callbacks(chan, cb); chan->cb = cb;
kref_init(&chan->kref); kref_init(&chan->kref);
mutex_lock(&relay_channels_mutex); mutex_lock(&relay_channels_mutex);
...@@ -712,7 +695,7 @@ size_t relay_switch_subbuf(struct rchan_buf *buf, size_t length) ...@@ -712,7 +695,7 @@ size_t relay_switch_subbuf(struct rchan_buf *buf, size_t length)
new_subbuf = buf->subbufs_produced % buf->chan->n_subbufs; new_subbuf = buf->subbufs_produced % buf->chan->n_subbufs;
new = buf->start + new_subbuf * buf->chan->subbuf_size; new = buf->start + new_subbuf * buf->chan->subbuf_size;
buf->offset = 0; buf->offset = 0;
if (!buf->chan->cb->subbuf_start(buf, new, old, buf->prev_padding)) { if (!relay_subbuf_start(buf, new, old, buf->prev_padding)) {
buf->offset = buf->chan->subbuf_size + 1; buf->offset = buf->chan->subbuf_size + 1;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment