Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3737606pxb; Tue, 26 Jan 2021 03:32:25 -0800 (PST) X-Google-Smtp-Source: ABdhPJwUaNhfX+/D0YTP+301ypzYKzkIuw6Z0EH0sltEobx32mxqzSSJoSPMQYUmcGFhdOJoOrjK X-Received: by 2002:a17:906:4694:: with SMTP id a20mr2922077ejr.201.1611660745301; Tue, 26 Jan 2021 03:32:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611660745; cv=none; d=google.com; s=arc-20160816; b=bllbz+B3NTZqdQgocfZWTdUB5UkO9Lmvy/V+0nxgwlTmmXWsJQDg/Xu3SSXqiZmvst VhdhUZybqVqTfHDQp+0sXKSioSkyvMpc0FTh9X7Wv/V/5/XhaXciS7xi/nWEIfDiAyjM 0kL92TGI1n6G2sBNAW0vAnQ0PkS7UG/e5SvfN26PyiEEH0bLFvRn2vbp5dP23SBL7/U3 8KuEAkrp+9FVKLSatdq00uXJ/dVmb2A4XPfQ707zEFAW/MA8/77H2GpoFWtfndUeNYVu 78+KJvdl3zpbGrf0nUGc6+U0RQwI7IfgbM8ZO3X2600dPR4HDRfJPYVaPb3YM2lp2T85 yPlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ZIW7mnwPUf6YWlYV9Dc8rQUYYrNuTxch5ZKKzYw0AFE=; b=OJjLwVqw3SA5fwkybCch1WnAjHsoojLKQDHRxYI/DFn8ULOg6Nt+AqSJXwmRPs3WUO oTv/nLlsdi5RErMyKKhJExMLiyOEt7BFeCDMhXOJYCXW961X1ePHMf3g4DYEoHROW18I N+RwlLQpIeu7dNkUz3qQdi/Xx7uB5JeHhH0uCDomi5XbSGE4WZuq6mROxpkrT7gXY4W9 mOZTfDFWpW+hEa5hhRKNB+F3cjt9wpCBvnOpYqimWieFsbsl7ZEanRV5YfPZQHi1Tq4D xDQJa8Cuge+kQvopgvEAxQr+gAklt4h3jsxz/elePi2zqISN13z2h+Az2/NeS8xUSFji W4OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ByfMfrJV; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e18si522307edz.446.2021.01.26.03.32.00; Tue, 26 Jan 2021 03:32:25 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ByfMfrJV; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405077AbhAZL3W (ORCPT + 99 others); Tue, 26 Jan 2021 06:29:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731145AbhAZJp4 (ORCPT ); Tue, 26 Jan 2021 04:45:56 -0500 Received: from mail-io1-xd2a.google.com (mail-io1-xd2a.google.com [IPv6:2607:f8b0:4864:20::d2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70359C061573; Tue, 26 Jan 2021 01:45:16 -0800 (PST) Received: by mail-io1-xd2a.google.com with SMTP id q129so32352057iod.0; Tue, 26 Jan 2021 01:45:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ZIW7mnwPUf6YWlYV9Dc8rQUYYrNuTxch5ZKKzYw0AFE=; b=ByfMfrJVJCKfp9k9KLuY9+zPDSK/oFPLxitqpAXbJiff4391iSWe8bKaYpGBbCmmvE FIyrmxZBTVaD2k5CbmUL7zZ898btlbJNEgMoRgegkdChxpRG0wHsfu+P1j+Xvk9nnHyD x/5TkGYudvDAChZjGnJXtjw1q2R5CB8MhAJtJUoaU2DvDlmWgqbJ3Hdn//kyJbj3JTrU eoaAyB08XmQ+F9wGYcs+tDXIbHAV95o7rM+y7DAztaGQ0U83UmbjTSn+AWLbCEI2CUOn fL21yhJXU7mRf8+Npa6Fd/e0B0JcBAWP1EetClFEvo5H0/nbc91eHMYHCXE0g3OjS1WV y3bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ZIW7mnwPUf6YWlYV9Dc8rQUYYrNuTxch5ZKKzYw0AFE=; b=fi4Gsd1X1UnHzLEH4LduDZbTwYZwXnHrZh8luRFKorFaUFgP0kMHeeChC4OFZdFDyk 6lUIwXfggD+3QfKSLpFJ56KLlULSc4RCDi/eNGwjTxJ1OrWA+L/RwP2Nl8Y9X4pahwTk HnvJcuZyoLHDipQJYo9Jw7CtUivPcNO2y1mZNL0c0w4jR/pAJHSZdPKGgMEuZb3VgdKG 8X9mpgP4JfSCsdN6lCWoXrRsp4TkZstHeWpgKeiXgb3PDeAQKRloDIJ1vQkSHBNYrzlB ABMKwV6T1hQIpNL5sADfqN3fh8ukHAChy6+X9pjzfdLJLmZYDFb5liZxGeWIAdBCSBWO rZhA== X-Gm-Message-State: AOAM5314U4v/PnUdnfueKPkmCtx0kXlKWXRLZ7PbVlnRLs9ZjEFDDHW5 NnxRLQwaDX13zmcYhze2RHlDUZApD756AhkdPkw= X-Received: by 2002:a02:7fc5:: with SMTP id r188mr4063015jac.69.1611654315745; Tue, 26 Jan 2021 01:45:15 -0800 (PST) MIME-Version: 1.0 References: <20210122162529.84978-1-alexandru.ardelean@analog.com> <20210122162529.84978-4-alexandru.ardelean@analog.com> <20210124181126.07c100a5@archlinux> In-Reply-To: From: Alexandru Ardelean Date: Tue, 26 Jan 2021 11:45:04 +0200 Message-ID: Subject: Re: [PATCH v2 03/12][RESEND] iio: buffer: rework buffer & scan_elements dir creation To: Greg Kroah-Hartman Cc: Jonathan Cameron , Alexandru Ardelean , LKML , linux-iio , Lars-Peter Clausen , "Hennerich, Michael" , nuno.sa@analog.com, "Bogdan, Dragos" , "Rafael J. Wysocki" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 25, 2021 at 9:32 PM Greg Kroah-Hartman wrote: > > On Sun, Jan 24, 2021 at 06:11:26PM +0000, Jonathan Cameron wrote: > > On Fri, 22 Jan 2021 18:25:20 +0200 > > Alexandru Ardelean wrote: > > > > > When adding more than one IIO buffer per IIO device, we will need to create > > > a buffer & scan_elements directory for each buffer. > > > We also want to move the 'scan_elements' to be a sub-directory of the > > > 'buffer' folder. > > > > > > The format we want to reach is, for a iio:device0 folder, for 2 buffers > > > [for example], we have a 'buffer0' and a 'buffer1' subfolder, and each with > > > it's own 'scan_elements' subfolder. > > > > > > So, for example: > > > iio:device0/buffer0 > > > scan_elements/ > > > > > > iio:device0/buffer1 > > > scan_elements/ > > > > > > The other attributes under 'bufferX' would remain unchanged. > > > > > > However, we would also need to symlink back to the old 'buffer' & > > > 'scan_elements' folders, to keep backwards compatibility. > > > > > > Doing all these, require that we maintain the kobjects for each 'bufferX' > > > and 'scan_elements' so that we can symlink them back. We also need to > > > implement the sysfs_ops for these folders. > > > > > > Signed-off-by: Alexandru Ardelean > > > > +CC GregKH and Rafael W for feedback on various things inline. > > > > It might be that this is the neatest solution that we can come up with but > > more eyes would be good! > > In short, please do NOT do this. > > At all. > > no. > > {sigh} > > > > > Whilst I think this looks fine, I'm less confident than I'd like to be. > > > > Jonathan > > > > > --- > > > drivers/iio/industrialio-buffer.c | 195 +++++++++++++++++++++++++++--- > > > drivers/iio/industrialio-core.c | 24 ++-- > > > include/linux/iio/buffer_impl.h | 14 ++- > > > include/linux/iio/iio.h | 2 +- > > > 4 files changed, 200 insertions(+), 35 deletions(-) > > > > > > diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c > > > index 0412c4fda4c1..0f470d902790 100644 > > > --- a/drivers/iio/industrialio-buffer.c > > > +++ b/drivers/iio/industrialio-buffer.c > > > @@ -1175,8 +1175,6 @@ static ssize_t iio_buffer_store_enable(struct device *dev, > > > return (ret < 0) ? ret : len; > > > } > > > > > > -static const char * const iio_scan_elements_group_name = "scan_elements"; > > > - > > > static ssize_t iio_buffer_show_watermark(struct device *dev, > > > struct device_attribute *attr, > > > char *buf) > > > @@ -1252,6 +1250,124 @@ static struct attribute *iio_buffer_attrs[] = { > > > &dev_attr_data_available.attr, > > > }; > > > > > > +#define to_dev_attr(_attr) container_of(_attr, struct device_attribute, attr) > > > + > > > +static ssize_t iio_buffer_dir_attr_show(struct kobject *kobj, > > > + struct attribute *attr, > > > + char *buf) > > > +{ > > > + struct iio_buffer *buffer = container_of(kobj, struct iio_buffer, buffer_dir); > > > + struct device_attribute *dattr; > > > + > > > + dattr = to_dev_attr(attr); > > > + > > > + return dattr->show(&buffer->indio_dev->dev, dattr, buf); > > > +} > > > First off, you are dealing with "raw" kobjects here, below a 'struct > device' in the device tree, which means that suddenly userspace does not > know what in the world is going on, and you lost events and lots of > other stuff. > > Never do this. It should not be needed, and you are just trying to > paper over one odd decision of an api with another one you will be stuck > with for forever. > > Remember the driver core can create subdirectories for your attributes > automatically if you want them to be in a subdir, but that's it, no > further than that. Just name the attribute group. > > But yes, you can not create a symlink to there, because (surprise), you > don't want to! > > So please, just rethink your naming, create a totally new naming scheme > for multiple entities, and just drop the old one (or keep a single > value if you really want to.) Don't make it harder than it has to be > please, you can never remove the "compatible symlinks", just make a new > api and move on. So, coming back to Jonathan. Any thoughts on how to proceed? We could merge the files 'buffer & scan_elements' [from in the /sys/bus/iio/devices/iio:deviceX/{buffer,scan_elements} So, essentially: # ls /sys/bus/iio/devices/iio:deviceX/bufferY data_available length watermark enable length_align_bytes in_voltage0_en in_voltage0_type in_voltage1_index in_voltage0_index in_voltage1_en in_voltage1_type Where: # ls /sys/bus/iio/devices/iio:deviceX/scan_elements in_voltage0_en in_voltage0_type in_voltage1_index in_voltage0_index in_voltage1_en in_voltage1_typ # ls /sys/bus/iio/devices/iio:deviceX/buffer data_available length watermark enable length_align_bytes I don't think we need to add any prefixes for the scan_elements/buffer files, or? Do we still do this new ioctl() for buffer0, 1, 2, N being accessed via anon inodes? Or do we go [back] via the route of each buffer with it's own chardev? i.e. introduce a "/dev/iio/deviceX/bufferY" structure I'm fine either way. Thanks Alex > > thanks, > > greg k-h