* [PATCH RESEND v4 1/2] mmc: card: Move MMC specific attributes to mmc sub-directory
@ 2012-07-14 18:46 Maya Erez
2012-07-14 18:50 ` merez
2012-07-14 18:59 ` Chris Ball
0 siblings, 2 replies; 3+ messages in thread
From: Maya Erez @ 2012-07-14 18:46 UTC (permalink / raw)
To: linux-mmc; +Cc: linux-arm-msm, Maya Erez, open list
Separate MMC specific attributes from general block device
attributes and move them from the /sys/block/<BLOCK_DEV> directory
to /sys/block/<BLOCK_DEV>/mmc directory
Signed-off-by: Maya Erez <merez@codeaurora.org>
---
drivers/mmc/card/block.c | 71 +++++++++++++++++++++++++++++++++++++++++----
1 files changed, 64 insertions(+), 7 deletions(-)
diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 4ba0f09..2b8ad9e 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -114,6 +114,9 @@ struct mmc_blk_data {
struct device_attribute force_ro;
struct device_attribute power_ro_lock;
int area_type;
+
+ struct kobject kobj;
+ struct kobj_type kobj_type;
};
static DEFINE_MUTEX(open_lock);
@@ -185,6 +188,51 @@ static void mmc_blk_put(struct mmc_blk_data *md)
mutex_unlock(&open_lock);
}
+static ssize_t mmc_blk_attr_show(struct kobject *kobj, struct attribute *attr,
+ char *buf)
+{
+ struct device_attribute *dev_attr;
+ struct mmc_blk_data *md;
+ ssize_t ret;
+
+ dev_attr = container_of(attr, struct device_attribute, attr);
+ if (!dev_attr->show)
+ return -EIO;
+
+ md = container_of(kobj, struct mmc_blk_data, kobj);
+ if (!md || &md->kobj != kobj)
+ return -EINVAL;
+
+ ret = dev_attr->show(disk_to_dev(md->disk), dev_attr, buf);
+
+ return ret;
+}
+
+static ssize_t mmc_blk_attr_store(struct kobject *kobj, struct attribute *attr,
+ const char *buf, size_t count)
+{
+ struct device_attribute *dev_attr;
+ struct mmc_blk_data *md;
+ ssize_t ret;
+
+ dev_attr = container_of(attr, struct device_attribute, attr);
+ if (!dev_attr->store)
+ return -EIO;
+
+ md = container_of(kobj, struct mmc_blk_data, kobj);
+ if (!md || &md->kobj != kobj)
+ return -EINVAL;
+
+ ret = dev_attr->store(disk_to_dev(md->disk), dev_attr, buf, count);
+
+ return ret;
+}
+
+static const struct sysfs_ops mmc_blk_sysfs_ops = {
+ .show = mmc_blk_attr_show,
+ .store = mmc_blk_attr_store,
+};
+
static ssize_t power_ro_lock_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -1999,14 +2047,15 @@ static void mmc_blk_remove_req(struct mmc_blk_data *md)
if (md) {
card = md->queue.card;
if (md->disk->flags & GENHD_FL_UP) {
- device_remove_file(disk_to_dev(md->disk), &md->force_ro);
+ sysfs_remove_file(&md->kobj, &md->force_ro.attr);
if ((md->area_type & MMC_BLK_DATA_AREA_BOOT) &&
card->ext_csd.boot_ro_lockable)
- device_remove_file(disk_to_dev(md->disk),
- &md->power_ro_lock);
+ sysfs_remove_file(&md->kobj,
+ &md->power_ro_lock.attr);
/* Stop new requests from getting into the queue */
del_gendisk(md->disk);
+ kobject_put(&md->kobj);
}
/* Then flush out any already in there */
@@ -2035,12 +2084,19 @@ static int mmc_add_disk(struct mmc_blk_data *md)
struct mmc_card *card = md->queue.card;
add_disk(md->disk);
+
+ md->kobj_type.sysfs_ops = &mmc_blk_sysfs_ops;
+ ret = kobject_init_and_add(&md->kobj, &md->kobj_type,
+ &disk_to_dev(md->disk)->kobj, "%s", "mmc");
+ if (ret)
+ goto init_kobj_fail;
+
md->force_ro.show = force_ro_show;
md->force_ro.store = force_ro_store;
sysfs_attr_init(&md->force_ro.attr);
md->force_ro.attr.name = "force_ro";
md->force_ro.attr.mode = S_IRUGO | S_IWUSR;
- ret = device_create_file(disk_to_dev(md->disk), &md->force_ro);
+ ret = sysfs_create_file(&md->kobj, &md->force_ro.attr);
if (ret)
goto force_ro_fail;
@@ -2059,16 +2115,17 @@ static int mmc_add_disk(struct mmc_blk_data *md)
md->power_ro_lock.attr.mode = mode;
md->power_ro_lock.attr.name =
"ro_lock_until_next_power_on";
- ret = device_create_file(disk_to_dev(md->disk),
- &md->power_ro_lock);
+ ret = sysfs_create_file(&md->kobj, &md->power_ro_lock.attr);
if (ret)
goto power_ro_lock_fail;
}
return ret;
power_ro_lock_fail:
- device_remove_file(disk_to_dev(md->disk), &md->force_ro);
+ sysfs_remove_file(&md->kobj, &md->force_ro.attr);
force_ro_fail:
+ kobject_put(&md->kobj);
+init_kobj_fail:
del_gendisk(md->disk);
return ret;
--
1.7.3.3
--
Sent by a consultant of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH RESEND v4 1/2] mmc: card: Move MMC specific attributes to mmc sub-directory
2012-07-14 18:46 [PATCH RESEND v4 1/2] mmc: card: Move MMC specific attributes to mmc sub-directory Maya Erez
@ 2012-07-14 18:50 ` merez
2012-07-14 18:59 ` Chris Ball
1 sibling, 0 replies; 3+ messages in thread
From: merez @ 2012-07-14 18:50 UTC (permalink / raw)
Cc: linux-mmc, linux-arm-msm, Maya Erez, open list
Hi all,
Do you have additional comments on this patch?
Thanks,
Maya
On Sat, July 14, 2012 11:46 am, Maya Erez wrote:
> Separate MMC specific attributes from general block device
> attributes and move them from the /sys/block/<BLOCK_DEV> directory
> to /sys/block/<BLOCK_DEV>/mmc directory
>
> Signed-off-by: Maya Erez <merez@codeaurora.org>
> ---
> drivers/mmc/card/block.c | 71
> +++++++++++++++++++++++++++++++++++++++++----
> 1 files changed, 64 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
> index 4ba0f09..2b8ad9e 100644
> --- a/drivers/mmc/card/block.c
> +++ b/drivers/mmc/card/block.c
> @@ -114,6 +114,9 @@ struct mmc_blk_data {
> struct device_attribute force_ro;
> struct device_attribute power_ro_lock;
> int area_type;
> +
> + struct kobject kobj;
> + struct kobj_type kobj_type;
> };
>
> static DEFINE_MUTEX(open_lock);
> @@ -185,6 +188,51 @@ static void mmc_blk_put(struct mmc_blk_data *md)
> mutex_unlock(&open_lock);
> }
>
> +static ssize_t mmc_blk_attr_show(struct kobject *kobj, struct attribute
> *attr,
> + char *buf)
> +{
> + struct device_attribute *dev_attr;
> + struct mmc_blk_data *md;
> + ssize_t ret;
> +
> + dev_attr = container_of(attr, struct device_attribute, attr);
> + if (!dev_attr->show)
> + return -EIO;
> +
> + md = container_of(kobj, struct mmc_blk_data, kobj);
> + if (!md || &md->kobj != kobj)
> + return -EINVAL;
> +
> + ret = dev_attr->show(disk_to_dev(md->disk), dev_attr, buf);
> +
> + return ret;
> +}
> +
> +static ssize_t mmc_blk_attr_store(struct kobject *kobj, struct attribute
> *attr,
> + const char *buf, size_t count)
> +{
> + struct device_attribute *dev_attr;
> + struct mmc_blk_data *md;
> + ssize_t ret;
> +
> + dev_attr = container_of(attr, struct device_attribute, attr);
> + if (!dev_attr->store)
> + return -EIO;
> +
> + md = container_of(kobj, struct mmc_blk_data, kobj);
> + if (!md || &md->kobj != kobj)
> + return -EINVAL;
> +
> + ret = dev_attr->store(disk_to_dev(md->disk), dev_attr, buf, count);
> +
> + return ret;
> +}
> +
> +static const struct sysfs_ops mmc_blk_sysfs_ops = {
> + .show = mmc_blk_attr_show,
> + .store = mmc_blk_attr_store,
> +};
> +
> static ssize_t power_ro_lock_show(struct device *dev,
> struct device_attribute *attr, char *buf)
> {
> @@ -1999,14 +2047,15 @@ static void mmc_blk_remove_req(struct mmc_blk_data
> *md)
> if (md) {
> card = md->queue.card;
> if (md->disk->flags & GENHD_FL_UP) {
> - device_remove_file(disk_to_dev(md->disk), &md->force_ro);
> + sysfs_remove_file(&md->kobj, &md->force_ro.attr);
> if ((md->area_type & MMC_BLK_DATA_AREA_BOOT) &&
> card->ext_csd.boot_ro_lockable)
> - device_remove_file(disk_to_dev(md->disk),
> - &md->power_ro_lock);
> + sysfs_remove_file(&md->kobj,
> + &md->power_ro_lock.attr);
>
> /* Stop new requests from getting into the queue */
> del_gendisk(md->disk);
> + kobject_put(&md->kobj);
> }
>
> /* Then flush out any already in there */
> @@ -2035,12 +2084,19 @@ static int mmc_add_disk(struct mmc_blk_data *md)
> struct mmc_card *card = md->queue.card;
>
> add_disk(md->disk);
> +
> + md->kobj_type.sysfs_ops = &mmc_blk_sysfs_ops;
> + ret = kobject_init_and_add(&md->kobj, &md->kobj_type,
> + &disk_to_dev(md->disk)->kobj, "%s", "mmc");
> + if (ret)
> + goto init_kobj_fail;
> +
> md->force_ro.show = force_ro_show;
> md->force_ro.store = force_ro_store;
> sysfs_attr_init(&md->force_ro.attr);
> md->force_ro.attr.name = "force_ro";
> md->force_ro.attr.mode = S_IRUGO | S_IWUSR;
> - ret = device_create_file(disk_to_dev(md->disk), &md->force_ro);
> + ret = sysfs_create_file(&md->kobj, &md->force_ro.attr);
> if (ret)
> goto force_ro_fail;
>
> @@ -2059,16 +2115,17 @@ static int mmc_add_disk(struct mmc_blk_data *md)
> md->power_ro_lock.attr.mode = mode;
> md->power_ro_lock.attr.name =
> "ro_lock_until_next_power_on";
> - ret = device_create_file(disk_to_dev(md->disk),
> - &md->power_ro_lock);
> + ret = sysfs_create_file(&md->kobj, &md->power_ro_lock.attr);
> if (ret)
> goto power_ro_lock_fail;
> }
> return ret;
>
> power_ro_lock_fail:
> - device_remove_file(disk_to_dev(md->disk), &md->force_ro);
> + sysfs_remove_file(&md->kobj, &md->force_ro.attr);
> force_ro_fail:
> + kobject_put(&md->kobj);
> +init_kobj_fail:
> del_gendisk(md->disk);
>
> return ret;
> --
> 1.7.3.3
> --
> Sent by a consultant of the Qualcomm Innovation Center, Inc.
> The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
>
--
Sent by consultant of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH RESEND v4 1/2] mmc: card: Move MMC specific attributes to mmc sub-directory
2012-07-14 18:46 [PATCH RESEND v4 1/2] mmc: card: Move MMC specific attributes to mmc sub-directory Maya Erez
2012-07-14 18:50 ` merez
@ 2012-07-14 18:59 ` Chris Ball
1 sibling, 0 replies; 3+ messages in thread
From: Chris Ball @ 2012-07-14 18:59 UTC (permalink / raw)
To: Maya Erez; +Cc: linux-mmc, linux-arm-msm, open list
Hi,
On Sat, Jul 14 2012, Maya Erez wrote:
> Separate MMC specific attributes from general block device
> attributes and move them from the /sys/block/<BLOCK_DEV> directory
> to /sys/block/<BLOCK_DEV>/mmc directory
I don't think we can do this, even though the change is a good one.
What happens if someone has userspace scripts that manipulate force_ro,
or ro_lock_until_next_power_on?
sysfs isn't a firmly stable kernel ABI, but I think it's much closer
to one than this patch implies.
Thanks,
- Chris.
--
Chris Ball <cjb@laptop.org> <http://printf.net/>
One Laptop Per Child
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-07-14 18:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-14 18:46 [PATCH RESEND v4 1/2] mmc: card: Move MMC specific attributes to mmc sub-directory Maya Erez
2012-07-14 18:50 ` merez
2012-07-14 18:59 ` Chris Ball
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox