]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
relay: make create_buf_file and remove_buf_file callbacks mandatory
authorJani Nikula <jani.nikula@intel.com>
Wed, 16 Dec 2020 04:45:53 +0000 (20:45 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 16 Dec 2020 06:46:18 +0000 (22:46 -0800)
All clients provide create_buf_file and remove_buf_file callbacks, and
they're required for relay to make sense.  There is no point in them being
optional.

Also document whether each callback is mandatory/optional.

Link: https://lkml.kernel.org/r/88003c1527386b93036e286e7917f1e33aec84ac.1606153547.git.jani.nikula@intel.com
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Suggested-by: Christoph Hellwig <hch@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Kalle Valo <kvalo@codeaurora.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/relay.h
kernel/relay.c

index b3c4f49f69510f600436d7d3aea26aecb7f826dd..99d024475ba51d10eed3fbc51c203142797e59b3 100644 (file)
@@ -89,6 +89,8 @@ struct rchan_callbacks
         * The client should return 1 to continue logging, 0 to stop
         * logging.
         *
+        * This callback is optional.
+        *
         * NOTE: subbuf_start will also be invoked when the buffer is
         *       created, so that the first sub-buffer can be initialized
         *       if necessary.  In this case, prev_subbuf will be NULL.
@@ -122,6 +124,8 @@ struct rchan_callbacks
         * cause relay_open() to create a single global buffer rather
         * than the default set of per-cpu buffers.
         *
+        * This callback is mandatory.
+        *
         * See Documentation/filesystems/relay.rst for more info.
         */
        struct dentry *(*create_buf_file)(const char *filename,
@@ -139,6 +143,8 @@ struct rchan_callbacks
         * channel buffer.
         *
         * The callback should return 0 if successful, negative if not.
+        *
+        * This callback is mandatory.
         */
        int (*remove_buf_file)(struct dentry *dentry);
 };
index d9b8185161a89ce7316cc3f8f2f7c7258133385c..dd4ec4ec07f30ff17f6dce08b003407ee8bb3cef 100644 (file)
@@ -271,26 +271,6 @@ static int subbuf_start_default_callback (struct rchan_buf *buf,
        return 1;
 }
 
-/*
- * create_buf_file_create() default callback.  Does nothing.
- */
-static struct dentry *create_buf_file_default_callback(const char *filename,
-                                                      struct dentry *parent,
-                                                      umode_t mode,
-                                                      struct rchan_buf *buf,
-                                                      int *is_global)
-{
-       return NULL;
-}
-
-/*
- * remove_buf_file() default callback.  Does nothing.
- */
-static int remove_buf_file_default_callback(struct dentry *dentry)
-{
-       return -EINVAL;
-}
-
 /**
  *     wakeup_readers - wake up readers waiting on a channel
  *     @work: contains the channel buffer
@@ -467,10 +447,6 @@ static void setup_callbacks(struct rchan *chan,
 {
        if (!cb->subbuf_start)
                cb->subbuf_start = subbuf_start_default_callback;
-       if (!cb->create_buf_file)
-               cb->create_buf_file = create_buf_file_default_callback;
-       if (!cb->remove_buf_file)
-               cb->remove_buf_file = remove_buf_file_default_callback;
        chan->cb = cb;
 }
 
@@ -530,7 +506,7 @@ struct rchan *relay_open(const char *base_filename,
                return NULL;
        if (subbuf_size > UINT_MAX / n_subbufs)
                return NULL;
-       if (!cb)
+       if (!cb || !cb->create_buf_file || !cb->remove_buf_file)
                return NULL;
 
        chan = kzalloc(sizeof(struct rchan), GFP_KERNEL);