Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp32448pxv; Thu, 24 Jun 2021 02:03:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwpXbt3D8VY9t/0dITm6KVJ/L+P2YODU4Cn8XfYa0CSnc5GrNhOKXxD9TLzIyjyTXh0+Cq0 X-Received: by 2002:a17:907:2d07:: with SMTP id gs7mr4204626ejc.375.1624525381083; Thu, 24 Jun 2021 02:03:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624525381; cv=none; d=google.com; s=arc-20160816; b=IZxSdPI5f8GkrsOBJ/QTgttUN4EampbQfn9SYgmwRpVbz3uHUyhb/X2sB2OLtMRRP2 5T0508JjOaXdclWscfxF0AnDYvlJsnV/NifX6g8A3Y3RULKQUoP/rcZCStVfplgiCoc2 dWpzppQ66cxv99PrHGwsXnBFuGsFU0nIhjYDigkVD1xnzd9RDKZ5PRgDRL/7bPX6Avnf SmKX4pdF4y7+iYkkf3QlZPEF3CNGO9xibk3br+L4+fSDMB5KdWdOWZPopbjjUqEdTyj/ 0IxyCNUpH2yf4QXkZpVacztlb8MKyTin4v7RqFmuxuzlLmv4J0LIgQQ7VhD7yqDDgBok 2JAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=gOxneZwjI52NGf5YtOkngslNEIWH7cmjZeAOERs/N1o=; b=s7p5RrcuftyxcM5KGmBXZ0oN6Ti9fUmMzUtOmTGsU3NL1m7o/q9GSmM2Ffawwl1aUr 29PUYwfUw/JoBGE8LUW+AXsr/BGnpPVrCS2AyGfG7gpWCWKjxSnesirCScLMv2FgXFek 9T0icNsqgebvdDlkhfzJe20uze29w6LrdwQ+RyG/teC5i62nIoqjfQghFPO9wvggrIfg eH8cKZZVCWH17GB+7dmlqs3Iid8EklZfL/s8XLbgwoDZOW489ig559TjLVUwWjdi2Dia Piym0w42Z4aHWOPy3ez9hO8WUJ3eFAwfiSBDJtH8sEznR5InAxFIQ2gTVQ4JBG7iBkJH NFVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=qVGFmIBZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a14si2510755edt.405.2021.06.24.02.02.38; Thu, 24 Jun 2021 02:03:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=qVGFmIBZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230122AbhFXJD4 (ORCPT + 99 others); Thu, 24 Jun 2021 05:03:56 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:56832 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229918AbhFXJDw (ORCPT ); Thu, 24 Jun 2021 05:03:52 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 04E8C1FD67; Thu, 24 Jun 2021 09:01:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1624525293; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gOxneZwjI52NGf5YtOkngslNEIWH7cmjZeAOERs/N1o=; b=qVGFmIBZsXtc/KT5jd285fvitzFu/HscGDU/99JWXqmysYTcbcTp9+7CHCAIoQ7Zd/SQN4 +Pmf2DguX4xoL3fBRQ/m7U6Z6ksPr+Ksf1Khn7T7GuSn2N7GVrujAgMmsVGNcme+KhAQIX OmFu0wLVuZuu+Neo77oDGjco/guIs3A= Received: from suse.cz (unknown [10.100.224.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 9C85AA3B91; Thu, 24 Jun 2021 09:01:32 +0000 (UTC) Date: Thu, 24 Jun 2021 11:01:31 +0200 From: Petr Mladek To: Jia He Cc: Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes , Jonathan Corbet , Alexander Viro , Linus Torvalds , "Peter Zijlstra (Intel)" , Eric Biggers , "Ahmed S. Darwish" , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Matthew Wilcox , Christoph Hellwig , nd@arm.com Subject: Re: [PATCH v2 2/4] lib/vsprintf.c: make '%pD' print the full path of file Message-ID: References: <20210623055011.22916-1-justin.he@arm.com> <20210623055011.22916-3-justin.he@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210623055011.22916-3-justin.he@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 2021-06-23 13:50:09, Jia He wrote: > Previously, the specifier '%pD' is for printing dentry name of struct > file. It may not be perfect (by default it only prints one component.) > > As suggested by Linus [1]: > > A dentry has a parent, but at the same time, a dentry really does > > inherently have "one name" (and given just the dentry pointers, you > > can't show mount-related parenthood, so in many ways the "show just > > one name" makes sense for "%pd" in ways it doesn't necessarily for > > "%pD"). But while a dentry arguably has that "one primary component", > > a _file_ is certainly not exclusively about that last component. > > Hence change the behavior of '%pD' to print the full path of that file. > > If someone invokes snprintf() with small but positive space, > prepend_name_with_len() moves or truncates the string partially. Does this comment belong to the 1st patch? prepend_name_with_len() is not called in this patch. > More > than that, kasprintf() will pass NULL @buf and @end as the parameters, > and @end - @buf can be negative in some case. Hence make it return at > the very beginning with false in these cases. Same here. file_d_path_name() does not return bool. Well, please mention in the commit message that %pD uses the entire given buffer as a scratch space. It might write something behind the trailing '\0'. It would make sense to warn about this also in Documentation/core-api/printk-formats.rst. It is a bit non-standard behavior. > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > index f0c35d9b65bf..f4494129081f 100644 > --- a/lib/vsprintf.c > +++ b/lib/vsprintf.c > @@ -920,13 +921,44 @@ char *dentry_name(char *buf, char *end, const struct dentry *d, struct printf_sp > } > > static noinline_for_stack > -char *file_dentry_name(char *buf, char *end, const struct file *f, > +char *file_d_path_name(char *buf, char *end, const struct file *f, > struct printf_spec spec, const char *fmt) > { > + char *p; > + const struct path *path; > + int prepend_len, widen_len, dpath_len; > + > if (check_pointer(&buf, end, f, spec)) > return buf; > > - return dentry_name(buf, end, f->f_path.dentry, spec, fmt); > + path = &f->f_path; > + if (check_pointer(&buf, end, path, spec)) > + return buf; > + > + p = d_path_unsafe(path, buf, end - buf, &prepend_len); > + > + /* Calculate the full d_path length, ignoring the tail '\0' */ > + dpath_len = end - buf - prepend_len - 1; > + > + widen_len = max_t(int, dpath_len, spec.field_width); > + > + /* Case 1: Already started past the buffer. Just forward @buf. */ > + if (buf >= end) > + return buf + widen_len; > + > + /* > + * Case 2: The entire remaining space of the buffer filled by > + * the truncated path. Still need to get moved right when > + * the filled width is greather than the full path length. s/filled/field/ ? > + */ > + if (prepend_len < 0) > + return widen_string(buf + dpath_len, dpath_len, end, spec); Otherwise, it looks good to me. Best Regards, Petr