From patchwork Mon Jun 20 00:42:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Overstreet X-Patchwork-Id: 12886924 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 79063C43334 for ; Mon, 20 Jun 2022 00:43:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 11B0E8D0006; Sun, 19 Jun 2022 20:43:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A5768D0001; Sun, 19 Jun 2022 20:43:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E60C38D0006; Sun, 19 Jun 2022 20:43:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D54D78D0001 for ; Sun, 19 Jun 2022 20:43:46 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id B45BC801E0 for ; Mon, 20 Jun 2022 00:43:46 +0000 (UTC) X-FDA: 79596766452.29.027E081 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) by imf31.hostedemail.com (Postfix) with ESMTP id 617AE20016 for ; Mon, 20 Jun 2022 00:43:46 +0000 (UTC) Received: by mail-qk1-f179.google.com with SMTP id d128so6880941qkg.8 for ; Sun, 19 Jun 2022 17:43:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X/vHm1f3WoFXRt6JUj3SilR7opGdtbcYgwZ9r1atlS8=; b=merDOSNMLYB6urSNHfDzTPlO9cTnNP2/a+Co95AIL+tp45UY1ESEm0GqSiRzYXGjPq lKJyO17f8asxDNlFx3YoHH74RPB12Y1OXa3miHqcxl3nepJtQLBUO9Vv5UHdySoFPh8K PGKEHVHhgt9ZYBn4DvdxjpTQB5GqGkaI+LQAnRZWVQ8SX7TbDJNlwW2CW67lMlBrQaqM fHJMTDRHSDe1GvdIBQNm34YtHj7FhTmUjvYWB9DPu2p8WHbZTwICJGdaIzqbiHLk2tuN ZC81jsJMxRKZ1U5KcvigCc/Eahf5rQRytJ7Y04hPgHNB3cyrUwmXC8gLtHcpNZqCkTdj ugFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X/vHm1f3WoFXRt6JUj3SilR7opGdtbcYgwZ9r1atlS8=; b=K8YJzxFcESZfMKqz+SwPDt8EAhPtukmrd1+mp6YBVGiBfCBDz0Cu8RfDvjFxUR/jbh bUMjWBEK+cBB1oQmn7HascJn1eJmxl+3VXBuzBRV0KJeJnP67YgsD+IMBGoP4/XMoxX4 iyMe2jpHzIlnxgriii18oFx7r4yJAXwjxYxJ4GcpgF/X2HB1iHRo5kqrFK9jDw9HDRuS yIb3CxDMWlUmQXRqwCMmAsOJ6JAWW0qqOHyQs47IWHcWzrJJSZSzcVNgOBSa2QGPpvvv TAtmc6XdteBVoZFLtnXVKS7ZRl2LPbjkx9p8XkDx6RDhaf8kGXlkX6L8UntdT6xZYrL0 5nqA== X-Gm-Message-State: AJIora//D0rhV3U7EBNZtUllOPKEAM5Gw+s/7FE1yH6EH3yuTI/iHn0/ wYBatDEcQ/wsCMqEE40bcw== X-Google-Smtp-Source: AGRyM1shE4oiEAmMw5aoUvXut3DE6PwvQ/fgFRcao0IJAPOeGEA0eOkJ0l5lxSyNWcz00L20yvlfpg== X-Received: by 2002:a05:620a:2720:b0:6a7:c28:3afa with SMTP id b32-20020a05620a272000b006a70c283afamr14575088qkp.438.1655685825745; Sun, 19 Jun 2022 17:43:45 -0700 (PDT) Received: from localhost (c-73-219-103-14.hsd1.vt.comcast.net. [73.219.103.14]) by smtp.gmail.com with ESMTPSA id bq38-20020a05620a46a600b006a785ba0c25sm10096007qkb.77.2022.06.19.17.43.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jun 2022 17:43:44 -0700 (PDT) From: Kent Overstreet To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, pmladek@suse.com Cc: Kent Overstreet , rostedt@goodmis.org, enozhatsky@chromium.org, linux@rasmusvillemoes.dk, willy@infradead.org Subject: [PATCH v4 31/34] d_path: prt_path() Date: Sun, 19 Jun 2022 20:42:30 -0400 Message-Id: <20220620004233.3805-32-kent.overstreet@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220620004233.3805-1-kent.overstreet@gmail.com> References: <20220620004233.3805-1-kent.overstreet@gmail.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf31.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=merDOSNM; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf31.hostedemail.com: domain of kent.overstreet@gmail.com designates 209.85.222.179 as permitted sender) smtp.mailfrom=kent.overstreet@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655685826; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=X/vHm1f3WoFXRt6JUj3SilR7opGdtbcYgwZ9r1atlS8=; b=dE8a4AEyGaOE+hfZJxPHS4IXQ/C15IC1P1P6exmQ46YsrEswqr4fTbnXStDQnLHJz1Fo6Q cK5ws6KI1+2DDjh+vzuvC6mvlHNxlBCKhzgqj5P/quWRHcZkId3p5BUq/f/2kjxnPOsRJG svaLE0m/1dIB0f+VoAlfxde6/uzhrHk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655685826; a=rsa-sha256; cv=none; b=7e/QU38NX2tTKpYk+p1FQg2vz5yHwgXFxLrIVFjdzYvY4T1o8iKtqrxLw9gNBkVxlhvr8U fp1eg26aqZlURfSiUoRhBgDDSHl4m3s8ico0ROYcTdqyCtJxzC4fY0lS1AJaQ08VEgjhYx F57cOLMGh5ZWrQ1c6p6a1Q/00dDRr1U= X-Stat-Signature: e3swha67j8c3beu4p6snug7ojnezu1fi X-Rspamd-Queue-Id: 617AE20016 X-Rspam-User: Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=merDOSNM; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf31.hostedemail.com: domain of kent.overstreet@gmail.com designates 209.85.222.179 as permitted sender) smtp.mailfrom=kent.overstreet@gmail.com X-Rspamd-Server: rspam10 X-HE-Tag: 1655685826-797119 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This implements a new printbuf version of d_path()/mangle_path(), which will replace the seq_buf version. Signed-off-by: Kent Overstreet --- fs/d_path.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/dcache.h | 1 + 2 files changed, 36 insertions(+) diff --git a/fs/d_path.c b/fs/d_path.c index e4e0ebad1f..1bd9e85f2f 100644 --- a/fs/d_path.c +++ b/fs/d_path.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "mount.h" @@ -294,6 +295,40 @@ char *d_path(const struct path *path, char *buf, int buflen) } EXPORT_SYMBOL(d_path); +/** + * prt_path - format a path for output + * @out: printbuf to output to + * @path: path to write into the sequence buffer. + * @esc: set of characters to escape in the output + * + * Write a path name into the sequence buffer. + * + * Returns 0 on success, or error code from d_path + */ +int prt_path(struct printbuf *out, const struct path *path, const char *esc) +{ + char *p, *buf; + size_t size; +again: + buf = out->buf + out->pos; + size = printbuf_remaining_size(out); + + p = d_path(path, buf, size); + if (IS_ERR(p)) { + printbuf_make_room(out, max_t(size_t, 64, size * 2)); + if (printbuf_remaining_size(out) > size) + goto again; + + return PTR_ERR(p); + } + + p = mangle_path(buf, p, esc); + if (p) + out->pos += p - buf; + return 0; +} +EXPORT_SYMBOL(prt_path); + /* * Helper function for dentry_operations.d_dname() members */ diff --git a/include/linux/dcache.h b/include/linux/dcache.h index f5bba51480..2181144f9f 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -293,6 +293,7 @@ extern char *d_absolute_path(const struct path *, char *, int); extern char *d_path(const struct path *, char *, int); extern char *dentry_path_raw(const struct dentry *, char *, int); extern char *dentry_path(const struct dentry *, char *, int); +extern int prt_path(struct printbuf *, const struct path *, const char *); /* Allocation counts.. */