Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2651324pxb; Sun, 24 Jan 2021 15:24:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJxurAlo0vrTWKKpYAzL/wBJnAVP3hdUozV+LuvrXD3I+e//6FBSrP9f0A3n9XtM5aIB7rcE X-Received: by 2002:a17:906:46d3:: with SMTP id k19mr277740ejs.546.1611530657277; Sun, 24 Jan 2021 15:24:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611530657; cv=none; d=google.com; s=arc-20160816; b=vr+EGdUtuhEfL9drJffiKrILXBqOhNuiVBgMQqyJxNZlP3Ugg/ycGmzjc+QSZIYEgr 9iq2gA44MerUL7RJWACyaW33RbQv9VcRRlU603TvBwzepmjGyq2EWbBGiLVGJjg+YRpY 0+nk0rh7XgQvn7PNP26PrWB0RbORHt4ZhUrqhZ5sxgmHgc36AODW/oqrBuEQThwU16eu gpIYYjuCOf6oBIMnkJsCWTtC0VpEcnS/Ew+1fHm4X0cr4RGb/3GWlxRnP/SLl+j5ThxU FrD9BJf4mn6QB6WVYg0N8XJhlKjY99lTIDo3kA8QnjN6+VpVeex1cGYmq78tpZFR+VeV 342A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Ns4HnDqHyl7H/uBQuuuFU38KOhiW7eRkDPVaTcwUY8E=; b=vrHnsRQDUcFSw6KuJ1V9MJm2bB4EScwgYKLHbjs1ZsSBjsmhl+lBcGlLNvl+VFxTrc lGK97ku+D6tC1m+3SCwpNUGkkvWcTq63UwgVBVuLc8oGDdTPs8b3Ux7o7kdjv7KFrDFw xi1SRh/y+KJ9HYilxlmTzMXzZVYx8cO3vPKQPKLxDjh4+NQBnwCqNtoZBJc/kjv5Jbp6 hptsqL58d7FviOGS21O7XOGnZD4YsqdBpRHIDOsAdAz7AJdz3G5v2kHbBw6F8FODOIWv Ey5uEkmerA8/H2HK1h2P2Pu0GzLbaa4d7sJsvRHgRkcUoOJ9Ng8clssusQGCbccDiiQA goVA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d17si6350835edv.443.2021.01.24.15.23.53; Sun, 24 Jan 2021 15:24:17 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726692AbhAXXWH (ORCPT + 99 others); Sun, 24 Jan 2021 18:22:07 -0500 Received: from lilium.sigma-star.at ([109.75.188.150]:47008 "EHLO lilium.sigma-star.at" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726608AbhAXXVs (ORCPT ); Sun, 24 Jan 2021 18:21:48 -0500 Received: from localhost (localhost [127.0.0.1]) by lilium.sigma-star.at (Postfix) with ESMTP id B9D28181D91B1; Mon, 25 Jan 2021 00:21:01 +0100 (CET) Received: from lilium.sigma-star.at ([127.0.0.1]) by localhost (lilium.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id SeyKoaZyWjtH; Mon, 25 Jan 2021 00:21:01 +0100 (CET) Received: from lilium.sigma-star.at ([127.0.0.1]) by localhost (lilium.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id pvJY0DbAgGiB; Mon, 25 Jan 2021 00:21:01 +0100 (CET) From: Richard Weinberger To: miklos@szeredi.hu Cc: miquel.raynal@bootlin.com, vigneshr@ti.com, boris.brezillon@collabora.com, rminnich@google.com, sven@narfation.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, fuse-devel@lists.sourceforge.net, Richard Weinberger Subject: [PATCH 3/8] fuse: Make cuse_parse_one a common helper Date: Mon, 25 Jan 2021 00:20:02 +0100 Message-Id: <20210124232007.21639-4-richard@nod.at> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210124232007.21639-1-richard@nod.at> References: <20210124232007.21639-1-richard@nod.at> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This function will be used by MUSE too, let's share it. Signed-off-by: Richard Weinberger --- fs/fuse/Kconfig | 4 +++ fs/fuse/Makefile | 1 + fs/fuse/cuse.c | 58 +-------------------------------------- fs/fuse/fuse_i.h | 2 ++ fs/fuse/helper.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 78 insertions(+), 57 deletions(-) create mode 100644 fs/fuse/helper.c diff --git a/fs/fuse/Kconfig b/fs/fuse/Kconfig index 40ce9a1c12e5..9c8cc1e7b3a5 100644 --- a/fs/fuse/Kconfig +++ b/fs/fuse/Kconfig @@ -18,9 +18,13 @@ config FUSE_FS If you want to develop a userspace FS, or if you want to use a filesystem based on FUSE, answer Y or M. =20 +config FUSE_HELPER + def_bool n + config CUSE tristate "Character device in Userspace support" depends on FUSE_FS + select FUSE_HELPER help This FUSE extension allows character devices to be implemented in userspace. diff --git a/fs/fuse/Makefile b/fs/fuse/Makefile index 8c7021fb2cd4..7a5768cce6be 100644 --- a/fs/fuse/Makefile +++ b/fs/fuse/Makefile @@ -9,5 +9,6 @@ obj-$(CONFIG_VIRTIO_FS) +=3D virtiofs.o =20 fuse-y :=3D dev.o dir.o file.o inode.o control.o xattr.o acl.o readdir.o fuse-$(CONFIG_FUSE_DAX) +=3D dax.o +fuse-$(CONFIG_FUSE_HELPER) +=3D helper.o =20 virtiofs-y :=3D virtio_fs.o diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c index 45082269e698..fe8515844064 100644 --- a/fs/fuse/cuse.c +++ b/fs/fuse/cuse.c @@ -199,62 +199,6 @@ struct cuse_devinfo { const char *name; }; =20 -/** - * cuse_parse_one - parse one key=3Dvalue pair - * @pp: i/o parameter for the current position - * @end: points to one past the end of the packed string - * @keyp: out parameter for key - * @valp: out parameter for value - * - * *@pp points to packed strings - "key0=3Dval0\0key1=3Dval1\0" which en= ds - * at @end - 1. This function parses one pair and set *@keyp to the - * start of the key and *@valp to the start of the value. Note that - * the original string is modified such that the key string is - * terminated with '\0'. *@pp is updated to point to the next string. - * - * RETURNS: - * 1 on successful parse, 0 on EOF, -errno on failure. - */ -static int cuse_parse_one(char **pp, char *end, char **keyp, char **valp= ) -{ - char *p =3D *pp; - char *key, *val; - - while (p < end && *p =3D=3D '\0') - p++; - if (p =3D=3D end) - return 0; - - if (end[-1] !=3D '\0') { - pr_err("info not properly terminated\n"); - return -EINVAL; - } - - key =3D val =3D p; - p +=3D strlen(p); - - if (valp) { - strsep(&val, "=3D"); - if (!val) - val =3D key + strlen(key); - key =3D strstrip(key); - val =3D strstrip(val); - } else - key =3D strstrip(key); - - if (!strlen(key)) { - pr_err("zero length info key specified\n"); - return -EINVAL; - } - - *pp =3D p; - *keyp =3D key; - if (valp) - *valp =3D val; - - return 1; -} - /** * cuse_parse_dev_info - parse device info * @p: device info string @@ -275,7 +219,7 @@ static int cuse_parse_devinfo(char *p, size_t len, st= ruct cuse_devinfo *devinfo) int rc; =20 while (true) { - rc =3D cuse_parse_one(&p, end, &key, &val); + rc =3D fuse_kv_parse_one(&p, end, &key, &val); if (rc < 0) return rc; if (!rc) diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h index 8c56a3fd2c4e..555856b0d998 100644 --- a/fs/fuse/fuse_i.h +++ b/fs/fuse/fuse_i.h @@ -1228,5 +1228,7 @@ void fuse_dax_cancel_work(struct fuse_conn *fc); /* file.c */ struct page **fuse_pages_alloc(unsigned int npages, gfp_t flags, struct fuse_page_desc **desc); +/* helper.c */ +int fuse_kv_parse_one(char **pp, char *end, char **keyp, char **valp); =20 #endif /* _FS_FUSE_I_H */ diff --git a/fs/fuse/helper.c b/fs/fuse/helper.c new file mode 100644 index 000000000000..0c828daf8e8a --- /dev/null +++ b/fs/fuse/helper.c @@ -0,0 +1,70 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Helper functions used by CUSE and MUSE + * + * Copyright (C) 2008-2009 SUSE Linux Products GmbH + * Copyright (C) 2008-2009 Tejun Heo + * + */ + +#include +#include + +#include "fuse_i.h" + +/** + * fuse_kv_parse_one - parse one key=3Dvalue pair + * @pp: i/o parameter for the current position + * @end: points to one past the end of the packed string + * @keyp: out parameter for key + * @valp: out parameter for value + * + * *@pp points to packed strings - "key0=3Dval0\0key1=3Dval1\0" which en= ds + * at @end - 1. This function parses one pair and set *@keyp to the + * start of the key and *@valp to the start of the value. Note that + * the original string is modified such that the key string is + * terminated with '\0'. *@pp is updated to point to the next string. + * + * RETURNS: + * 1 on successful parse, 0 on EOF, -errno on failure. + */ +int fuse_kv_parse_one(char **pp, char *end, char **keyp, char **valp) +{ + char *p =3D *pp; + char *key, *val; + + while (p < end && *p =3D=3D '\0') + p++; + if (p =3D=3D end) + return 0; + + if (end[-1] !=3D '\0') { + pr_err("info not properly terminated\n"); + return -EINVAL; + } + + key =3D val =3D p; + p +=3D strlen(p); + + if (valp) { + strsep(&val, "=3D"); + if (!val) + val =3D key + strlen(key); + key =3D strstrip(key); + val =3D strstrip(val); + } else + key =3D strstrip(key); + + if (!strlen(key)) { + pr_err("zero length info key specified\n"); + return -EINVAL; + } + + *pp =3D p; + *keyp =3D key; + if (valp) + *valp =3D val; + + return 1; +} +EXPORT_SYMBOL_GPL(fuse_kv_parse_one); --=20 2.26.2