mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Anton Vorontsov <cbouatmailru@gmail.com>
To: dragos.tatulea@intel.com
Cc: ccross@android.com, keescook@chromium.org, tony.luck@intel.com,
	linux-kernel@vger.kernel.org, adrian.hunter@intel.com,
	octavian.purdila@intel.com
Subject: Re: [PATCH v3 3/9] pstore: add support for external writers
Date: Sat, 17 Nov 2012 18:47:23 -0800	[thread overview]
Message-ID: <20121118024723.GC5556@lizard.sbx05977.paloaca.wayport.net> (raw)
In-Reply-To: <1350558367-31801-4-git-send-email-dragos.tatulea@intel.com>

On Thu, Oct 18, 2012 at 02:06:01PM +0300, dragos.tatulea@intel.com wrote:
> From: Adrian Hunter <adrian.hunter@intel.com>
> 
> Other modules that may wish to write to persistent storage
> are supported by adding a notifier and write function.
> 
> The notifier has 3 events: PSTORE_BEGIN, PSTORE_DUMP and
> PSTORE_END.  External writers use the PSTORE_DUMP event
> whereas the PSTORE_BEGIN and PSTORE_END can be used by
> platform code to ensure the back end is powered up.
> 
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> ---
>  fs/pstore/platform.c   |   88 ++++++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/pstore.h |   43 +++++++++++++++++++----
>  2 files changed, 124 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
> index 9d65723..63ff377 100644
> --- a/fs/pstore/platform.c
> +++ b/fs/pstore/platform.c
[...]
> +/* pstore_write must only be called from PSTORE_DUMP notifier callbacks */
> +int pstore_write(enum pstore_type_id type, const char *buf, size_t size)
> +{
> +	size_t len;
> +	int err = 0, err2;

I guess there is no need for err2 here, you can place it in the while
loop, in the if block.

> +
> +	if (!psinfo)
> +		return -ENODEV;
> +
> +	/*
> +	 * No locking is needed because pstore_write is called only from
> +	 * PSTORE_DUMP notifier callbacks.
> +	 */
> +
> +	if (type != psinfo->ext_type) {
> +		err = pstore_ext_flush();
> +		psinfo->ext_type = type;
> +		psinfo->ext_part = 1;
> +	}
> +
> +	while (size) {
> +		len = min(size, psinfo->bufsize - psinfo->ext_len);
> +		memcpy(psinfo->buf + psinfo->ext_len, buf, len);
> +		psinfo->ext_len += len;
> +		buf += len;
> +		size -= len;
> +		if (psinfo->ext_len == psinfo->bufsize) {
> +			err2 = pstore_ext_flush();
> +			if (err2 && !err)
> +				err = err2;
> +		}
> +	}
> +
> +	return err;
> +}
> +EXPORT_SYMBOL_GPL(pstore_write);
> +
>  module_param(backend, charp, 0444);
>  MODULE_PARM_DESC(backend, "Pstore backend to use");
> diff --git a/include/linux/pstore.h b/include/linux/pstore.h
> index 55ab23f..1bf7f4b 100644
> --- a/include/linux/pstore.h
> +++ b/include/linux/pstore.h
> @@ -40,17 +40,27 @@ enum pstore_type_id {
>  
>  struct module;
>  
> +/* Notifier events */
> +#define PSTORE_BEGIN		1
> +#define PSTORE_DUMP		2
> +#define PSTORE_END		3
> +
>  #define PSTORE_NO_HEADINGS	BIT(0)
>  #define PSTORE_MAX_KMSG_BYTES	BIT(1)
>  
>  struct pstore_info {
> -	struct module	*owner;
> -	char		*name;
> -	unsigned int	flags;
> -	spinlock_t	buf_lock;	/* serialize access to 'buf' */
> -	char		*buf;
> -	size_t		bufsize;
> -	struct mutex	read_mutex;	/* serialize open/read/close */

That's why I don't like "pretty" formatting for structs. :) The change is
unrelated, so please don't do this.

> +	struct module		*owner;
> +	char			*name;
> +	unsigned int		flags;
> +	spinlock_t		buf_lock;	/* serialize access to 'buf' */
> +	char			*buf;
> +	size_t			bufsize;
> +	struct mutex		read_mutex;	/* serialize open/read/close */
> +	u64			ext_id;
> +	size_t			ext_len;
> +	unsigned int		ext_part;
> +	enum pstore_type_id	ext_type;
> +	enum kmsg_dump_reason	ext_reason;
>  	int		(*open)(struct pstore_info *psi);
>  	int		(*close)(struct pstore_info *psi);
>  	ssize_t		(*read)(u64 *id, enum pstore_type_id *type,
> @@ -70,12 +80,31 @@ struct pstore_info {
>  
>  #ifdef CONFIG_PSTORE
>  extern int pstore_register(struct pstore_info *);
> +extern int pstore_notifier_register(struct notifier_block *n);
> +extern int pstore_notifier_unregister(struct notifier_block *n);
> +/* pstore_write must only be called from PSTORE_DUMP notifier callbacks */
> +extern int pstore_write(enum pstore_type_id type, const char *buf, size_t size);
>  #else
>  static inline int
>  pstore_register(struct pstore_info *psi)
>  {
>  	return -ENODEV;
>  }
> +static inline int
> +pstore_notifier_register(struct notifier_block *n)
> +{
> +	return 0;
> +}
> +static inline int
> +pstore_notifier_unregister(struct notifier_block *n)
> +{
> +	return 0;
> +}
> +static inline int
> +pstore_write(enum pstore_type_id type, const char *buf, size_t size)
> +{
> +	return 0;
> +}
>  #endif
>  
>  #endif /*_LINUX_PSTORE_H*/
> -- 
> 1.7.9.5

  reply	other threads:[~2012-11-18  2:50 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-18 11:05 [PATCH v3 0/8] pstore: add interface for dumpers and add task list dumper dragos.tatulea
2012-10-18 11:05 ` [PATCH v3 1/9] pstore: add flags dragos.tatulea
2012-10-18 11:06 ` [PATCH v3 2/9] pstore: add debugfs support for causing dumps and panics dragos.tatulea
2012-11-18  1:53   ` Anton Vorontsov
2012-10-18 11:06 ` [PATCH v3 3/9] pstore: add support for external writers dragos.tatulea
2012-11-18  2:47   ` Anton Vorontsov [this message]
2012-10-18 11:06 ` [PATCH v3 4/9] pstore: allow storing different type id's in ram backend dragos.tatulea
2012-11-18  2:04   ` Anton Vorontsov
2012-10-18 11:06 ` [PATCH v3 5/9] pstore: add task list dumper dragos.tatulea
2012-11-18  2:46   ` Anton Vorontsov
2012-10-18 11:06 ` [PATCH v3 6/9] pstore: do not run timer while pstore is not mounted dragos.tatulea
2012-10-18 11:06 ` [PATCH v3 7/9] pstore: make sure pstore_write exists on flush error dragos.tatulea
2012-11-18  2:40   ` Anton Vorontsov
2012-10-18 11:06 ` [PATCH v3 8/9] pstore: max out console log level during sysfs dump switch dragos.tatulea
2012-11-18  2:44   ` Anton Vorontsov
2012-10-18 11:06 ` [PATCH v3 9/9] pstore: add android log dumping dragos.tatulea

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121118024723.GC5556@lizard.sbx05977.paloaca.wayport.net \
    --to=cbouatmailru@gmail.com \
    --cc=adrian.hunter@intel.com \
    --cc=ccross@android.com \
    --cc=dragos.tatulea@intel.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=octavian.purdila@intel.com \
    --cc=tony.luck@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®