Re: [PATCH 1/2] sysfs: allow the group is_visible() method to return a mode and add an update API

Previous thread: shell outputs anything typed when the kernel thinks@100% by Madhou on Friday, March 21, 2008 - 5:11 pm. (4 messages)

Next thread: [PATCH 2/2] scsi_transport_spi: fix the attribute settings by James Bottomley on Friday, March 21, 2008 - 5:29 pm. (1 message)
To: Hannes Reinecke <hare@...>, Kay Sievers <kay.sievers@...>, Greg KH <greg@...>
Cc: linux-scsi <linux-scsi@...>, linux-kernel <linux-kernel@...>
Date: Friday, March 21, 2008 - 5:27 pm

We have a problem in scsi_transport_spi in that we need to customise
not only the visibility of the attributes, but also their mode. Fix
this by making the is_visible() callback return a mode, with 0
indicating is not visible.

Also add a sysfs_update_group() API to allow us to change either the
visibility or mode of the files at any time on the fly.

Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
---

Greg, can I take this through SCSI, please ... assuming it's OK? We
need this to fix up the SPI transport class.

Thanks,

James

fs/sysfs/file.c | 14 ++++++++++----
fs/sysfs/group.c | 47 +++++++++++++++++++++++++++++++++++------------
fs/sysfs/sysfs.h | 2 ++
include/linux/sysfs.h | 4 +++-
4 files changed, 50 insertions(+), 17 deletions(-)

diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 6f5954a..8f7ee10 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -490,11 +490,10 @@ const struct file_operations sysfs_file_operations = {
.poll = sysfs_poll,
};

-
-int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr,
- int type)
+int sysfs_add_file_mode(struct sysfs_dirent *dir_sd,
+ const struct attribute *attr, int type, mode_t amode)
{
- umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG;
+ umode_t mode = (amode & S_IALLUGO) | S_IFREG;
struct sysfs_addrm_cxt acxt;
struct sysfs_dirent *sd;
int rc;
@@ -515,6 +514,13 @@ int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr,
}

+int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr,
+ int type)
+{
+ return sysfs_add_file_mode(dir_sd, attr, type, attr->mode);
+}
+
+
/**
* sysfs_create_file - create an attribute file for an object.
* @kobj: object we're creating for.
diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index 4779049..6c1232a 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -23,30 +23,38 @@ static void remove_files(...

To: James Bottomley <James.Bottomley@...>
Cc: Hannes Reinecke <hare@...>, Kay Sievers <kay.sievers@...>, linux-scsi <linux-scsi@...>, linux-kernel <linux-kernel@...>
Date: Friday, March 21, 2008 - 6:26 pm

Sure. But can you document that "update" field a bit more so we can
remember what it means in the future?

thanks,

greg k-h
--

To: Greg KH <greg@...>
Cc: Hannes Reinecke <hare@...>, Kay Sievers <kay.sievers@...>, linux-scsi <linux-scsi@...>, linux-kernel <linux-kernel@...>
Date: Saturday, March 22, 2008 - 2:02 pm

How about this? I also added docbook for create and update attribute
group.

James

---

From: James Bottomley <James.Bottomley@HansenPartnership.com>
Date: Thu, 20 Mar 2008 20:47:52 -0500
Subject: [SCSI] sysfs: make group is_valid return a mode_t

We have a problem in scsi_transport_spi in that we need to customise
not only the visibility of the attributes, but also their mode. Fix
this by making the is_visible() callback return a mode, with 0
indicating is not visible.

Also add a sysfs_update_group() API to allow us to change either the
visibility or mode of the files at any time on the fly.

Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
---
fs/sysfs/file.c | 14 ++++++--
fs/sysfs/group.c | 77 +++++++++++++++++++++++++++++++++++++++++-------
fs/sysfs/sysfs.h | 2 +
include/linux/sysfs.h | 4 ++-
4 files changed, 80 insertions(+), 17 deletions(-)

diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 6f5954a..8f7ee10 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -490,11 +490,10 @@ const struct file_operations sysfs_file_operations = {
.poll = sysfs_poll,
};

-
-int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr,
- int type)
+int sysfs_add_file_mode(struct sysfs_dirent *dir_sd,
+ const struct attribute *attr, int type, mode_t amode)
{
- umode_t mode = (attr->mode & S_IALLUGO) | S_IFREG;
+ umode_t mode = (amode & S_IALLUGO) | S_IFREG;
struct sysfs_addrm_cxt acxt;
struct sysfs_dirent *sd;
int rc;
@@ -515,6 +514,13 @@ int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr,
}

+int sysfs_add_file(struct sysfs_dirent *dir_sd, const struct attribute *attr,
+ int type)
+{
+ return sysfs_add_file_mode(dir_sd, attr, type, attr->mode);
+}
+
+
/**
* sysfs_create_file - create an attribute file for an object.
* @kobj: object we're creating for.
diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
in...

To: Greg KH <greg@...>
Cc: Hannes Reinecke <hare@...>, Kay Sievers <kay.sievers@...>, linux-scsi <linux-scsi@...>, linux-kernel <linux-kernel@...>
Date: Sunday, March 30, 2008 - 12:54 pm

Can I get an ACK from someone from sysfs for this, please?

--

To: James Bottomley <James.Bottomley@...>
Cc: Greg KH <greg@...>, Hannes Reinecke <hare@...>, linux-scsi <linux-scsi@...>, linux-kernel <linux-kernel@...>
Date: Monday, March 31, 2008 - 9:42 am

Looks good to me.

I think with the "visible" stuff for attribute groups, will be able to
fix the USB event timing problem, by moving the creation of the device
attributes to default attributes. So I'm looking forward to have this in

Thanks for doing this,
Kay

--

To: Kay Sievers <kay.sievers@...>
Cc: James Bottomley <James.Bottomley@...>, Hannes Reinecke <hare@...>, linux-scsi <linux-scsi@...>, linux-kernel <linux-kernel@...>
Date: Wednesday, April 2, 2008 - 2:30 am

Acked-by: Greg Kroah-Hartman <gregkh@suse.de>

--

Previous thread: shell outputs anything typed when the kernel thinks@100% by Madhou on Friday, March 21, 2008 - 5:11 pm. (4 messages)

Next thread: [PATCH 2/2] scsi_transport_spi: fix the attribute settings by James Bottomley on Friday, March 21, 2008 - 5:29 pm. (1 message)