Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753954Ab3G2JoP (ORCPT ); Mon, 29 Jul 2013 05:44:15 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:20604 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751330Ab3G2JoO (ORCPT ); Mon, 29 Jul 2013 05:44:14 -0400 X-IronPort-AV: E=Sophos;i="4.89,768,1367942400"; d="scan'208";a="8057011" Message-ID: <51F6388B.8000308@cn.fujitsu.com> Date: Mon, 29 Jul 2013 17:40:27 +0800 From: Gu Zheng User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110930 Thunderbird/7.0.1 MIME-Version: 1.0 To: Rui Xiang CC: containers@lists.linux-foundation.org, linux-kernel@vger.kernel.org, serge.hallyn@ubuntu.com, ebiederm@xmission.com, akpm@linux-foundation.org, gaofeng@cn.fujitsu.com, libo.chen@huawei.com Subject: Re: [PATCH 1/9] syslog_ns: add syslog_namespace and put/get_syslog_ns References: <1375065080-26740-1-git-send-email-rui.xiang@huawei.com> <1375065080-26740-2-git-send-email-rui.xiang@huawei.com> In-Reply-To: <1375065080-26740-2-git-send-email-rui.xiang@huawei.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/07/29 17:42:03, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/07/29 17:42:03, Serialize complete at 2013/07/29 17:42:03 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=ISO-8859-1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3880 Lines: 131 Hi Rui, Refer to inline:). On 07/29/2013 10:31 AM, Rui Xiang wrote: > Add a struct syslog_namespace which contains the necessary > members for hanlding syslog and realize get_syslog_ns and > put_syslog_ns API. > > Signed-off-by: Rui Xiang > --- > include/linux/syslog.h | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ > kernel/printk.c | 7 ------ > 2 files changed, 68 insertions(+), 7 deletions(-) > > diff --git a/include/linux/syslog.h b/include/linux/syslog.h > index 98a3153..425fafe 100644 > --- a/include/linux/syslog.h > +++ b/include/linux/syslog.h > @@ -21,6 +21,9 @@ > #ifndef _LINUX_SYSLOG_H > #define _LINUX_SYSLOG_H > > +#include > +#include > + > /* Close the log. Currently a NOP. */ > #define SYSLOG_ACTION_CLOSE 0 > /* Open the log. Currently a NOP. */ > @@ -47,6 +50,71 @@ > #define SYSLOG_FROM_READER 0 > #define SYSLOG_FROM_PROC 1 > > +enum log_flags { > + LOG_NOCONS = 1, /* already flushed, do not print to console */ > + LOG_NEWLINE = 2, /* text ended with a newline */ > + LOG_PREFIX = 4, /* text started with a prefix */ > + LOG_CONT = 8, /* text is a fragment of a continuation line */ > +}; > + > +struct syslog_namespace { > + struct kref kref; /* syslog_ns reference count & control */ > + > + raw_spinlock_t logbuf_lock; /* access conflict locker */ > + /* cpu currently holding logbuf_lock of ns */ > + unsigned int logbuf_cpu; > + > + /* index and sequence number of the first record stored in the buffer */ > + u64 log_first_seq; > + u32 log_first_idx; > + > + /* index and sequence number of the next record stored in the buffer */ > + u64 log_next_seq; > + u32 log_next_idx; > + > + /* the next printk record to read after the last 'clear' command */ > + u64 clear_seq; > + u32 clear_idx; > + > + char *log_buf; > + u32 log_buf_len; > + > + /* the next printk record to write to the console */ > + u64 console_seq; > + u32 console_idx; > + > + /* the next printk record to read by syslog(READ) or /proc/kmsg */ > + u64 syslog_seq; > + u32 syslog_idx; > + enum log_flags syslog_prev; > + size_t syslog_partial; > + > + int dmesg_restrict; > +}; > + > +static inline struct syslog_namespace *get_syslog_ns( > + struct syslog_namespace *ns) > +{ > + if (ns) > + kref_get(&ns->kref); > + return ns; > +} > + > +static inline void free_syslog_ns(struct kref *kref) > +{ > + struct syslog_namespace *ns; > + ns = container_of(kref, struct syslog_namespace, kref); > + > + kfree(ns->log_buf); > + kfree(ns); > +} This interface seems a bit ugly, why not use the format like put_syslog_ns()? static inline void free_syslog_ns(struct syslog_namespace *ns) > + > +static inline void put_syslog_ns(struct syslog_namespace *ns) > +{ > + if (ns) > + kref_put(&ns->kref, free_syslog_ns); > +} > + > int do_syslog(int type, char __user *buf, int count, bool from_file); > > #endif /* _LINUX_SYSLOG_H */ > diff --git a/kernel/printk.c b/kernel/printk.c > index d37d45c..7e544bf 100644 > --- a/kernel/printk.c > +++ b/kernel/printk.c > @@ -193,13 +193,6 @@ static int console_may_schedule; > * separated by ',', and find the message after the ';' character. > */ > > -enum log_flags { > - LOG_NOCONS = 1, /* already flushed, do not print to console */ > - LOG_NEWLINE = 2, /* text ended with a newline */ > - LOG_PREFIX = 4, /* text started with a prefix */ > - LOG_CONT = 8, /* text is a fragment of a continuation line */ > -}; > - > struct log { > u64 ts_nsec; /* timestamp in nanoseconds */ > u16 len; /* length of entire record */ -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/