From patchwork Wed Aug 7 07:37:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rui Xiang X-Patchwork-Id: 265380 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3A6302C0208 for ; Wed, 7 Aug 2013 17:40:59 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932286Ab3HGHkh (ORCPT ); Wed, 7 Aug 2013 03:40:37 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:45842 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932211Ab3HGHhq (ORCPT ); Wed, 7 Aug 2013 03:37:46 -0400 Received: from 172.24.2.119 (EHLO szxeml209-edg.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.4-GA FastPath queued) with ESMTP id BFQ12514; Wed, 07 Aug 2013 15:37:43 +0800 (CST) Received: from szxeml459-hub.china.huawei.com (10.82.67.202) by szxeml209-edg.china.huawei.com (172.24.2.184) with Microsoft SMTP Server (TLS) id 14.1.323.7; Wed, 7 Aug 2013 15:37:40 +0800 Received: from localhost (10.135.72.188) by szxeml459-hub.china.huawei.com (10.82.67.202) with Microsoft SMTP Server id 14.1.323.7; Wed, 7 Aug 2013 15:37:17 +0800 From: Rui Xiang To: , CC: , , , , , , , , Rui Xiang Subject: [PATCH v3 01/11] syslog_ns: add syslog_namespace and put/get_syslog_ns Date: Wed, 7 Aug 2013 15:37:05 +0800 Message-ID: <1375861035-24320-2-git-send-email-rui.xiang@huawei.com> X-Mailer: git-send-email 1.8.1.msysgit.1 In-Reply-To: <1375861035-24320-1-git-send-email-rui.xiang@huawei.com> References: <1375861035-24320-1-git-send-email-rui.xiang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.135.72.188] X-CFilter-Loop: Reflected Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org 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); +} + +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 69b0890..665cfdc 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 */