From patchwork Tue Jul 22 12:13:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 34089 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D505420672 for ; Tue, 22 Jul 2014 12:15:30 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id rp18sf69806940iec.0 for ; Tue, 22 Jul 2014 05:15:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type :content-transfer-encoding; bh=ajnjIJL/e0RTAJE135uKvZKsdhhix/AU5xVJrAXsp2M=; b=Xj3oBBWG5ArMtpedNUEsK4yoKPkVoWb/FhY0HHnnpagD3m+6DUOsW8OvVxKm+clHXZ FKVTSaW50ucO8YJ0OZuTL8xaycXsNE36hfg8Cul4DhK1L4QULvo3EQCPTF76hDfYhfLq sJz+FOvDnkaZnIbqS5Nhzs4bq1lMOmlo8v2KYKLWHJLurdYQjZ3jC+hGnq4FpzZNurf+ bfct0MZfDfW5mMImPBvpHEtyZGVEvJrIZAOB9yG5YymCEMMxZZjkcaXf+tlvPhBRHp6m NavU0PAXnTHHGbISAeDkbjN0/pGAbFVQSKyOnNUYp8OEyrFIjXYFYwdIDgQFkG8KcaCt JZeQ== X-Gm-Message-State: ALoCoQnlyzl4NmqmaGp9+4NogfYKbR7I81Grx3s7oMNdtSQPApsjZOfwAXdZmU8EnJHQD175geUu X-Received: by 10.42.37.71 with SMTP id x7mr12314112icd.4.1406031330213; Tue, 22 Jul 2014 05:15:30 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.20.23 with SMTP id 23ls2242217qgi.26.gmail; Tue, 22 Jul 2014 05:15:30 -0700 (PDT) X-Received: by 10.221.39.132 with SMTP id tm4mr11976433vcb.74.1406031330099; Tue, 22 Jul 2014 05:15:30 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id ym14si335450vdc.50.2014.07.22.05.15.30 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 22 Jul 2014 05:15:30 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.170 as permitted sender) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id lf12so14620987vcb.29 for ; Tue, 22 Jul 2014 05:15:30 -0700 (PDT) X-Received: by 10.52.37.81 with SMTP id w17mr10208239vdj.95.1406031329977; Tue, 22 Jul 2014 05:15:29 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.37.5 with SMTP id tc5csp190824vcb; Tue, 22 Jul 2014 05:15:29 -0700 (PDT) X-Received: by 10.66.97.7 with SMTP id dw7mr11515519pab.114.1406031328771; Tue, 22 Jul 2014 05:15:28 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cc10si106452pdb.488.2014.07.22.05.15.26 for ; Tue, 22 Jul 2014 05:15:26 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755505AbaGVMPX (ORCPT + 12 others); Tue, 22 Jul 2014 08:15:23 -0400 Received: from mail-ig0-f170.google.com ([209.85.213.170]:63727 "EHLO mail-ig0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755348AbaGVMNv (ORCPT ); Tue, 22 Jul 2014 08:13:51 -0400 Received: by mail-ig0-f170.google.com with SMTP id h3so4127821igd.5 for ; Tue, 22 Jul 2014 05:13:50 -0700 (PDT) X-Received: by 10.51.17.104 with SMTP id gd8mr15632841igd.49.1406031230469; Tue, 22 Jul 2014 05:13:50 -0700 (PDT) Received: from localhost.localdomain (c-24-245-18-91.hsd1.mn.comcast.net. [24.245.18.91]) by mx.google.com with ESMTPSA id tp4sm21112991igb.9.2014.07.22.05.13.49 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Jul 2014 05:13:49 -0700 (PDT) From: Alex Elder To: akpm@linux-foundation.org Cc: kay@vrfy.org, pmladek@suse.cz, bp@suse.de, john.stultz@linaro.org, jack@suse.cz, linux-kernel@vger.kernel.org Subject: [PATCH v6 4/7] printk: LOG_CONT and LOG_NEWLINE are opposites Date: Tue, 22 Jul 2014 07:13:47 -0500 Message-Id: <1406031230-18107-5-git-send-email-elder@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1406031230-18107-1-git-send-email-elder@linaro.org> References: <1406031230-18107-1-git-send-email-elder@linaro.org> MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: elder@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.170 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Two log record flags--LOG_CONT and LOG_NEWLINE--are mutually exclusive. That is, one or the other is always set, but they are never both set at the same time in a log record flags field. What follows is a great deal of explanation that aims to prove this assertion. Having that knowledge allows us to simplify a bit of logic, and with a little more work (in follow-on patches) it allows us to do without a flag value, simplifying things. Log record flags are held in the "cont" continuation buffer, as well as in "syslog_prev" and "console_prev". Those are discussed later. Other than that, log record flags are only set in log_store(): msg->flags = flags & 0x1f; There are 5 places log_store() is called: twice from cont_flush(); and three times from vprintk_emit(). Only two single-flag values are ever passed to cont_flush(): LOG_CONT; and LOG_NEWLINE. That passed-in value is provided to log_store() either as-is, or modified to include LOG_NOCONS. There are thus four possible flag combinations supplied to log_store() by cont_flush(): LOG_CONT; LOG_NEWLINE; LOG_CONT|LOG_NOCONS; or LOG_NEWLINE|LOG_NOCONS. The first call vprintk_emit() makes to log_store() passes a flags value of LOG_PREFIX|LOG_NEWLINE. The second and third calls pass a locally-computed "lflags" value, possibly with LOG_CONT added. The only possible flag combinations held in "lflags" are: 0; LOG_NEWLINE; LOG_PREFIX; or LOG_NEWLINE|LOG_PREFIX. If LOG_NEWLINE is not set, LOG_CONT flag is added in the call to log_store(). So there are four possible flag combinations supplied by vprintk_emit(): LOG_CONT; LOG_NEWLINE; LOG_PREFIX|LOG_CONT; or LOG_PREFIX|LOG_NEWLINE. Therefore log_store() is never provided (so never records) a flag value that contains both LOG_CONT and LOG_NEWLINE, and one of those flags is always present. Meanwhile, the "cont" flags field is only ever assigned value 0, or a value passed to cont_flush(). The value of cont.flags is only ever *used* if cont.flushed is true, and that only gets set after the cont.flags field is assigned to the value passed to cont_flush(). As mentioned above, cont_flush() is never provided more than one flag value, and it's always either LOG_NEWLINE or LOG_CONT. Therefore, for all intents and purposes, cont.flags only ever holds LOG_NEWLINE or LOG_CONT. The only values assigned to "syslog_prev" and "console_prev" are the initial value LOG_NEWLINE or the flags value from a log record. So none of these ever hold LOG_CONT and LOG_NEWLINE at the same time. This proves that at LOG_CONT and LOG_NEWLINE are in fact mutually exclusive flags. This patch makes the following changes: - Changes two spots in msg_print_txt() so they no longer bother checking for LOG_NEWLINE once its known that LOG_CONT is set. - Changes two |= assignments in vprintk_emit() to be simple assignments instead, because the result is known to be the same and it makes it obvious no other flags are involved. - Assigns LOG_CONT to "lflags" in vprintk_emit() if it does not contain LOG_NEWLINE (rather than just adding it at the time of the call to log_store()). - Adds a short explanatory comment. Signed-off-by: Alex Elder Reviewed-by: Petr Mládek --- kernel/printk/printk.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c index 847e941..1ff3a05 100644 --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -1010,11 +1010,9 @@ static size_t msg_print_text(const struct printk_log *msg, enum log_flags prev, prefix = false; if (msg->flags & LOG_CONT) { - if ((prev & LOG_CONT) && !(prev & LOG_NEWLINE)) + if (prev & LOG_CONT) prefix = false; - - if (!(msg->flags & LOG_NEWLINE)) - newline = false; + newline = false; } if ((prev & LOG_CONT) && (msg->flags & LOG_PREFIX) && len < size) { @@ -1661,10 +1659,16 @@ asmlinkage int vprintk_emit(int facility, int level, text_len += vscnprintf(text + text_len, sizeof(textbuf) - text_len, fmt, args); - /* mark and strip a trailing newline */ + /* + * If there's a trailing newline, flag it and strip it off. + * Otherwise we assume this is a partial log message, to be + * continued with the next call. + */ if (text_len && text[text_len-1] == '\n') { text_len--; - lflags |= LOG_NEWLINE; + lflags = LOG_NEWLINE; + } else { + lflags = LOG_CONT; } /* strip kernel syslog prefix and extract log level or control flags */ @@ -1694,7 +1698,7 @@ asmlinkage int vprintk_emit(int facility, int level, level = default_message_loglevel; if (dict) - lflags |= LOG_PREFIX|LOG_NEWLINE; + lflags = LOG_PREFIX|LOG_NEWLINE; if (!(lflags & LOG_NEWLINE)) { /* @@ -1708,8 +1712,7 @@ asmlinkage int vprintk_emit(int facility, int level, if (cont_add(facility, level, text, text_len)) printed_len += text_len; else - printed_len += log_store(facility, level, - lflags | LOG_CONT, 0, + printed_len += log_store(facility, level, lflags, 0, dict, dictlen, text, text_len); } else { bool stored = false;